annotate vendor/symfony/http-kernel/Controller/ArgumentResolver/ServiceValueResolver.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children c2387f117808
rev   line source
Chris@14 1 <?php
Chris@14 2
Chris@14 3 /*
Chris@14 4 * This file is part of the Symfony package.
Chris@14 5 *
Chris@14 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@14 7 *
Chris@14 8 * For the full copyright and license information, please view the LICENSE
Chris@14 9 * file that was distributed with this source code.
Chris@14 10 */
Chris@14 11
Chris@14 12 namespace Symfony\Component\HttpKernel\Controller\ArgumentResolver;
Chris@14 13
Chris@14 14 use Psr\Container\ContainerInterface;
Chris@14 15 use Symfony\Component\HttpFoundation\Request;
Chris@14 16 use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
Chris@14 17 use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
Chris@14 18
Chris@14 19 /**
Chris@14 20 * Yields a service keyed by _controller and argument name.
Chris@14 21 *
Chris@14 22 * @author Nicolas Grekas <p@tchwork.com>
Chris@14 23 */
Chris@14 24 final class ServiceValueResolver implements ArgumentValueResolverInterface
Chris@14 25 {
Chris@14 26 private $container;
Chris@14 27
Chris@14 28 public function __construct(ContainerInterface $container)
Chris@14 29 {
Chris@14 30 $this->container = $container;
Chris@14 31 }
Chris@14 32
Chris@14 33 /**
Chris@14 34 * {@inheritdoc}
Chris@14 35 */
Chris@14 36 public function supports(Request $request, ArgumentMetadata $argument)
Chris@14 37 {
Chris@14 38 $controller = $request->attributes->get('_controller');
Chris@14 39
Chris@14 40 if (\is_array($controller) && \is_callable($controller, true) && \is_string($controller[0])) {
Chris@14 41 $controller = $controller[0].'::'.$controller[1];
Chris@14 42 }
Chris@14 43
Chris@14 44 return \is_string($controller) && $this->container->has($controller) && $this->container->get($controller)->has($argument->getName());
Chris@14 45 }
Chris@14 46
Chris@14 47 /**
Chris@14 48 * {@inheritdoc}
Chris@14 49 */
Chris@14 50 public function resolve(Request $request, ArgumentMetadata $argument)
Chris@14 51 {
Chris@14 52 if (\is_array($controller = $request->attributes->get('_controller'))) {
Chris@14 53 $controller = $controller[0].'::'.$controller[1];
Chris@14 54 }
Chris@14 55
Chris@14 56 yield $this->container->get($controller)->get($argument->getName());
Chris@14 57 }
Chris@14 58 }