resolve() public method

Resolves a parameter value.
public resolve ( Parameter $parameter, ParameterBag $unresolvedParameters, ParameterBag $resolvedParameters ) : ParameterBag
$parameter Nelmio\Alice\Parameter Unresolved parameter
$unresolvedParameters Nelmio\Alice\ParameterBag
$resolvedParameters Nelmio\Alice\ParameterBag
return Nelmio\Alice\ParameterBag Contains all the resolved parameters (as parameter are dynamics, resolving 1 parameter may result in resolving several other parameters).
コード例 #1
0
 /**
  * @inheritdoc
  */
 public function resolve(ParameterBag $unresolvedParameters, ParameterBag $injectedParameters = null) : ParameterBag
 {
     $resolvedParameters = null === $injectedParameters ? new ParameterBag() : $injectedParameters;
     foreach ($unresolvedParameters as $key => $value) {
         if ($resolvedParameters->has($key)) {
             continue;
         }
         $context = new ResolvingContext($key);
         $resolvedParameters = $this->resolver->resolve(new Parameter($key, $value), $unresolvedParameters, $resolvedParameters, $context);
     }
     return $resolvedParameters;
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function resolve(Parameter $unresolvedArrayParameter, ParameterBag $unresolvedParameters, ParameterBag $resolvedParameters, ResolvingContext $context = null) : ParameterBag
 {
     if (null === $this->resolver) {
         throw ResolverNotFoundExceptionFactory::createUnexpectedCall(__METHOD__);
     }
     $context = ResolvingContext::createFrom($context, $unresolvedArrayParameter->getKey());
     $resolvedArray = [];
     /* @var array $unresolvedArray */
     $unresolvedArray = $unresolvedArrayParameter->getValue();
     foreach ($unresolvedArray as $index => $unresolvedValue) {
         // Iterate over all the values of the array to resolve each of them
         $resolvedParameters = $this->resolver->resolve(new Parameter((string) $index, $unresolvedValue), $unresolvedParameters, $resolvedParameters, $context);
         $resolvedArray[$index] = $resolvedParameters->get((string) $index);
         $resolvedParameters = $resolvedParameters->without((string) $index);
     }
     $resolvedParameters = $resolvedParameters->with($unresolvedArrayParameter->withValue($resolvedArray));
     return $resolvedParameters;
 }
コード例 #3
0
 /**
  * @param ParameterResolverInterface $resolver
  * @param Parameter                  $parameter Parameter being resolved
  * @param string                     $key       Key of the parameter that need to be resolved to resolve $parameter
  * @param ParameterBag               $unresolvedParameters
  * @param ParameterBag               $resolvedParameters
  * @param ResolvingContext           $context
  *
  * @return ParameterBag
  */
 private function resolveStringKey(ParameterResolverInterface $resolver = null, Parameter $parameter, string $key, ParameterBag $unresolvedParameters, ParameterBag $resolvedParameters, ResolvingContext $context) : ParameterBag
 {
     if ($resolvedParameters->has($key)) {
         return $resolvedParameters;
     }
     if (false === $unresolvedParameters->has($key)) {
         throw ParameterNotFoundExceptionFactory::createForWhenResolvingParameter($key, $parameter);
     }
     $context->checkForCircularReference($key);
     $context->add($key);
     if (null === $resolver) {
         throw ResolverNotFoundExceptionFactory::createUnexpectedCall(__METHOD__);
     }
     return $resolver->resolve(new Parameter($key, $unresolvedParameters->get($key)), $unresolvedParameters, $resolvedParameters, $context);
 }