コード例 #1
0
 /**
  *
  * @param ParameterInterface $parameter
  * @param InjectorInterface $injector
  * @return mixed
  * @throws InjectorException
  */
 private function resolveParameter(ParameterInterface $parameter, InjectorInterface $injector)
 {
     $name = $parameter->getName();
     if ($this->hasValue($name)) {
         return $this->getValue($name);
     }
     if ($parameter->hasClassName()) {
         $className = $parameter->getClassName();
         if ($this->hasDefinition($className)) {
             $definition = $this->getDefinition($className);
             return $definition->resolve($injector);
         }
         return $injector->create($className);
     }
     if ($parameter->hasDefaultValue()) {
         return $parameter->getDefaultValue();
     }
     throw new InjectorException(sprintf('Failed to resolve parameter `%s`', $name));
 }
コード例 #2
0
 /**
  *
  * @param ParameterInterface $parameter
  * @param array $nameValueMap
  * @param DefinitionInterface[] $eachDefinition
  * @return array
  * @throws InjectorException
  */
 private function resolveParameter(ParameterInterface $parameter, array $nameValueMap, $eachDefinition)
 {
     $name = $parameter->getName();
     if (isset($nameValueMap[$name])) {
         return $nameValueMap[$name];
     }
     if ($parameter->hasClassName()) {
         $className = $parameter->getClassName();
         return $this->withEachDefinition($eachDefinition)->create($className);
     }
     if ($parameter->hasDefaultValue()) {
         return $parameter->getDefaultValue();
     }
     throw new InjectorException(InjectorException::getParameterInjectionFailedMessage($name), null);
 }