Changeset 46

Show
Ignore:
Timestamp:
11/27/06 22:15:12 (2 years ago)
Author:
mikey
Message:

added possibility to use class loaders

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/XJConf/DefinitionParser.php

    r19 r46  
    7171     */ 
    7272    private $nodeTypes       = array(); 
     73    /** 
     74     * hashmap of class loaders where the key is the namespace the class loader 
     75     *  should be used for 
     76     * 
     77     * @var  array<String,XJConfClassLoader> 
     78     */ 
     79    private $classLoaders    = array(); 
    7380 
    7481    /** 
     
    7784     * Sets the node types depending on your PHP version using the constants 
    7885     * defined by the XMLReader PHP extension. 
    79      */ 
    80     public function __construct() 
     86     *  
     87     * @param  array<String,XJConfClassLoader>  $classLoaders  optional 
     88     */ 
     89    public function __construct($classLoaders = array()) 
    8190    { 
    8291        $this->defs             = new NamespaceDefinitions(); 
    8392        $this->currentNamespace = self::DEFAULT_NAMESPACE; 
     93        $this->classLoaders     = $classLoaders; 
    8494 
    8595        if (!defined('XMLREADER_ELEMENT')) { 
     
    114124    { 
    115125        return $this->defs; 
     126    } 
     127     
     128    /** 
     129     * check whether a class loader exists for given namespace 
     130     * 
     131     * @param   string  $namespace 
     132     * @return  bool 
     133     */ 
     134    public function hasClassLoader($namespace) 
     135    { 
     136        return (isset($this->classLoaders[$namespace])); 
     137    } 
     138     
     139    /** 
     140     * return the class loader for the given namespace 
     141     * 
     142     * @param   string             $namespace 
     143     * @return  XJConfClassLoader 
     144     */ 
     145    public function getClassLoader($namespace) 
     146    { 
     147         
     148        if ($this->hasClassLoader($namespace) == true) { 
     149            return $this->classLoaders[$namespace]; 
     150        } 
     151         
     152        return null; 
    116153    } 
    117154 
     
    164201                                } 
    165202                            } 
    166  
    167203                    $this->startElement($nameSpaceURI, $elementName, $attributes); 
    168204                    if (true === $empty) { 
     
    209245                return; 
    210246        } 
    211  
     247         
    212248        // create the appropriate definition handler and use this 
    213249        // to create the required definition 
  • trunk/XJConf/XmlParser.php

    r18 r46  
    119119        $this->tagDefs->appendNamespaceDefinitions($tagDefs); 
    120120    } 
     121     
     122    public function getTagDefinitions() 
     123    { 
     124        return $this->tagDefs; 
     125    } 
    121126 
    122127    /** 
  • trunk/XJConf/definitions/TagDefinition.php

    r43 r46  
    1313                   'definitions.Definition', 
    1414                   'exceptions.ValueConversionException', 
    15                    'exceptions.XJConfException' 
     15                   'exceptions.XJConfException', 
     16                   'XJConfClassLoader' 
    1617); 
    1718/** 
     
    8485     */ 
    8586        private $cdata          = null; 
     87        /** 
     88         * the class loader to use 
     89         * 
     90         * @var  XJConfClassLoader 
     91         */ 
     92        private $classLoader    = null; 
    8693 
    8794    /** 
     
    143150        public function getType() 
    144151        { 
     152            if (null != $this->classLoader) { 
     153                return $this->classLoader->getType($this->type); 
     154            } 
     155             
    145156                return $this->type; 
    146157        } 
     
    160171                        $data = ''; 
    161172                } 
    162  
     173                 
    163174        // no constructor definition has been set, 
    164175        // create a new one 
     
    381392                return false; 
    382393        } 
     394         
     395        /** 
     396         * set the class loader for this tag 
     397         * 
     398         * @param  XJConfClassLoader  $classLoader 
     399         */ 
     400        public function setClassLoader(XJConfClassLoader $classLoader) 
     401        { 
     402            $this->classLoader = $classLoader; 
     403        } 
    383404 
    384405    /** 
     
    389410    private function getValueConverter() 
    390411    { 
     412        if (null != $this->classLoader) { 
     413                    $this->classLoader->loadClass($this->type); 
     414                } 
     415                 
    391416        if (null == $this->valueConverter) { 
    392417            $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 
  • trunk/XJConf/definitions/handler/TagDefinitionHandler.php

    r19 r46  
    8686            $def->setSetterMethod($atts['setter']); 
    8787        } 
     88         
     89        // give definition the correct class loader 
     90        if ($this->defParser->hasClassLoader($this->defParser->getCurrentNamespace()) == true) { 
     91            $def->setClassLoader($this->defParser->getClassLoader($this->defParser->getCurrentNamespace())); 
     92        } 
    8893 
    8994        return $def;