/** * 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; }
/** * finds implementation to be used from list of @ImplementedBy annotations * * @param \stubbles\reflect\annotation\Annotations $annotations * @param string $type * @return \ReflectionClass * @throws \stubbles\ioc\binding\BindingException */ private function findImplementation(Annotations $annotations, string $type) : \ReflectionClass { $implementation = null; foreach ($annotations->named('ImplementedBy') as $annotation) { /* @var $annotation \stubbles\reflect\annotation\Annotation */ if (null !== $this->environment && $annotation->hasValueByName('environment') && strtoupper($annotation->getEnvironment()) === $this->environment) { $implementation = $annotation->getClass(); } elseif (!$annotation->hasValueByName('environment') && null == $implementation) { $implementation = $annotation->getClass(); } } if (null === $implementation) { throw new BindingException('Interface ' . $type . ' annotated with @ImplementedBy, but no default found'); } return $implementation; }