Source for file jSelector.class.php

Documentation is available at jSelector.class.php

  1. <?php
  2. /**
  3. * Declare all differents classes corresponding to main jelix selectors
  4. *
  5. * a selector is a string refering to a file or a ressource, by indicating its module and its name.
  6. * For example : "moduleName~resourceName". There are several type of selector, depending on the
  7. * resource type. Selector objects get the real path of the corresponding file, the name of the
  8. * compiler (if the file has to be compile) etc.
  9. * So here, there is a selector class for each selector type.
  10. @package     jelix
  11. @subpackage  core_selector
  12. @author      Laurent Jouanneau
  13. @contributor Christophe Thiriot
  14. @copyright   2005-2007 Laurent Jouanneau
  15. @copyright   2008 Christophe Thiriot
  16. @link        http://www.jelix.org
  17. @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  18. */
  19.  
  20. /**
  21.  * Exception for selector errors
  22.  * @package    jelix
  23.  * @subpackage core_selector
  24.  */
  25. class jExceptionSelector extends jException }
  26.  
  27. /**
  28. * Create instance of selectors object
  29. @package    jelix
  30. @subpackage core_selector
  31. */
  32. class jSelectorFactory {
  33.     private function __construct(){}
  34.  
  35.     /**
  36.      * Create an instance of a selector object corresponding to the given selector
  37.      * @param string $selstr  the selector. It should be a full selector : "type:module~resource" (not "module~resource")
  38.      * @return jISelector the corresponding selector
  39.      */
  40.     static public function create ($selstr$defaulttype=false{
  41.         if (is_string($defaulttype&& strpos($selstr':'=== false{
  42.             $selstr "$defaulttype:$selstr";
  43.         }
  44.  
  45.         if(preg_match("/^([a-z]{3,5})\:([\w~\/\.]+)$/"$selstr$m)) {
  46.             $cname='jSelector'.$m[1];
  47.             if(class_exists($cname)) {
  48.                 $sel new $cname($m[2]);
  49.                 return $sel;
  50.             }
  51.         }
  52.         throw new jExceptionSelector('jelix~errors.selector.invalid.syntax'array($selstr,''));
  53.     }
  54. }

Documentation generated on Mon, 19 Sep 2011 14:13:31 +0200 by phpDocumentor 1.4.3