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 a7f98c6

Browse filesBrowse files
[DI] rename ResolveDefinitionTemplatesPass to ResolveChildDefinitionsPass
1 parent 2fde094 commit a7f98c6
Copy full SHA for a7f98c6

9 files changed

+620
-166
lines changed

‎UPGRADE-3.4.md

Copy file name to clipboardExpand all lines: UPGRADE-3.4.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ DependencyInjection
5252
5353
* Case insensitivity of parameter names is deprecated and will be removed in 4.0.
5454
55+
* The `ResolveDefinitionTemplatesPass` class is deprecated and will be removed in 4.0.
56+
Use the `ResolveChildDefinitionsPass` class instead.
57+
5558
Debug
5659
-----
5760

‎UPGRADE-4.0.md

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ DependencyInjection
159159
* The `DefinitionDecorator` class has been removed. Use the `ChildDefinition`
160160
class instead.
161161

162+
* The `ResolveDefinitionTemplatesPass` class has been removed.
163+
Use the `ResolveChildDefinitionsPass` class instead.
164+
162165
* Using unsupported configuration keys in YAML configuration files raises an
163166
exception.
164167

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* deprecated the ability to check for the initialization of a private service with the `Container::initialized()` method
1010
* deprecated support for top-level anonymous services in XML
1111
* deprecated case insensitivity of parameter names
12+
* deprecated the `ResolveDefinitionTemplatesPass` class in favor of `ResolveChildDefinitionsPass`
1213

1314
3.3.0
1415
-----

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct()
4848

