/** * (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; }
/** * (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; }
private function _injectConstructorArguments(BeanDefinition $bean) { if ($bean->isCreatedWithFactoryBean()) { $factoryMethod = $bean->getFactoryMethod(); $factoryBean = $bean->getFactoryBean(); $def = $this->_container->getBeanDefinition($factoryBean); $class = $def->getClass(); $rMethod = $this->_reflectionFactory->getMethod($class, $factoryMethod); $annotations = $this->_reflectionFactory->getMethodAnnotations($class, $factoryMethod); $this->_applyToConstructor($rMethod, $annotations, $bean); } else { if ($bean->isCreatedByConstructor()) { $class = $bean->getClass(); $rClass = $this->_reflectionFactory->getClass($class); $rMethod = $rClass->getConstructor(); if ($rMethod) { $annotations = $this->_reflectionFactory->getMethodAnnotations($class, $rMethod->getName()); $this->_applyToConstructor($rMethod, $annotations, $bean); } } } }
/** * (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; }
/** * (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; }
public function getAspects() { $ret = array(); $aspectClasses = $this->reflectionFactory->getClassesByAnnotation('aspect'); foreach ($aspectClasses as $aspectClass) { foreach ($this->_knownBeansByClass[$aspectClass] as $beanName) { $rClass = $this->reflectionFactory->getClass($aspectClass); foreach ($rClass->getMethods() as $rMethod) { $methodName = $rMethod->getName(); $annotations = $this->reflectionFactory->getMethodAnnotations($aspectClass, $methodName); if ($annotations->contains('methodinterceptor')) { foreach ($annotations->getAnnotations('methodinterceptor') as $annotation) { $classExpression = $annotation->getOptionSingleValue('class-expression'); $expression = $annotation->getOptionSingleValue('expression'); $ret[] = $this->_newAspect($beanName, $classExpression, $expression, $methodName, AspectDefinition::ASPECT_METHOD); } } if ($annotations->contains('exceptioninterceptor')) { foreach ($annotations->getAnnotations('exceptioninterceptor') as $annotation) { $classExpression = $annotation->getOptionSingleValue('class-expression'); $expression = $annotation->getOptionSingleValue('expression'); $ret[] = $this->_newAspect($beanName, $classExpression, $expression, $methodName, AspectDefinition::ASPECT_EXCEPTION); } } } } } return $ret; }