/** * Check whenever class or trait or interface exists. * It does autoload if needed. * @param string $class * @return bool True if class or trait or interface exists */ public static function exists($class) { if (Blacklister::ignores($class)) { return false; } if (self::isConfirmed($class)) { return true; } try { if (class_exists($class)) { return self::confirm($class); } } catch (Exception $ex) { // Some class loaders throw exception if class not found } try { if (trait_exists($class)) { return self::confirm($class); } } catch (Exception $ex) { // Some class loaders throw exception if class not found } try { if (interface_exists($class)) { return self::confirm($class); } } catch (Exception $ex) { // Some class loaders throw exception if class not found } Blacklister::ignore($class); return false; }
/** * Clear entire annotations cache. */ public static function cacheClear() { self::$annotations = []; self::$classNames = []; Blacklister::reset(); Builder::clearCache(); (new MetaCache())->clear(); }
/** * 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; }