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 a variadic argument's values from the request attributes. Chris@0: * Chris@0: * @author Iltar van der Berg Chris@0: */ Chris@0: final class VariadicValueResolver 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->isVariadic() && $request->attributes->has($argument->getName()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function resolve(Request $request, ArgumentMetadata $argument) Chris@0: { Chris@0: $values = $request->attributes->get($argument->getName()); Chris@0: Chris@17: if (!\is_array($values)) { Chris@17: throw new \InvalidArgumentException(sprintf('The action argument "...$%1$s" is required to be an array, the request attribute "%1$s" contains a type of "%2$s" instead.', $argument->getName(), \gettype($values))); Chris@0: } Chris@0: Chris@0: foreach ($values as $value) { Chris@0: yield $value; Chris@0: } Chris@0: } Chris@0: }