/**
  * (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 afterCreate($bean, BeanDefinition $beanDefinition)
 {
     $rClass = $this->reflectionFactory->getClass(get_class($bean));
     if ($rClass->implementsInterface('Ding\\MessageSource\\IMessageSourceAware')) {
         $bean->setMessageSource($this->_container);
     }
     return $bean;
 }
예제 #3
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);
             }
         }
     }
 }
예제 #4
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;
 }
예제 #5
0
 /**
  * Call this one *from* your aspect, in order to proceed with the
  * execution. If you pass any arguments to this method, they will override
  * the original arguments when proceeding to the call.
  *
  * @return void
  */
 public function proceed()
 {
     $target = $this->_reflectionFactory->getMethod($this->_class, $this->_method);
     if (!$target->isPublic()) {
         $target->setAccessible(true);
     }
     $arguments = func_get_args();
     if (empty($arguments)) {
         $arguments = $this->_args;
     }
     $this->_result = $target->invokeArgs($this->_object, $arguments);
     return $this->_result;
 }
예제 #6
0
파일: Proxy.php 프로젝트: im286er/Ding
 /**
  * This will give you the name of a proxy class as a string. The class will
  * already exist in the vm.
  *
  * @return string
  */
 public function create($class, IDispatcher $dispatcher)
 {
     $subject = $this->reflectionFactory->getClass($class);
     $proxyClassName = 'Proxy' . str_replace('\\', '', $subject->getName());
     $cacheKey = $proxyClassName . '.proxy';
     $result = false;
     $src = $this->cache->fetch($cacheKey, $result);
     if (!$result) {
         $src = $this->createClass($proxyClassName, $dispatcher->getMethodsIntercepted(), $subject);
         $this->cache->store($cacheKey, $src);
     }
     eval($src);
     $proxyClassName::setDispatcher($dispatcher);
     $proxyClassName::setReflectionFactory($this->reflectionFactory);
     return $proxyClassName;
 }
예제 #7
0
 /**
  * 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);
                     }
                 }
             }
         }
     }
 }
예제 #8
0
 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);
             }
         }
     }
 }
예제 #9
0
파일: Dispatcher.php 프로젝트: im286er/Ding
 /**
  * Calls the specified method from the specifed object using the specified
  * arguments map.
  *
  * @param object $object
  * @param string $method Method name
  * @param array $arguments Map of arguments, where key is argument name,
  * and value is argument value.
  *
  * @return mxied
  */
 private function invokeAction($object, $method, array $arguments)
 {
     $methodInfo = $this->reflectionFactory->getMethod(get_class($object), $method);
     $parameters = $methodInfo->getParameters();
     $values = array();
     $total = count($parameters);
     for ($i = 0; $i < $total; $i++) {
         $parameter = array_shift($parameters);
         $name = $parameter->getName();
         if (isset($arguments[$name])) {
             $values[] = $arguments[$name];
         } else {
             if ($parameter->isOptional()) {
                 $values[] = $parameter->getDefaultValue();
             } else {
                 $ctl = get_class($object);
                 throw new MvcException("Missing required argument: {$name} for action {$ctl}:{$method}");
             }
         }
     }
     return $methodInfo->invokeArgs($object, $values);
 }
예제 #10
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;
 }
예제 #11
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;
 }
예제 #12
0
파일: Xml.php 프로젝트: im286er/Ding
 private function _addBeanToKnownByClass($class, $name)
 {
     if (strpos($class, "\${") !== false) {
         return;
     }
     if (!isset($this->_knownBeansByClass[$class])) {
         $this->_knownBeansByClass[$class] = array();
     }
     $this->_knownBeansByClass[$class][] = $name;
     // Load any parent classes
     $rClass = $this->_reflectionFactory->getClass($class);
     $parentClass = $rClass->getParentClass();
     while ($parentClass) {
         $parentClassName = $parentClass->getName();
         $this->_knownBeansByClass[$parentClassName][] = $name;
         $parentClass = $parentClass->getParentClass();
     }
     // Load any interfaces
     foreach ($rClass->getInterfaces() as $interfaceName => $rInterface) {
         $this->_knownBeansByClass[$interfaceName][] = $name;
     }
 }
예제 #13
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);
     }
 }