Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/http-kernel/Controller/ArgumentResolver.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
32 /** | 32 /** |
33 * @var iterable|ArgumentValueResolverInterface[] | 33 * @var iterable|ArgumentValueResolverInterface[] |
34 */ | 34 */ |
35 private $argumentValueResolvers; | 35 private $argumentValueResolvers; |
36 | 36 |
37 public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, $argumentValueResolvers = array()) | 37 public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, $argumentValueResolvers = []) |
38 { | 38 { |
39 $this->argumentMetadataFactory = $argumentMetadataFactory ?: new ArgumentMetadataFactory(); | 39 $this->argumentMetadataFactory = $argumentMetadataFactory ?: new ArgumentMetadataFactory(); |
40 $this->argumentValueResolvers = $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers(); | 40 $this->argumentValueResolvers = $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers(); |
41 } | 41 } |
42 | 42 |
43 /** | 43 /** |
44 * {@inheritdoc} | 44 * {@inheritdoc} |
45 */ | 45 */ |
46 public function getArguments(Request $request, $controller) | 46 public function getArguments(Request $request, $controller) |
47 { | 47 { |
48 $arguments = array(); | 48 $arguments = []; |
49 | 49 |
50 foreach ($this->argumentMetadataFactory->createArgumentMetadata($controller) as $metadata) { | 50 foreach ($this->argumentMetadataFactory->createArgumentMetadata($controller) as $metadata) { |
51 foreach ($this->argumentValueResolvers as $resolver) { | 51 foreach ($this->argumentValueResolvers as $resolver) { |
52 if (!$resolver->supports($request, $metadata)) { | 52 if (!$resolver->supports($request, $metadata)) { |
53 continue; | 53 continue; |
54 } | 54 } |
55 | 55 |
56 $resolved = $resolver->resolve($request, $metadata); | 56 $resolved = $resolver->resolve($request, $metadata); |
57 | 57 |
58 if (!$resolved instanceof \Generator) { | 58 if (!$resolved instanceof \Generator) { |
59 throw new \InvalidArgumentException(sprintf('%s::resolve() must yield at least one value.', get_class($resolver))); | 59 throw new \InvalidArgumentException(sprintf('%s::resolve() must yield at least one value.', \get_class($resolver))); |
60 } | 60 } |
61 | 61 |
62 foreach ($resolved as $append) { | 62 foreach ($resolved as $append) { |
63 $arguments[] = $append; | 63 $arguments[] = $append; |
64 } | 64 } |
67 continue 2; | 67 continue 2; |
68 } | 68 } |
69 | 69 |
70 $representative = $controller; | 70 $representative = $controller; |
71 | 71 |
72 if (is_array($representative)) { | 72 if (\is_array($representative)) { |
73 $representative = sprintf('%s::%s()', get_class($representative[0]), $representative[1]); | 73 $representative = sprintf('%s::%s()', \get_class($representative[0]), $representative[1]); |
74 } elseif (is_object($representative)) { | 74 } elseif (\is_object($representative)) { |
75 $representative = get_class($representative); | 75 $representative = \get_class($representative); |
76 } | 76 } |
77 | 77 |
78 throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.', $representative, $metadata->getName())); | 78 throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.', $representative, $metadata->getName())); |
79 } | 79 } |
80 | 80 |
81 return $arguments; | 81 return $arguments; |
82 } | 82 } |
83 | 83 |
84 public static function getDefaultArgumentValueResolvers() | 84 public static function getDefaultArgumentValueResolvers() |
85 { | 85 { |
86 return array( | 86 return [ |
87 new RequestAttributeValueResolver(), | 87 new RequestAttributeValueResolver(), |
88 new RequestValueResolver(), | 88 new RequestValueResolver(), |
89 new SessionValueResolver(), | 89 new SessionValueResolver(), |
90 new DefaultValueResolver(), | 90 new DefaultValueResolver(), |
91 new VariadicValueResolver(), | 91 new VariadicValueResolver(), |
92 ); | 92 ]; |
93 } | 93 } |
94 } | 94 } |