예제 #1
0
 /**
  * Create new instance of annotation
  * @param string $class
  * @param mixed[] $parameters
  * @param ReflectionAnnotatedClass|ReflectionAnnotatedMethod|ReflectionAnnotatedProperty|bool $targetReflection
  * @return boolean|object
  */
 public function instantiateAnnotation($class, $parameters, $targetReflection = false)
 {
     $class = ucfirst($class) . "Annotation";
     // If namespaces are empty assume global namespace
     $fqn = $this->normalizeFqn('\\', $class);
     foreach ($this->addendum->namespaces as $ns) {
         $fqn = $this->normalizeFqn($ns, $class);
         if (Blacklister::ignores($fqn)) {
             continue;
         }
         try {
             if (!ClassChecker::exists($fqn)) {
                 $this->addendum->getLogger()->debug('Annotation class `{fqn}` not found, ignoring', ['fqn' => $fqn]);
                 Blacklister::ignore($fqn);
             } else {
                 // Class exists, exit loop
                 break;
             }
         } catch (Exception $e) {
             // Ignore class autoloading errors
         }
     }
     if (Blacklister::ignores($fqn)) {
         return false;
     }
     try {
         // NOTE: was class_exists here, however should be safe to use ClassChecker::exists here
         if (!ClassChecker::exists($fqn)) {
             $this->addendum->getLogger()->debug('Annotation class `{fqn}` not found, ignoring', ['fqn' => $fqn]);
             Blacklister::ignore($fqn);
             return false;
         }
     } catch (Exception $e) {
         // Ignore autoload errors and return false
         Blacklister::ignore($fqn);
         return false;
     }
     $resolvedClass = Addendum::resolveClassName($fqn);
     if ((new ReflectionClass($resolvedClass))->implementsInterface(AnnotationInterface::class) || $resolvedClass == AnnotationInterface::class) {
         return new $resolvedClass($parameters, $targetReflection);
     }
     return false;
 }