コード例 #1
0
 /**
  * (non-PHPdoc)
  * @see Ding\Bean\Lifecycle.IAfterDefinitionListener::afterDefinition()
  */
 public function afterDefinition(BeanDefinition $bean)
 {
     $class = $bean->getClass();
     $annotations = $this->reflectionFactory->getClassAnnotations($class);
     if ($annotations->contains('initmethod')) {
         $annotation = $annotations->getSingleAnnotation('initmethod');
         if ($annotation->hasOption('method')) {
             $bean->setInitMethod($annotation->getOptionSingleValue('method'));
         }
     }
     if ($annotations->contains('destroymethod')) {
         $annotation = $annotations->getSingleAnnotation('destroymethod');
         if ($annotation->hasOption('method')) {
             $bean->setDestroyMethod($annotation->getOptionSingleValue('method'));
         }
     }
     foreach ($this->reflectionFactory->getClass($class)->getMethods() as $method) {
         $methodName = $method->getName();
         $annotations = $this->reflectionFactory->getMethodAnnotations($class, $methodName);
         if ($annotations->contains('postconstruct')) {
             $bean->setInitMethod($methodName);
             break;
         }
         if ($annotations->contains('predestroy')) {
             $bean->setDestroyMethod($methodName);
             break;
         }
     }
     return $bean;
 }
コード例 #2
0
 /**
  * (non-PHPdoc)
  * @see Ding\Bean\Lifecycle.IAfterDefinitionListener::afterDefinition()
  */
 public function afterDefinition(BeanDefinition $bean)
 {
     $class = $bean->getClass();
     $rClass = $this->reflectionFactory->getClass($class);
     $annotations = $this->reflectionFactory->getClassAnnotations($class);
     $props = $bean->getProperties();
     foreach ($rClass->getMethods() as $rMethod) {
         $methodName = $rMethod->getName();
         if (strpos($methodName, 'set') !== 0) {
             continue;
         }
         $annotations = $this->reflectionFactory->getMethodAnnotations($class, $methodName);
         if (!$annotations->contains('required')) {
             continue;
         }
         $propName = lcfirst(substr($methodName, 3));
         if (!isset($props[$propName])) {
             throw new BeanFactoryException('Missing @Required property: ' . $methodName);
         }
     }
     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;
 }
コード例 #4
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;
 }
コード例 #5
0
 private function _injectMethods(BeanDefinition $bean)
 {
     $class = $bean->getClass();
     $rClass = $this->_reflectionFactory->getClass($class);
     $properties = $bean->getProperties();
     foreach ($rClass->getMethods() as $method) {
         $methodName = $method->getName();
         $annotations = $this->_reflectionFactory->getMethodAnnotations($class, $methodName);
         if (!$annotations->contains('inject') || $annotations->contains('bean') || $method->isConstructor()) {
             continue;
         }
         $annotation = $annotations->getSingleAnnotation('inject');
         $namedAnnotation = null;
         if ($annotations->contains('named')) {
             $namedAnnotation = $annotations->getSingleAnnotation('named');
         }
         // Just 1 arg now. Multiple arguments need support in the container side.
         $parameters = $method->getParameters();
         if (empty($parameters)) {
             throw new InjectByTypeException($methodName, $methodName, 'Nothing to inject (no arguments in method)');
         }
         if (count($parameters) > 1) {
             throw new InjectByTypeException($methodName, $methodName, 'Multiple arguments are not yet supported');
         }
         $type = array_shift($parameters);
         $type = $type->getClass();
         if ($type !== null) {
             $type = $type->getName();
         }
         $newProperties = $this->_arrayToBeanProperties($methodName, $this->_inject($methodName, $annotation, $type, $namedAnnotation));
         $properties = array_merge($properties, $newProperties);
     }
     $bean->setProperties($properties);
 }
コード例 #6
0
ファイル: ContainerImpl.php プロジェクト: marcelog/ding
 /**
  * Applies specific bean aspects and global defined aspects.
  *
  * @param BeanDefinition $definition
  *
  * @return void
  */
 private function _applyAspects(BeanDefinition $definition)
 {
     $class = $definition->getClass();
     $dispatcher = clone $this->_dispatcherTemplate;
     $this->_applySpecificAspects($definition, $dispatcher);
     $this->_applyGlobalAspects($definition, $dispatcher);
     if ($dispatcher->hasMethodsIntercepted()) {
         $definition->setProxyClassName($this->_proxyFactory->create($class, $dispatcher));
     }
 }