コード例 #1
0
 private function _injectProperties(BeanDefinition $bean)
 {
     $class = $bean->getClass();
     $rClass = $this->_reflectionFactory->getClass($class);
     $properties = $bean->getProperties();
     foreach ($rClass->getProperties() as $property) {
         $propertyName = $property->getName();
         $annotations = $this->_reflectionFactory->getPropertyAnnotations($class, $propertyName);
         if (!$annotations->contains('inject')) {
             continue;
         }
         $namedAnnotation = null;
         if ($annotations->contains('named')) {
             $namedAnnotation = $annotations->getSingleAnnotation('named');
         }
         $annotation = $annotations->getSingleAnnotation('inject');
         $newProperties = $this->_arrayToBeanProperties($propertyName, $this->_inject($propertyName, $annotation, null, $namedAnnotation));
         $properties = array_merge($properties, $newProperties);
     }
     $bean->setProperties($properties);
 }
コード例 #2
0
 /**
  * (non-PHPdoc)
  * @see Ding\Bean\Lifecycle.IAfterDefinitionListener::afterDefinition()
  */
 public function afterDefinition(BeanDefinition $bean)
 {
     $class = $bean->getClass();
     $rClass = $this->reflectionFactory->getClass($class);
     $properties = $bean->getProperties();
     foreach ($rClass->getMethods() as $method) {
         $methodName = $method->getName();
         if (strpos($methodName, 'set') !== 0) {
             continue;
         }
         $annotations = $this->reflectionFactory->getMethodAnnotations($class, $methodName);
         if (!$annotations->contains('resource')) {
             continue;
         }
         $propName = lcfirst(substr($methodName, 3));
         $name = $propName;
         $annotation = $annotations->getSingleAnnotation('resource');
         if ($annotation->hasOption('name')) {
             $name = $annotation->getOptionSingleValue('name');
         }
         $properties[$propName] = new BeanPropertyDefinition($propName, BeanPropertyDefinition::PROPERTY_BEAN, $name);
     }
     foreach ($rClass->getProperties() as $property) {
         $propertyName = $property->getName();
         $annotations = $this->reflectionFactory->getPropertyAnnotations($class, $propertyName);
         if (!$annotations->contains('resource')) {
             continue;
         }
         $annotation = $annotations->getSingleAnnotation('resource');
         $name = $propertyName;
         if ($annotation->hasOption('name')) {
             $name = $annotation->getOptionSingleValue('name');
         }
         $properties[$propertyName] = new BeanPropertyDefinition($propertyName, BeanPropertyDefinition::PROPERTY_BEAN, $name);
     }
     $bean->setProperties($properties);
     return $bean;
 }
コード例 #3
0
 /**
  * (non-PHPdoc)
  * @see Ding\Bean\Lifecycle.IAfterDefinitionListener::afterDefinition()
  */
 public function afterDefinition(BeanDefinition $bean)
 {
     $properties = $bean->getProperties();
     $class = $bean->getClass();
     $rClass = $this->reflectionFactory->getClass($class);
     foreach ($rClass->getProperties() as $rProperty) {
         $propertyName = $rProperty->getName();
         $annotations = $this->reflectionFactory->getPropertyAnnotations($class, $propertyName);
         if ($annotations->contains('value')) {
             $annotation = $annotations->getSingleAnnotation('value');
             if ($annotation->hasOption('value')) {
                 $value = $annotation->getOptionSingleValue('value');
                 $properties[$propertyName] = new BeanPropertyDefinition($propertyName, BeanPropertyDefinition::PROPERTY_SIMPLE, $value);
             }
         }
     }
     $bean->setProperties($properties);
     if ($bean->isCreatedWithFactoryBean()) {
         $factoryMethod = $bean->getFactoryMethod();
         $factoryBean = $bean->getFactoryBean();
         $def = $this->_container->getBeanDefinition($factoryBean);
         $annotations = $this->reflectionFactory->getMethodAnnotations($def->getClass(), $factoryMethod);
         $this->_applyToConstructor($annotations, $bean);
     } else {
         if ($bean->isCreatedByConstructor()) {
             $class = $bean->getClass();
             $rClass = $this->reflectionFactory->getClass($bean->getClass());
             $rMethod = $rClass->getConstructor();
             if ($rMethod) {
                 $annotations = $this->reflectionFactory->getMethodAnnotations($class, $rMethod->getName());
                 $this->_applyToConstructor($annotations, $bean);
             }
         }
     }
     return $bean;
 }