Example #1
0
 protected function getInjectableMethods($classMethods)
 {
     foreach ($classMethods as $reflectedMethod) {
         $inject = $this->annotationReader->getMethodAnnotation($reflectedMethod, Inject::CLASS);
         if ($inject) {
             $parameters = [];
             $namedParameters = $this->extractNamedParameters($this->annotationReader, $reflectedMethod);
             $assistedParameters = $this->extractAssistedParameters($this->annotationReader, $reflectedMethod);
             $providerParameters = $this->extractProviderParameters($this->annotationReader, $reflectedMethod);
             foreach ($reflectedMethod->getParameters() as $parameter) {
                 $injectionParameter = new InjectionParameter($parameter->getName());
                 if (isset($assistedParameters[$parameter->getName()])) {
                     if ($reflectedMethod->getName() !== '__construct') {
                         throw new \Exception('Assisted injection not possible for setters');
                     }
                     $injectionParameter->setIsAssisted(true);
                 } else {
                     if (isset($namedParameters[$parameter->getName()])) {
                         $injectionParameter->setAlias($namedParameters[$parameter->getName()]);
                     } else {
                         if (isset($providerParameters[$parameter->getName()])) {
                             $injectionParameter->setProvides($providerParameters[$parameter->getName()]);
                         } else {
                             if ($class = $this->getParameterClassName($parameter)) {
                                 $injectionParameter->setInterface($class);
                             }
                         }
                     }
                 }
                 if ($parameter->isDefaultValueAvailable()) {
                     $injectionParameter->setDefaultValue($parameter->getDefaultValue());
                 }
                 $parameters[] = $injectionParameter;
             }
             if ($parameters) {
                 $this->injectableMethods[$reflectedMethod->getName()] = $parameters;
             }
         }
     }
 }
Example #2
0
 protected function createParameter(Meta\InjectionParameter $parameterMeta)
 {
     if ($parameterMeta->isProvider()) {
         return new Provider\ProviderImpl($this, $parameterMeta->provides());
     }
     return $this->getInstance($parameterMeta->type(), false, $parameterMeta->isOptional());
 }