コード例 #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
 public function parse()
 {
     foreach ($this->_directories as $dir) {
         $classesPerFile = $this->_getClassesFromDirectory($dir);
         foreach ($classesPerFile as $file => $classes) {
             foreach ($classes as $class) {
                 $this->_reflectionFactory->getClassAnnotations($class);
             }
         }
     }
 }
コード例 #3
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;
 }
コード例 #4
0
ファイル: MvcAnnotationDriver.php プロジェクト: im286er/Ding
 /**
  * Will call HttpUrlMapper::addAnnotatedController to add new mappings
  * from the @Controller annotated classes. Also, creates a new bean
  * definition for every one of them.
  *
  * (non-PHPdoc)
  * @see Ding\Bean\Lifecycle.ILifecycleListener::afterConfig()
  */
 public function afterConfig()
 {
     foreach ($this->reflectionFactory->getClassesByAnnotation('controller') as $controller) {
         foreach ($this->_container->getBeansByClass($controller) as $name) {
             $annotations = $this->reflectionFactory->getClassAnnotations($controller);
             if (!$annotations->contains('requestmapping')) {
                 continue;
             }
             $requestMappings = $annotations->getAnnotations('requestmapping');
             foreach ($requestMappings as $map) {
                 if ($map->hasOption('url')) {
                     foreach ($map->getOptionValues('url') as $url) {
                         HttpUrlMapper::addAnnotatedController($url, $name);
                     }
                 }
             }
         }
     }
 }
コード例 #5
0
ファイル: Annotation.php プロジェクト: im286er/Ding
 /**
  * Looks for @ListensOn and register the bean as an event listener. Since
  * this is an "early" discovery of a bean, a BeanDefinition is generated.
  *
  * @param Collection $annotations Bean Annotations (for classes or methods)
  * @param string $beanName The target bean name.
  * @param string $class The bean class
  *
  * @return void
  */
 protected function registerEventsFor(Collection $annotations, $beanName, $class)
 {
     $rClass = $this->reflectionFactory->getClass($class);
     if ($rClass->isAbstract()) {
         return;
     }
     $this->_registerEventsForBeanName($annotations, $beanName);
     while ($rClass = $this->reflectionFactory->getClass($class)->getParentClass()) {
         $class = $rClass->getName();
         $annotations = $this->reflectionFactory->getClassAnnotations($rClass->getName());
         $this->_registerEventsForBeanName($annotations, $beanName);
     }
 }