Example #1
0
 private function _applyToConstructor(Collection $annotations, BeanDefinition $bean)
 {
     $constructorArguments = $bean->getArguments();
     if ($annotations->contains('value')) {
         foreach ($annotations->getAnnotations('value') as $annotation) {
             if ($annotation->hasOption('value')) {
                 foreach ($annotation->getOptionValues('value') as $value) {
                     $argName = false;
                     if ($annotation->hasOption('name')) {
                         $argName = $annotation->getOptionSingleValue('name');
                     }
                     $constructorArguments[] = new BeanConstructorArgumentDefinition(BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_VALUE, $value, $argName);
                 }
             }
         }
     }
     $bean->setArguments($constructorArguments);
 }
Example #2
0
 private function _applyToConstructor(\ReflectionMethod $rMethod, Collection $beanAnnotations, BeanDefinition $bean)
 {
     $constructorArguments = $bean->getArguments();
     if (!$beanAnnotations->contains('inject')) {
         return;
     }
     $annotations = $beanAnnotations->getAnnotations('inject');
     foreach ($annotations as $annotation) {
         if ($annotation->hasOption('type')) {
             if (!$annotation->hasOption('name')) {
                 throw new InjectByTypeException('constructor', 'Unknown', 'Cant specify type without name');
             }
         }
         if ($annotation->hasOption('name')) {
             if (!$annotation->hasOption('type')) {
                 throw new InjectByTypeException('constructor', 'Unknown', 'Cant specify name without type');
             }
             $name = $annotation->getOptionSingleValue('name');
             $type = $annotation->getOptionSingleValue('type');
             $namedAnnotation = null;
             if ($beanAnnotations->contains('named')) {
                 foreach ($beanAnnotations->getAnnotations('named') as $namedAnnotationCandidate) {
                     if ($namedAnnotationCandidate->hasOption('arg')) {
                         $target = $namedAnnotationCandidate->getOptionSingleValue('arg');
                         if ($target == $name) {
                             $namedAnnotation = $namedAnnotationCandidate;
                         }
                     }
                 }
             }
             $newArgs = $this->_inject($name, $annotation, $type, $namedAnnotation);
             $constructorArguments = array_merge($constructorArguments, $this->_arrayToConstructorArguments($name, $newArgs));
         } else {
             foreach ($rMethod->getParameters() as $parameter) {
                 $parameterName = $parameter->getName();
                 $type = $parameter->getClass();
                 if ($type === null) {
                     continue;
                 }
                 $type = $type->getName();
                 $namedAnnotation = null;
                 if ($beanAnnotations->contains('named')) {
                     foreach ($beanAnnotations->getAnnotations('named') as $namedAnnotationCandidate) {
                         if ($namedAnnotationCandidate->hasOption('arg')) {
                             $target = $namedAnnotationCandidate->getOptionSingleValue('arg');
                             if ($target == $parameterName) {
                                 $namedAnnotation = $namedAnnotationCandidate;
                             }
                         }
                     }
                 }
                 $newArgs = $this->_inject($parameterName, $annotation, $type, $namedAnnotation);
                 $constructorArguments = array_merge($constructorArguments, $this->_arrayToConstructorArguments($parameterName, $newArgs, $namedAnnotation));
             }
         }
     }
     $bean->setArguments($constructorArguments);
 }
Example #3
0
 private function _registerEventsForBeanName(Collection $annotations, $beanName)
 {
     if ($annotations->contains('listenson')) {
         $annotation = $annotations->getSingleAnnotation('listenson');
         foreach ($annotation->getOptionValues('value') as $eventCsv) {
             foreach (explode(',', $eventCsv) as $eventName) {
                 if (!isset($this->_knownBeansPerEvent[$eventName])) {
                     $this->_knownBeansPerEvent[$eventName] = array();
                 }
                 $this->_knownBeansPerEvent[$eventName][] = $beanName;
             }
         }
     }
 }
Example #4
0
 /**
  * This one will populate the map indexed by annotations names, so we can
  * then get all classes with a particular annotation name.
  *
  * @param string $class A class name.
  * @param Collection $annotations The annotations to index.
  *
  * @return void
  */
 private function _populateClassesPerAnnotations($class, Collection $annotations)
 {
     foreach ($annotations->getAll() as $name => $annotation) {
         $cacheKey = $name . '.classbyannotations';
         if (!isset($this->_classesAnnotated[$name])) {
             $this->_classesAnnotated[$name] = array();
         }
         $this->_classesAnnotated[$name][$class] = $class;
         $this->_cache->store($cacheKey, $this->_classesAnnotated);
     }
 }
Example #5
0
 /**
  * Adds a bean to $_knownBeans.
  *
  * @param string $class The class for this bean
  * @param string $key Where this bean has been chosen from (i.e: component, configuration, bean, etc)
  * @param Ding\Annotation\Collection $annotations Annotations for this bean
  * @param string $overrideWithName Override this bean name with this one
  * @param string $fBean An optional factory bean
  * @param string $fMethod An optional factory method
  *
  * @return string The name of the bean recently added
  */
 private function _addBean($class, $key, $annotations, $overrideWithName = false, $fBean = false, $fMethod = false)
 {
     $annotation = $annotations->getSingleAnnotation($key);
     $names = $this->_getAllNames($annotation, $overrideWithName);
     $leadName = $names[0];
     $this->_addBeanToKnownByClass($class, $leadName);
     $this->_knownBeans[$leadName] = array($names, $class, $key, $annotations, $fBean, $fMethod);
     // Dont let @Bean methods interfere with bean parentship.
     if (!$fBean) {
         $this->_knownClassesWithValidBeanAnnotations[$class] = $leadName;
     }
     return $leadName;
 }