4949
$this->optimizationPasses = array(array(
5050
new ExtensionCompilerPass(),
51-
new ResolveDefinitionTemplatesPass(),
51+
new ResolveChildDefinitionsPass(),
5252
new ServiceLocatorTagPass(),
5353
new DecoratorServicePass(),
5454
new ResolveParameterPlaceHoldersPass(false),
+183Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\ChildDefinition;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Exception\ExceptionInterface;
17+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
18+
19+
/**
20+
* This replaces all ChildDefinition instances with their equivalent fully
21+
* merged Definition instance.
22+
*
23+
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
24+
* @author Nicolas Grekas <p@tchwork.com>
25+
*/
26+
class ResolveChildDefinitionsPass extends AbstractRecursivePass
27+
{
28+
protected function processValue($value, $isRoot = false)
29+
{
30+
if (!$value instanceof Definition) {
31+
return parent::processValue($value, $isRoot);
32+
}
33+
if ($isRoot) {
34+
// yes, we are specifically fetching the definition from the
35+
// container to ensure we are not operating on stale data
36+
$value = $this->container->getDefinition($this->currentId);
37+
}
38+
if ($value instanceof ChildDefinition) {
39+
$value = $this->resolveDefinition($value);
40+
if ($isRoot) {
41+
$this->container->setDefinition($this->currentId, $value);
42+
}
43+
}
44+
45+
return parent::processValue($value, $isRoot);
46+
}
47+
48+
/**
49+
* Resolves the definition.
50+
*
51+
* @return Definition
52+
*
53+
* @throws RuntimeException When the definition is invalid
54+
*/
55+
private function resolveDefinition(ChildDefinition $definition)
56+
{
57+
try {
58+
return $this->doResolveDefinition($definition);
59+
} catch (ExceptionInterface $e) {
60+
$r = new \ReflectionProperty($e, 'message');
61+
$r->setAccessible(true);
62+
$r->setValue($e, sprintf('Service "%s": %s', $this->currentId, $e->getMessage()));
63+
64+
throw $e;
65+
}
66+
}
67+
68+
private function doResolveDefinition(ChildDefinition $definition)
69+
{
70+
if (!$this->container->has($parent = $definition->getParent())) {
71+
throw new RuntimeException(sprintf('Parent definition "%s" does not exist.', $parent));
72+
}
73+
74+
$parentDef = $this->container->findDefinition($parent);
75+
if ($parentDef instanceof ChildDefinition) {
76+
$id = $this->currentId;
77+
$this->currentId = $parent;
78+
$parentDef = $this->resolveDefinition($parentDef);
79+
$this->container->setDefinition($parent, $parentDef);
80+
$this->currentId = $id;
81+
}
82+
83+
$this->container->log($this, sprintf('Resolving inheritance for "%s" (parent: %s).', $this->currentId, $parent));
84+
$def = new Definition();
85+
86+
// merge in parent definition
87+
// purposely ignored attributes: abstract, shared, tags, autoconfigured
88+
$def->setClass($parentDef->getClass());
89+
$def->setArguments($parentDef->getArguments());
90+
$def->setMethodCalls($parentDef->getMethodCalls());
91+
$def->setProperties($parentDef->getProperties());
92+
if ($parentDef->getAutowiringTypes(false)) {
93+
$def->setAutowiringTypes($parentDef->getAutowiringTypes(false));
94+
}
95+
if ($parentDef->isDeprecated()) {
96+
$def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%'));
97+
}
98+
$def->setFactory($parentDef->getFactory());
99+
$def->setConfigurator($parentDef->getConfigurator());
100+
$def->setFile($parentDef->getFile());
101+
$def->setPublic($parentDef->isPublic());
102+
$def->setLazy($parentDef->isLazy());
103+
$def->setAutowired($parentDef->isAutowired());
104+
$def->setChanges($parentDef->getChanges());
105+
106+
$def->setBindings($parentDef->getBindings());
107+
108+
// overwrite with values specified in the decorator
109+
$changes = $definition->getChanges();
110+
if (isset($changes['class'])) {
111+
$def->setClass($definition->getClass());
112+
}
113+
if (isset($changes['factory'])) {
114+
$def->setFactory($definition->getFactory());
115+
}
116+
if (isset($changes['configurator'])) {
117+
$def->setConfigurator($definition->getConfigurator());
118+
}
119+
if (isset($changes['file'])) {
120+
$def->setFile($definition->getFile());
121+
}
122+
if (isset($changes['public'])) {
123+
$def->setPublic($definition->isPublic());
124+
}
125+
if (isset($changes['lazy'])) {
126+
$def->setLazy($definition->isLazy());
127+
}
128+
if (isset($changes['deprecated'])) {
129+
$def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%'));
130+
}
131+
if (isset($changes['autowired'])) {
132+
$def->setAutowired($definition->isAutowired());
133+
}
134+
if (isset($changes['shared'])) {
135+
$def->setShared($definition->isShared());
136+
}
137+
if (isset($changes['decorated_service'])) {
138+
$decoratedService = $definition->getDecoratedService();
139+
if (null === $decoratedService) {
140+
$def->setDecoratedService($decoratedService);
141+
} else {
142+
$def->setDecoratedService($decoratedService[0], $decoratedService[1], $decoratedService[2]);
143+
}
144+
}
145+
146+
// merge arguments
147+
foreach ($definition->getArguments() as $k => $v) {
148+
if (is_numeric($k)) {
149+
$def->addArgument($v);
150+
} elseif (0 === strpos($k, 'index_')) {
151+
$def->replaceArgument((int) substr($k, strlen('index_')), $v);
152+
} else {
153+
$def->setArgument($k, $v);
154+
}
155+
}
156+
157+
// merge properties
158+
foreach ($definition->getProperties() as $k => $v) {
159+
$def->setProperty($k, $v);
160+
}
161+
162+
// append method calls
163+
if ($calls = $definition->getMethodCalls()) {
164+
$def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
165+
}
166+
167+
// merge autowiring types
168+
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
169+
$def->addAutowiringType($autowiringType);
170+
}
171+
172+
// these attributes are always taken from the child
173+
$def->setAbstract($definition->isAbstract());
174+
$def->setTags($definition->getTags());
175+
// autoconfigure is never taken from parent (on purpose)
176+
// and it's not legal on an instanceof
177+
$def->setAutoconfigured($definition->isAutoconfigured());
178+
179+
return $def;
180+
}
181+
}
182+
183+
class_alias(ResolveChildDefinitionsPass::class, ResolveDefinitionTemplatesPass::class);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
+7-159Lines changed: 7 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -11,171 +11,19 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\ChildDefinition;
15-
use Symfony\Component\DependencyInjection\Definition;
16-
use Symfony\Component\DependencyInjection\Exception\ExceptionInterface;
17-
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
14+
@trigger_error('The '.__NAMESPACE__.'\ResolveDefinitionTemplatesPass class is deprecated since version 3.4 and will be removed in 4.0. Use the ResolveChildDefinitionsPass class instead.', E_USER_DEPRECATED);
1815

19-
/**
20-
* This replaces all ChildDefinition instances with their equivalent fully
21-
* merged Definition instance.
22-
*
23-
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
24-
* @author Nicolas Grekas <p@tchwork.com>
25-
*/
26-
class ResolveDefinitionTemplatesPass extends AbstractRecursivePass
27-
{
28-
protected function processValue($value, $isRoot = false)
29-
{
30-
if (!$value instanceof Definition) {
31-
return parent::processValue($value, $isRoot);
32-
}
33-
if ($isRoot) {
34-
// yes, we are specifically fetching the definition from the
35-
// container to ensure we are not operating on stale data
36-
$value = $this->container->getDefinition($this->currentId);
37-
}
38-
if ($value instanceof ChildDefinition) {
39-
$value = $this->resolveDefinition($value);
40-
if ($isRoot) {
41-
$this->container->setDefinition($this->currentId, $value);
42-
}
43-
}
44-
45-
return parent::processValue($value, $isRoot);
46-
}
16+
class_exists(ResolveChildDefinitionsPass::class);
4717

18+
if (false) {
4819
/**
49-
* Resolves the definition.
20+
* This definition decorates another definition.
5021
*
51-
* @return Definition
22+
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
5223
*
53-
* @throws RuntimeException When the definition is invalid
24+
* @deprecated The ResolveDefinitionTemplatesPass class is deprecated since version 3.4 and will be removed in 4.0. Use the ResolveChildDefinitionsPass class instead.
5425
*/
55-
private function resolveDefinition(ChildDefinition $definition)
26+
class ResolveDefinitionTemplatesPass extends AbstractRecursivePass
5627
{
57-
try {
58-
return $this->doResolveDefinition($definition);
59-
} catch (ExceptionInterface $e) {
60-
$r = new \ReflectionProperty($e, 'message');
61-
$r->setAccessible(true);
62-
$r->setValue($e, sprintf('Service "%s": %s', $this->currentId, $e->getMessage()));
63-
64-
throw $e;
65-
}
66-
}
67-
68-
private function doResolveDefinition(ChildDefinition $definition)
69-
{
70-
if (!$this->container->has($parent = $definition->getParent())) {
71-
throw new RuntimeException(sprintf('Parent definition "%s" does not exist.', $parent));
72-
}
73-
74-
$parentDef = $this->container->findDefinition($parent);
75-
if ($parentDef instanceof ChildDefinition) {
76-
$id = $this->currentId;
77-
$this->currentId = $parent;
78-
$parentDef = $this->resolveDefinition($parentDef);
79-
$this->container->setDefinition($parent, $parentDef);
80-
$this->currentId = $id;
81-
}
82-
83-
$this->container->log($this, sprintf('Resolving inheritance for "%s" (parent: %s).', $this->currentId, $parent));
84-
$def = new Definition();
85-
86-
// merge in parent definition
87-
// purposely ignored attributes: abstract, shared, tags, autoconfigured
88-
$def->setClass($parentDef->getClass());
89-
$def->setArguments($parentDef->getArguments());
90-
$def->setMethodCalls($parentDef->getMethodCalls());
91-
$def->setProperties($parentDef->getProperties());
92-
if ($parentDef->getAutowiringTypes(false)) {
93-
$def->setAutowiringTypes($parentDef->getAutowiringTypes(false));
94-
}
95-
if ($parentDef->isDeprecated()) {
96-
$def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%'));
97-
}
98-
$def->setFactory($parentDef->getFactory());
99-
$def->setConfigurator($parentDef->getConfigurator());
100-
$def->setFile($parentDef->getFile());
101-
$def->setPublic($parentDef->isPublic());
102-
$def->setLazy($parentDef->isLazy());
103-
$def->setAutowired($parentDef->isAutowired());
104-
$def->setChanges($parentDef->getChanges());
105-
106-
$def->setBindings($parentDef->getBindings());
107-
108-
// overwrite with values specified in the decorator
109-
$changes = $definition->getChanges();
110-
if (isset($changes['class'])) {
111-
$def->setClass($definition->getClass());
112-
}
113-
if (isset($changes['factory'])) {
114-
$def->setFactory($definition->getFactory());
115-
}
116-
if (isset($changes['configurator'])) {
117-
$def->setConfigurator($definition->getConfigurator());
118-
}
119-
if (isset($changes['file'])) {
120-
$def->setFile($definition->getFile());
121-
}
122-
if (isset($changes['public'])) {
123-
$def->setPublic($definition->isPublic());
124-
}
125-
if (isset($changes['lazy'])) {
126-
$def->setLazy($definition->isLazy());
127-
}
128-
if (isset($changes['deprecated'])) {
129-
$def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%'));
130-
}
131-
if (isset($changes['autowired'])) {
132-
$def->setAutowired($definition->isAutowired());
133-
}
134-
if (isset($changes['shared'])) {
135-
$def->setShared($definition->isShared());
136-
}
137-
if (isset($changes['decorated_service'])) {
138-
$decoratedService = $definition->getDecoratedService();
139-
if (null === $decoratedService) {
140-
$def->setDecoratedService($decoratedService);
141-
} else {
142-
$def->setDecoratedService($decoratedService[0], $decoratedService[1], $decoratedService[2]);
143-
}
144-
}
145-
146-
// merge arguments
147-
foreach ($definition->getArguments() as $k => $v) {
148-
if (is_numeric($k)) {
149-
$def->addArgument($v);
150-
} elseif (0 === strpos($k, 'index_')) {
151-
$def->replaceArgument((int) substr($k, strlen('index_')), $v);
152-
} else {
153-
$def->setArgument($k, $v);
154-
}
155-
}
156-
157-
// merge properties
158-
foreach ($definition->getProperties() as $k => $v) {
159-
$def->setProperty($k, $v);
160-
}
161-
162-
// append method calls
163-
if ($calls = $definition->getMethodCalls()) {
164-
$def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
165-
}
166-
167-
// merge autowiring types
168-
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
169-
$def->addAutowiringType($autowiringType);
170-
}
171-
172-
// these attributes are always taken from the child
173-
$def->setAbstract($definition->isAbstract());
174-
$def->setTags($definition->getTags());
175-
// autoconfigure is never taken from parent (on purpose)
176-
// and it's not legal on an instanceof
177-
$def->setAutoconfigured($definition->isAutoconfigured());
178-
179-
return $def;
18028
}
18129
}

0 commit comments

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