withValue() public method

public withValue ( $value ) : self
return self
コード例 #1
0
 public function testCanOnlyResolveStringValues()
 {
     $resolver = new StringParameterResolver();
     $parameter = new Parameter('foo', null);
     $this->assertTrue($resolver->canResolve($parameter->withValue('string')));
     $this->assertFalse($resolver->canResolve($parameter->withValue(null)));
     $this->assertFalse($resolver->canResolve($parameter->withValue(10)));
     $this->assertFalse($resolver->canResolve($parameter->withValue(0.75)));
     $this->assertFalse($resolver->canResolve($parameter->withValue([])));
     $this->assertFalse($resolver->canResolve($parameter->withValue(new \stdClass())));
     $this->assertFalse($resolver->canResolve($parameter->withValue(function () {
     })));
 }
コード例 #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;
 }