Changeset 77

Show
Ignore:
Timestamp:
12/19/06 20:09:16 (2 years ago)
Author:
schst
Message:

First version of static tags. This enables you to build a static registry or create objects for a factory. Currently static tags should only be used at root levels, if used as nested tags, the behavior is undefined.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/XJConf/converters/factories/ValueConverterFactoryChain.php

    r22 r77  
    1111                   'converters.factories.ConstructorValueConverterFactory', 
    1212                   'converters.factories.FactoryMethodValueConverterFactory', 
     13                   'converters.factories.StaticClassValueConverterFactory', 
    1314                   'definitions.Definition' 
    1415); 
     
    5960ValueConverterFactoryChain::push(new PrimitiveValueConverterFactory()); 
    6061ValueConverterFactoryChain::push(new ArrayValueConverterFactory()); 
     62ValueConverterFactoryChain::push(new StaticClassValueConverterFactory()); 
    6163ValueConverterFactoryChain::push(new ConstructorValueConverterFactory()); 
    6264ValueConverterFactoryChain::push(new FactoryMethodValueConverterFactory()); 
  • trunk/XJConf/definitions/TagDefinition.php

    r62 r77  
    9191         */ 
    9292        protected $classLoader    = null; 
     93        /** 
     94         * Whether the calls should be made statically or not 
     95         * 
     96         * @var  boolean 
     97         */ 
     98        protected $static = false; 
    9399 
    94100        /** 
     
    132138                return $this->classLoader->getType($this->type); 
    133139            } 
    134              
     140 
    135141                return $this->type; 
     142        } 
     143 
     144        /** 
     145         * Set whether calls should be made statically (true) 
     146         * or an instance of the class should be created (false) 
     147         * 
     148         * @param boolean $static 
     149         */ 
     150        public function setStatic($static) { 
     151            $this->static = $static; 
     152        } 
     153 
     154        /** 
     155         * get the type of the tag 
     156         * 
     157         * @return  string 
     158         */ 
     159        public function isStatic() 
     160        { 
     161                return $this->static; 
    136162        } 
    137163 
     
    150176                        $data = ''; 
    151177                } 
    152                  
     178 
    153179        // no constructor definition has been set, 
    154180        // create a new one 
     
    220246 
    221247        if ($def instanceof FactoryMethodDefinition) { 
     248            if ($this->isStatic()) { 
     249                throw new InvalidTagDefinitionException('Static classes may not have a factory method defined.'); 
     250            } 
    222251            $this->factoryMethod = $def; 
    223252            return; 
     
    225254 
    226255        if ($def instanceof ConstructorDefinition) { 
     256            if ($this->isStatic()) { 
     257                throw new InvalidTagDefinitionException('Static classes may not have a constructor defined.'); 
     258            } 
    227259            $this->constructor = $def; 
    228260            return; 
     
    371403                return false; 
    372404        } 
    373          
     405 
    374406        /** 
    375407         * set the class loader for this tag 
     
    392424            throw new ValueConversionException('No type set. Can not create ValueConverter.'); 
    393425        } 
    394          
     426 
    395427        if (null != $this->classLoader) { 
    396428                    $this->classLoader->loadClass($this->type); 
    397429                } 
    398                  
     430 
    399431        if (null == $this->valueConverter) { 
    400432            $this->valueConverter = ValueConverterFactoryChain::getFactory($this)->createValueConverter($this); 
  • trunk/XJConf/definitions/handler/AbstractTagDefinitionHandler.php

    r61 r77  
    5454                throw new InvalidTagDefinitionException('The <abstractTag> tag is missing the abstractType attribute.'); 
    5555        } 
    56          
     56 
    5757        if (isset($atts['concreteTypeAttribute']) == false) { 
    5858                throw new InvalidTagDefinitionException('The <abstractTag> tag is missing the concreteTypeAttribute attribute.'); 
     
    8484            $def->setSetterMethod($atts['setter']); 
    8585        } 
    86          
     86 
     87        // static 
     88        if (isset($atts['static']) == true && strtolower($atts['static']) == 'true') { 
     89            $def->setStatic(true); 
     90        } 
     91 
    8792        // give definition the correct class loader 
    8893        if ($this->defParser->hasClassLoader($this->defParser->getCurrentNamespace()) == true) { 
  • trunk/XJConf/definitions/handler/ConcreteTagDefinitionHandler.php

    r62 r77  
    8686            $def->setSetterMethod($atts['setter']); 
    8787        } 
    88          
     88 
     89        // static 
     90        if (isset($atts['static']) == true && strtolower($atts['static']) == 'true') { 
     91            $def->setStatic(true); 
     92        } 
     93 
    8994        // give definition the correct class loader 
    9095        if ($this->defParser->hasClassLoader($this->defParser->getCurrentNamespace()) == true) { 
  • trunk/autopackage2.php

    r76 r77  
    5050- New feature to define abstract tags, which enables yo to define the concrete type in the tag instead of the definition (mikey) 
    5151- It is now possible to define an explicit setter method for character data inside a tag (schst) 
     52- Added possibility to declare tags as static (schst) 
    5253- Added several unit tests (mikey) 
    5354Bugfixes: 
  • trunk/package.php

    r76 r77  
    4444- New feature to define abstract tags, which enables yo to define the concrete type in the tag instead of the definition (mikey) 
    4545- It is now possible to define an explicit setter method for character data inside a tag (schst) 
     46- Added possibility to declare tags as static (schst) 
    4647- Added several unit tests (mikey) 
    4748Bugfixes: