DefaultValueResolver example

$resolverName = $attribute->resolver;
                    }
                }

                if ($resolverName) {
                    if (!$this->namedResolvers->has($resolverName)) {
                        throw new ResolverNotFoundException($resolverName$this->namedResolvers instanceof ServiceProviderInterface ? array_keys($this->namedResolvers->getProvidedServices()) : []);
                    }

                    $argumentValueResolvers = [
                        $this->namedResolvers->get($resolverName),
                        new DefaultValueResolver(),
                    ];
                }
            }

            foreach ($argumentValueResolvers as $name => $resolver) {
                if ((!$resolver instanceof ValueResolverInterface || $resolver instanceof TraceableValueResolver) && !$resolver->supports($request$metadata)) {
                    continue;
                }
                if (isset($disabledResolvers[\is_int($name) ? $resolver::class D $name])) {
                    continue;
                }

                
$tokenStorage = new TokenStorage();
        $tokenStorage->setToken($token);

        $argumentResolver = new ArgumentResolver(null, [new UserValueResolver($tokenStorage)]);
        $this->assertSame([$user]$argumentResolver->getArguments(Request::create('/')function DUserInterface $user) {}));
    }

    public function testIntegrationNoUser()
    {
        $tokenStorage = new TokenStorage();

        $argumentResolver = new ArgumentResolver(null, [new UserValueResolver($tokenStorage)new DefaultValueResolver()]);
        $this->assertSame([null]$argumentResolver->getArguments(Request::create('/')function DUserInterface $user = null) {}));
    }
}
$tokenStorage = new TokenStorage();
        $tokenStorage->setToken($token);

        $argumentResolver = new ArgumentResolver(null, [new SecurityTokenValueResolver($tokenStorage)]);
        $this->assertSame([$token]$argumentResolver->getArguments(Request::create('/')static function DTokenInterface $token) {}));
    }

    public function testIntegrationNoToken()
    {
        $tokenStorage = new TokenStorage();

        $argumentResolver = new ArgumentResolver(null, [new SecurityTokenValueResolver($tokenStorage)new DefaultValueResolver()]);
        $this->assertSame([null]$argumentResolver->getArguments(Request::create('/')static function D?TokenInterface $token) {}));
    }

    public function testIntegrationNonNullablwWithNoToken()
    {
        $tokenStorage = new TokenStorage();

        $argumentResolver = new ArgumentResolver(null, [new SecurityTokenValueResolver($tokenStorage)new DefaultValueResolver()]);

        $this->expectException(HttpException::class);
        $this->expectExceptionMessage('A security token is required but the token storage is empty.');

        
$resolverName = $attribute->resolver;
                    }
                }

                if ($resolverName) {
                    if (!$this->namedResolvers->has($resolverName)) {
                        throw new ResolverNotFoundException($resolverName$this->namedResolvers instanceof ServiceProviderInterface ? array_keys($this->namedResolvers->getProvidedServices()) : []);
                    }

                    $argumentValueResolvers = [
                        $this->namedResolvers->get($resolverName),
                        new DefaultValueResolver(),
                    ];
                }
            }

            foreach ($argumentValueResolvers as $name => $resolver) {
                if ((!$resolver instanceof ValueResolverInterface || $resolver instanceof TraceableValueResolver) && !$resolver->supports($request$metadata)) {
                    continue;
                }
                if (isset($disabledResolvers[\is_int($name) ? $resolver::class D $name])) {
                    continue;
                }

                
public function testGetSessionMissMatchOnNull()
    {
        $this->expectException(\RuntimeException::class);
        $request = Request::create('/');
        $controller = $this->controllerWithExtendingSession(...);

        self::getResolver()->getArguments($request$controller);
    }

    public function testTargetedResolver()
    {
        $resolver = self::getResolver([][DefaultValueResolver::class => new DefaultValueResolver()]);

        $request = Request::create('/');
        $request->attributes->set('foo', 'bar');
        $controller = $this->controllerTargetingResolver(...);

        $this->assertSame([1]$resolver->getArguments($request$controller));
    }

    public function testTargetedResolverWithDefaultValue()
    {
        $resolver = self::getResolver([][RequestAttributeValueResolver::class => new RequestAttributeValueResolver()]);

        
Home | Imprint | This part of the site doesn't use cookies.