Ejemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see Ding\Bean\Lifecycle.ILifecycleListener::afterConfig()
  */
 public function afterConfig()
 {
     try {
         $bean = $this->_container->getBean('messageSource');
         $this->_container->setMessageSource($bean);
     } catch (\Exception $e) {
     }
 }
Ejemplo n.º 2
0
 /**
  * (non-PHPdoc)
  * @see Ding\Bean\Lifecycle.IAfterConfigListener::afterConfig()
  */
 public function afterConfig()
 {
     $holder = $this->_container->getBean('PropertiesHolder');
     foreach ($holder->getLocations() as $location) {
         if (is_string($location)) {
             $resource = $this->_resourceLoader->getResource(trim($location));
         } else {
             $resource = $location;
         }
         $contents = stream_get_contents($resource->getStream());
         $this->_container->registerProperties(parse_ini_string($contents, false));
     }
 }
Ejemplo n.º 3
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);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
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);
             }
         }
     }
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 /**
  * Returns the bean definition for a parent class of a class (if found). If
  * the parent class has a valid bean annotation (see $_knownBeans) it will
  * be returned.
  *
  * @param string $class
  *
  * @return BeanDefinition|null
  */
 private function _getParentBeanDefinition($class)
 {
     $def = null;
     while ($parentRefClass = $this->reflectionFactory->getClass($class)->getParentClass()) {
         $class = $parentRefClass->getName();
         // Does this class has a valid bean annotation?
         if (isset($this->_knownClassesWithValidBeanAnnotations[$class])) {
             $parentNameBean = $this->_knownClassesWithValidBeanAnnotations[$class];
             return $this->_container->getBeanDefinition($parentNameBean);
         }
     }
     return $def;
 }
Ejemplo n.º 7
0
 /**
  * Creates a new bean (prototypes).
  *
  * @param MethodInvocation $invocation The call.
  *
  * @return object
  */
 public function invoke(MethodInvocation $invocation)
 {
     return $this->_container->getBean($this->_beanName);
 }