Ejemplo n.º 1
0
 /**
  * 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;
 }