コード例 #1
0
 /**
  * Finds an annotation on the controller class or method.
  *
  * If the annotation is found on both the controller class and method, the method annotation is returned.
  * If the annotation is found on several classes in the hierarchy of controller classes,
  * the annotation of the child class is returned.
  *
  * This method does not support controller functions outside a class.
  *
  * @param \ReflectionFunctionAbstract $controller
  * @param string                      $annotationClass
  *
  * @return object|null The annotation, or null if not found.
  */
 protected function getControllerAnnotation(\ReflectionFunctionAbstract $controller, string $annotationClass)
 {
     if ($controller instanceof \ReflectionMethod) {
         $annotations = $this->annotationReader->getMethodAnnotations($controller);
         foreach ($annotations as $annotation) {
             if ($annotation instanceof $annotationClass) {
                 return $annotation;
             }
         }
         $class = $controller->getDeclaringClass();
         $classes = $this->reflectionTools->getClassHierarchy($class);
         foreach ($classes as $class) {
             $annotations = $this->annotationReader->getClassAnnotations($class);
             foreach ($annotations as $annotation) {
                 if ($annotation instanceof $annotationClass) {
                     return $annotation;
                 }
             }
         }
     }
     return null;
 }
コード例 #2
0
ファイル: Container.php プロジェクト: brick/di
 /**
  * @param string $key
  *
  * @return bool
  */
 public function has(string $key)
 {
     if (!isset($this->items[$key])) {
         if (class_exists($key)) {
             $class = new \ReflectionClass($key);
             $classes = $this->reflectionTools->getClassHierarchy($class);
             foreach ($classes as $class) {
                 if ($this->injectionPolicy->isClassInjected($class)) {
                     $this->bind($key);
                     // @todo allow to configure scope (singleton) with annotations
                     break;
                 }
             }
         }
     }
     return isset($this->items[$key]);
 }