Example #1
0
File: Xml.php Project: im286er/Ding
 /**
  * Returns a constructor argument definition.
  *
  * @param SimpleXML $simpleXmlArg Argument node.
  *
  * @throws BeanFactoryException
  * @return BeanConstructorArgumentDefinition
  */
 private function _loadConstructorArg($simpleXmlArg)
 {
     if (isset($simpleXmlArg->ref)) {
         $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_BEAN;
         $argValue = (string) $simpleXmlArg->ref->attributes()->bean;
     } else {
         if (isset($simpleXmlArg->bean)) {
             $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_BEAN;
             $name = BeanDefinition::generateName('Bean');
             $argValue = $name;
             $simpleXmlArg->bean->addAttribute('id', $name);
         } else {
             if (isset($simpleXmlArg->null)) {
                 $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_VALUE;
                 $argValue = null;
             } else {
                 if (isset($simpleXmlArg->false)) {
                     $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_VALUE;
                     $argValue = false;
                 } else {
                     if (isset($simpleXmlArg->true)) {
                         $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_VALUE;
                         $argValue = true;
                     } else {
                         if (isset($simpleXmlArg->array)) {
                             $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_ARRAY;
                             $argValue = array();
                             foreach ($simpleXmlArg->array->entry as $arrayEntry) {
                                 $key = (string) $arrayEntry->attributes()->key;
                                 $argValue[$key] = $this->_loadConstructorArg($arrayEntry);
                             }
                         } else {
                             if (isset($simpleXmlArg->eval)) {
                                 $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_CODE;
                                 $argValue = (string) $simpleXmlArg->eval;
                             } else {
                                 $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_VALUE;
                                 $argValue = (string) $simpleXmlArg->value;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (isset($simpleXmlArg->attributes()->name)) {
         $argName = (string) $simpleXmlArg->attributes()->name;
     } else {
         $argName = false;
     }
     return new BeanConstructorArgumentDefinition($argType, $argValue, $argName);
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see Ding\Bean\Lifecycle.IAfterDefinitionListener::afterDefinition()
  */
 public function afterDefinition(BeanDefinition $bean)
 {
     foreach ($bean->getMethodInjections() as $method) {
         $aspectBeanName = BeanDefinition::generateName('MethodInjectionAspect');
         $aspectBean = new BeanDefinition($aspectBeanName);
         $aspectBean->setClass('\\Ding\\Bean\\Factory\\Driver\\MethodInjectionAspect');
         $aspectBean->setProperties(array(new BeanPropertyDefinition('beanName', BeanPropertyDefinition::PROPERTY_SIMPLE, $method[1])));
         $this->_beans[$aspectBeanName] = $aspectBean;
         $aspectName = BeanDefinition::generateName('MethodInjectionAspect');
         $pointcutName = BeanDefinition::generateName('MethodInjectionPointcut');
         $pointcut = new PointcutDefinition($pointcutName, $method[0], 'invoke');
         $this->_aspectManager->setPointcut($pointcut);
         $aspect = new AspectDefinition($aspectName, array($pointcutName), AspectDefinition::ASPECT_METHOD, $aspectBeanName, '');
         $aspects = $bean->getAspects();
         $aspects[] = $aspect;
         $bean->setAspects($aspects);
     }
     return $bean;
 }
Example #3
0
 private function _newAspect($aspectBean, $classExpression, $expression, $method, $type)
 {
     $pointcutName = BeanDefinition::generateName('PointcutAnnotationAspectDriver');
     $pointcutDef = new PointcutDefinition($pointcutName, $expression, $method);
     $aspectName = BeanDefinition::generateName('AnnotationAspected');
     $aspectDef = new AspectDefinition($aspectName, array($pointcutName), $type, $aspectBean, $classExpression);
     $this->_aspectManager->setPointcut($pointcutDef);
     return $aspectDef;
 }
Example #4
0
 /**
  * Returns a constructor argument definition.
  *
  * @param mixed  $value Constructor arg YAML structure value.
  * @param string $yamlFilename Filename for yaml file.
  *
  * @throws BeanFactoryException
  * @return BeanConstructorArgumentDefinition
  */
 private function _loadConstructorArg($name, $value, $yamlFilename)
 {
     if (is_array($value)) {
         if (isset($value['ref'])) {
             $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_BEAN;
             $argValue = $value['ref'];
         } else {
             if (isset($value['eval'])) {
                 $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_CODE;
                 $argValue = $value['eval'];
             } else {
                 if (isset($value['bean'])) {
                     $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_BEAN;
                     $innerBean = BeanDefinition::generateName('Bean');
                     $this->_yamlFiles[$yamlFilename]['beans'][$innerBean] = $value['bean'];
                     $argValue = $innerBean;
                 } else {
                     $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_ARRAY;
                     $argValue = array();
                     foreach ($value as $key => $inValue) {
                         $argValue[$key] = $this->_loadConstructorArg(false, $inValue, $yamlFilename);
                     }
                 }
             }
         }
     } else {
         $argType = BeanConstructorArgumentDefinition::BEAN_CONSTRUCTOR_VALUE;
         $argValue = $value;
     }
     if (is_string($name)) {
         $argName = $name;
     } else {
         $argName = false;
     }
     return new BeanConstructorArgumentDefinition($argType, $argValue, $argName);
 }