Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpKernel\Controller\ArgumentResolver; Chris@0: Chris@0: use Symfony\Component\HttpFoundation\Request; Chris@0: use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; Chris@0: use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; Chris@0: Chris@0: /** Chris@0: * Yields the default value defined in the action signature when no value has been given. Chris@0: * Chris@0: * @author Iltar van der Berg Chris@0: */ Chris@0: final class DefaultValueResolver implements ArgumentValueResolverInterface Chris@0: { Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function supports(Request $request, ArgumentMetadata $argument) Chris@0: { Chris@0: return $argument->hasDefaultValue() || (null !== $argument->getType() && $argument->isNullable() && !$argument->isVariadic()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function resolve(Request $request, ArgumentMetadata $argument) Chris@0: { Chris@0: yield $argument->hasDefaultValue() ? $argument->getDefaultValue() : null; Chris@0: } Chris@0: }