|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Symfony package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
|
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\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Argument\AbstractArgument; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
18
|
|
|
use Symfony\Component\VarExporter\ProxyHelper; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Resolves named arguments to their corresponding numeric index. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Kévin Dunglas <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class ResolveNamedArgumentsPass extends AbstractRecursivePass |
|
26
|
|
|
{ |
|
27
|
|
|
protected bool $skipScalars = true; |
|
28
|
|
|
|
|
29
|
|
|
protected function processValue(mixed $value, bool $isRoot = false): mixed |
|
30
|
|
|
{ |
|
31
|
|
|
if ($value instanceof AbstractArgument && $value->getText().'.' === $value->getTextWithContext()) { |
|
32
|
|
|
$value->setContext(\sprintf('A value found in service "%s"', $this->currentId)); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if (!$value instanceof Definition) { |
|
36
|
|
|
return parent::processValue($value, $isRoot); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$calls = $value->getMethodCalls(); |
|
40
|
|
|
$calls[] = ['__construct', $value->getArguments()]; |
|
41
|
|
|
|
|
42
|
|
|
foreach ($calls as $i => $call) { |
|
43
|
|
|
[$method, $arguments] = $call; |
|
44
|
|
|
$parameters = null; |
|
45
|
|
|
$resolvedKeys = []; |
|
46
|
|
|
$resolvedArguments = []; |
|
47
|
|
|
|
|
48
|
|
|
foreach ($arguments as $key => $argument) { |
|
49
|
|
|
if ($argument instanceof AbstractArgument && $argument->getText().'.' === $argument->getTextWithContext()) { |
|
50
|
|
|
$argument->setContext(\sprintf('Argument '.(\is_int($key) ? 1 + $key : '"%3$s"').' of '.('__construct' === $method ? 'service "%s"' : 'method call "%s::%s()"'), $this->currentId, $method, $key)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (\is_int($key)) { |
|
54
|
|
|
$resolvedKeys[$key] = $key; |
|
55
|
|
|
$resolvedArguments[$key] = $argument; |
|
56
|
|
|
continue; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if (null === $parameters) { |
|
60
|
|
|
$r = $this->getReflectionMethod($value, $method); |
|
61
|
|
|
$class = $r instanceof \ReflectionMethod ? $r->class : $this->currentId; |
|
62
|
|
|
$method = $r->getName(); |
|
63
|
|
|
$parameters = $r->getParameters(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if (isset($key[0]) && '$' !== $key[0] && !class_exists($key) && !interface_exists($key, false)) { |
|
67
|
|
|
throw new InvalidArgumentException(\sprintf('Invalid service "%s": did you forget to add the "$" prefix to argument "%s"?', $this->currentId, $key)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (isset($key[0]) && '$' === $key[0]) { |
|
71
|
|
|
foreach ($parameters as $j => $p) { |
|
72
|
|
|
if ($key === '$'.$p->name) { |
|
73
|
|
|
if ($p->isVariadic() && \is_array($argument)) { |
|
74
|
|
|
foreach ($argument as $variadicArgument) { |
|
75
|
|
|
$resolvedKeys[$j] = $j; |
|
76
|
|
|
$resolvedArguments[$j++] = $variadicArgument; |
|
77
|
|
|
} |
|
78
|
|
|
} else { |
|
79
|
|
|
$resolvedKeys[$j] = $p->name; |
|
80
|
|
|
$resolvedArguments[$j] = $argument; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
continue 2; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
throw new InvalidArgumentException(\sprintf('Invalid service "%s": method "%s()" has no argument named "%s". Check your service definition.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method, $key)); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if (null !== $argument && !$argument instanceof Reference && !$argument instanceof Definition) { |
|
91
|
|
|
throw new InvalidArgumentException(\sprintf('Invalid service "%s": the value of argument "%s" of method "%s()" must be null, an instance of "%s" or an instance of "%s", "%s" given.', $this->currentId, $key, $class !== $this->currentId ? $class.'::'.$method : $method, Reference::class, Definition::class, get_debug_type($argument))); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$typeFound = false; |
|
95
|
|
|
foreach ($parameters as $j => $p) { |
|
96
|
|
|
if (!\array_key_exists($j, $resolvedArguments) && ProxyHelper::exportType($p, true) === $key) { |
|
97
|
|
|
$resolvedKeys[$j] = $p->name; |
|
98
|
|
|
$resolvedArguments[$j] = $argument; |
|
99
|
|
|
$typeFound = true; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
if (!$typeFound) { |
|
104
|
|
|
throw new InvalidArgumentException(\sprintf('Invalid service "%s": method "%s()" has no argument type-hinted as "%s". Check your service definition.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method, $key)); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if ($resolvedArguments !== $call[1]) { |
|
109
|
|
|
ksort($resolvedArguments); |
|
110
|
|
|
|
|
111
|
|
|
if (!$value->isAutowired() && !array_is_list($resolvedArguments)) { |
|
|
|
|
|
|
112
|
|
|
ksort($resolvedKeys); |
|
113
|
|
|
$resolvedArguments = array_combine($resolvedKeys, $resolvedArguments); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$calls[$i][1] = $resolvedArguments; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
[, $arguments] = array_pop($calls); |
|
121
|
|
|
|
|
122
|
|
|
if ($arguments !== $value->getArguments()) { |
|
123
|
|
|
$value->setArguments($arguments); |
|
124
|
|
|
} |
|
125
|
|
|
if ($calls !== $value->getMethodCalls()) { |
|
126
|
|
|
$value->setMethodCalls($calls); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
foreach ($value->getProperties() as $key => $argument) { |
|
130
|
|
|
if ($argument instanceof AbstractArgument && $argument->getText().'.' === $argument->getTextWithContext()) { |
|
131
|
|
|
$argument->setContext(\sprintf('Property "%s" of service "%s"', $key, $this->currentId)); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return parent::processValue($value, $isRoot); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths