Exemplo n.º 1
0
 public function testAnnotation()
 {
     $reader = new Reader();
     $annotations = $reader->getClassAnnotations(Foo::class);
     //$annotations = $annotations->filter("va");
     foreach ($annotations as $annotation) {
         //var_dump($annotation->getAttributes());
     }
 }
Exemplo n.º 2
0
 /**
  * @throws \Exception
  * @param \Reflector
  * @return array[mixed]
  */
 private function getDependenciesForFunctionOrMethod(\Reflector $reflector) : array
 {
     $annotations = $this->annotationReader->getReflectorAnnotations($reflector);
     $atInject = $annotations->filter("/^Inject\$/")->get();
     $atParams = $annotations->filter("/^param\$/");
     $parameters = $reflector->getParameters();
     if ($atInject !== null && !empty($atInject->getAttributes()) && count($atInject->getAttributes()) !== count($parameters)) {
         throw new \Exception("Number of annotated dependencies and number of parameters do not match");
     }
     //colect values
     foreach ($parameters as $index => $parameter) {
         $name = $parameter->getClass() !== null ? $parameter->getClass()->getName() : null;
         if ($atInject != null) {
             $foo = $atInject->getAttribute($index);
             if ($foo === "*" || $foo === null) {
                 $atParam = $atParams->get($index);
                 if ($atParam != null) {
                     $foo = $atParam->getAttribute(0);
                 }
             }
             if ($foo !== "*" && $foo !== null) {
                 $name = $foo;
             }
         }
         $names[$index] = $name;
     }
     //collect values
     $values = [];
     foreach ($parameters as $index => $parameter) {
         $value = $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null;
         $name = $names[$index];
         if (!empty($name)) {
             $foo = $this->getDependency($name);
             if ($foo !== null) {
                 $value = $foo;
             }
         }
         $values[$index] = $value;
     }
     return $values;
 }