[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/symfony/http-kernel/Controller/ArgumentResolver/ -> VariadicValueResolver.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\HttpKernel\Controller\ArgumentResolver;
  13  
  14  use Symfony\Component\HttpFoundation\Request;
  15  use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
  16  use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
  17  
  18  /**
  19   * Yields a variadic argument's values from the request attributes.
  20   *
  21   * @author Iltar van der Berg <kjarli@gmail.com>
  22   */
  23  final class VariadicValueResolver implements ArgumentValueResolverInterface
  24  {
  25      /**
  26       * {@inheritdoc}
  27       */
  28      public function supports(Request $request, ArgumentMetadata $argument)
  29      {
  30          return $argument->isVariadic() && $request->attributes->has($argument->getName());
  31      }
  32  
  33      /**
  34       * {@inheritdoc}
  35       */
  36      public function resolve(Request $request, ArgumentMetadata $argument)
  37      {
  38          $values = $request->attributes->get($argument->getName());
  39  
  40          if (!\is_array($values)) {
  41              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)));
  42          }
  43  
  44          foreach ($values as $value) {
  45              yield $value;
  46          }
  47      }
  48  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1