/**
  * {@inheritdoc}
  * @throws PropertyDefinitionNotFoundException
  */
 public function analyze(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionProperty $reflectionProperty)
 {
     $propertyName = $reflectionProperty->getName();
     // Set property metadata
     if ($classDefinition->hasProperty($propertyName)) {
         $classDefinition->getProperty($propertyName)->setIsPublic($reflectionProperty->isPublic())->setModifiers($reflectionProperty->getModifiers());
     }
 }
 /**
  * {@inheritdoc}
  * @throws MethodDefinitionAlreadyExistsException
  * @throws MethodDefinitionNotFoundException
  */
 public function analyze(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionMethod $reflectionMethod)
 {
     $methodName = $reflectionMethod->getName();
     // Constructor definition is required
     if ($methodName === '__construct' && !$classDefinition->hasMethod('__construct')) {
         $classDefinition->defineConstructor()->end();
     }
     // Set method metadata
     if ($classDefinition->hasMethod($methodName)) {
         $classDefinition->getMethod($methodName)->setModifiers($reflectionMethod->getModifiers())->setIsPublic($reflectionMethod->isPublic());
     }
 }
 /**
  * {@inheritdoc}
  * @throws PropertyDefinitionAlreadyExistsException
  * @throws PropertyDefinitionNotFoundException
  */
 public function analyze(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionProperty $reflectionProperty)
 {
     $propertyName = $reflectionProperty->getName();
     // Resolve annotations
     $annotations = $this->reader->getPropertyAnnotations($reflectionProperty);
     if (count($annotations)) {
         // Define property if not exists
         if (!$classDefinition->hasProperty($propertyName)) {
             $classDefinition->defineProperty($propertyName);
         }
         // Exec annotations
         foreach ($annotations as $annotation) {
             if ($annotation instanceof ResolvePropertyInterface) {
                 $annotation->resolveProperty($analyzer, $classDefinition, $reflectionProperty);
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  * @throws ParameterDefinitionAlreadyExistsException
  * @throws ReferenceNotImplementsException
  * @throws MethodDefinitionNotFoundException
  * @throws ParameterDefinitionNotFoundException
  * @throws \InvalidArgumentException
  */
 public function analyze(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionParameter $reflectionParameter)
 {
     $methodName = $reflectionParameter->getDeclaringFunction()->getName();
     $parameterName = $reflectionParameter->getName();
     // Define parameter only if method definition is available
     if ($classDefinition->hasMethod($methodName)) {
         $methodDefinition = $classDefinition->getMethod($methodName);
         // Define parameter definition if not exists
         $parameterDefinition = $methodDefinition->setupParameter($parameterName);
         $this->setReflectionMetadata($parameterDefinition, $reflectionParameter);
         $dependency = $parameterDefinition->getDependency();
         // If dependency was not set
         // UndefinedReference is the default value of dependency which was not use before
         if (!$dependency || $dependency instanceof UndefinedReference) {
             $this->setDependencyByReflection($parameterDefinition, $reflectionParameter);
         }
         $this->setOrderArguments($methodDefinition, $reflectionParameter->getDeclaringFunction());
     }
 }
 /**
  * {@inheritdoc}
  * @throws MethodDefinitionAlreadyExistsException
  */
 public function analyze(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionMethod $reflectionMethod)
 {
     $methodName = $reflectionMethod->getName();
     // Resolve annotations
     $annotations = $this->reader->getMethodAnnotations($reflectionMethod);
     // Create method definition if annotation is exists
     if (count($annotations)) {
         // Define method if not exists
         if (!$classDefinition->hasMethod($methodName)) {
             $classDefinition->defineMethod($methodName);
         }
         // Exec method annotations
         foreach ($annotations as $annotation) {
             if ($annotation instanceof ResolveMethodInterface) {
                 $annotation->resolveMethod($analyzer, $classDefinition, $reflectionMethod);
             }
         }
     }
 }
 /**
  * Generate return operator and save instance to static properties it its singleton
  *
  * @param ClassDefinition $classDefinition
  * @param string $id
  * @return string
  */
 protected function generateReturnOperator(ClassDefinition $classDefinition, string $id = null) : string
 {
     $code = "\treturn \$temp;";
     // If there is a singleton then save it to static service collection
     if ($classDefinition->isSingleton()) {
         $code = "\t\$singletonCollection['{$id}'] = \$temp;\n\t\t" . $code;
     }
     return $code;
 }
 /**
  * Add new class definition
  *
  * @param $className
  * @param string $serviceName
  * @return ClassBuilderInterface
  * @throws \InvalidArgumentException
  * @throws ClassDefinitionAlreadyExistsException
  */
 public function addDefinition($className, string $serviceName = null) : ClassBuilderInterface
 {
     // Check if class already exists
     if ($this->hasDefinition($className)) {
         throw new ClassDefinitionAlreadyExistsException();
     }
     // Create new definition
     $classDefinition = new ClassDefinition($this);
     $classDefinition->setClassName(new ClassReference($className));
     if ($serviceName) {
         $classDefinition->setServiceName($serviceName);
     }
     // Register definition
     $this->definitionCollection[$className] = $classDefinition;
     return $classDefinition;
 }
 /**
  * {@inheritdoc}
  * @throws WrongAnnotationConstructorException
  * @throws MethodDefinitionNotFoundException
  * @throws ParameterDefinitionAlreadyExistsException
  * @throws MethodDefinitionAlreadyExistsException
  */
 public function resolveMethod(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionMethod $reflectionMethod)
 {
     // Get parameter key
     $key = array_keys($this->value)[0];
     $classDefinition->setupMethod($reflectionMethod->getName())->defineParameter($key)->defineDependency(new ClassReference($this->value[$key]))->end();
 }
Beispiel #9
0
 /** {@inheritdoc} */
 public function resolveClass(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionClass $reflectionClass)
 {
     $classDefinition->setServiceName($this->value['value']);
     $classDefinition->setIsSingleton(true);
 }
 /** {@inheritdoc} */
 public function analyze(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionClass $reflectionClass)
 {
     // Get name space from class name
     $classDefinition->setNameSpace($reflectionClass->getNamespaceName());
 }
 /**
  * Resolve method
  *
  * @param ClassDefinition $classDefinition
  * @param array $methodArray
  * @param string $methodName
  * @throws MethodDefinitionAlreadyExistsException
  * @throws \InvalidArgumentException
  * @throws ParameterDefinitionAlreadyExistsException
  * @throws ReferenceNotImplementsException
  */
 protected function resolveMethod(ClassDefinition $classDefinition, array $methodArray, string $methodName)
 {
     $methodDefinition = $classDefinition->defineMethod($methodName);
     if (array_key_exists('arguments', $methodArray)) {
         $this->resolveArguments($methodDefinition, $methodArray['arguments']);
     }
 }
Beispiel #12
0
 /**
  * Define constructor
  *
  * @param ClassDefinition $classDefinition
  * @param $path
  * @throws MethodDefinitionAlreadyExistsException
  */
 protected function defineConstructor(ClassDefinition $classDefinition, $path)
 {
     $classDefinition->defineConstructor()->defineParameter('path')->defineDependency(new StringReference($path))->end()->end();
 }