/** * returns annotations for given reflected * * @param \Reflector|string|object $reflected class name, function name of or object instance to reflect * @param string $methodName optional specific method to reflect * @return \stubbles\reflect\annotation\Annotations * @since 5.3.0 */ function annotationsOf($reflected, string $methodName = null) : Annotations { $reflector = $reflected instanceof \Reflector ? $reflected : reflect($reflected, $methodName); $target = _annotationTarget($reflector); if (AnnotationCache::has($target)) { return AnnotationCache::get($target); } list($sourceTarget) = explode('#', $target); $return = null; foreach (Annotations::parse(docComment($reflector), $sourceTarget) as $annotations) { AnnotationCache::put($annotations); if ($annotations->target() === $target) { $return = $annotations; } } if (null === $return) { $return = new Annotations($target); AnnotationCache::put($return); } return $return; }
/** * @test */ public function retrieveAnnotationsForUncachedTargetReturnsNull() { assertNull(AnnotationCache::get('DoesNotExist')); }