Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a126c8

Browse filesBrowse files
nicolas-grekasdunglas
authored andcommitted
[DI] Deprecate string keys in arguments
1 parent 2ce36a6 commit 8a126c8
Copy full SHA for 8a126c8

File tree

Expand file treeCollapse file tree

4 files changed

+17
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+17
-11
lines changed
Open diff view settings
Collapse file

‎src/Symfony/Component/DependencyInjection/ChildDefinition.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ChildDefinition.php
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,14 @@ public function getArgument($index)
213213
*/
214214
public function replaceArgument($index, $value)
215215
{
216-
if (!is_int($index)) {
216+
if (is_int($index)) {
217+
$this->arguments['index_'.$index] = $value;
218+
} elseif (0 === strpos($index, '$')) {
219+
$this->arguments[$index] = $value;
220+
} else {
217221
throw new InvalidArgumentException('$index must be an integer.');
218222
}
219223

220-
$this->arguments['index_'.$index] = $value;
221-
222224
return $this;
223225
}
224226
}
Collapse file

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ private function doResolveDefinition(ChildDefinition $definition)
145145
continue;
146146
}
147147

148-
if (0 !== strpos($k, 'index_')) {
148+
if (0 === strpos($k, 'index_')) {
149+
$index = (int) substr($k, strlen('index_'));
150+
} elseif (0 !== strpos($k, '$')) {
149151
throw new RuntimeException(sprintf('Invalid argument key "%s" found.', $k));
150152
}
151153

152-
$index = (int) substr($k, strlen('index_'));
153154
$def->replaceArgument($index, $v);
154155
}
155156

Collapse file

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,22 @@ protected function processValue($value, $isRoot = false)
4343
list($method, $arguments) = $call;
4444
$method = $parameterBag->resolveValue($method);
4545
$parameters = null;
46+
$resolvedArguments = array();
4647

4748
foreach ($arguments as $key => $argument) {
4849
if (is_int($key) || '' === $key || '$' !== $key[0]) {
50+
if (!is_int($key)) {
51+
@trigger_error(sprintf('Using key "%s" for defining arguments of method "%s" for service "%s" is deprecated since Symfony 3.3 and will throw an exception in 4.0. Use no keys or $named arguments instead.', $key, $method, $this->currentId), E_USER_DEPRECATED);
52+
}
53+
$resolvedArguments[] = $argument;
4954
continue;
5055
}
5156

5257
$parameters = null !== $parameters ? $parameters : $this->getParameters($class, $method);
5358

5459
foreach ($parameters as $j => $p) {
5560
if ($key === '$'.$p->name) {
56-
unset($arguments[$key]);
57-
$arguments[$j] = $argument;
61+
$resolvedArguments[$j] = $argument;
5862

5963
continue 2;
6064
}
@@ -63,9 +67,9 @@ protected function processValue($value, $isRoot = false)
6367
throw new InvalidArgumentException(sprintf('Unable to resolve service "%s": method "%s::%s" has no argument named "%s". Check your service definition.', $this->currentId, $class, $method, $key));
6468
}
6569

66-
if ($arguments !== $call[1]) {
67-
ksort($arguments);
68-
$calls[$i][1] = $arguments;
70+
if ($resolvedArguments !== $call[1]) {
71+
ksort($resolvedArguments);
72+
$calls[$i][1] = $resolvedArguments;
6973
}
7074
}
7175

Collapse file

‎src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\Component\DependencyInjection\Reference;
2121
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
2222
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
23-
use Symfony\Component\Config\Resource\FileResource;
2423
use Symfony\Component\Yaml\Exception\ParseException;
2524
use Symfony\Component\Yaml\Parser as YamlParser;
2625
use Symfony\Component\Yaml\Tag\TaggedValue;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.