Skip to content

Commit 8b1d07e

Browse files
committed
Merge remote-tracking branch 'origin/2.7' into 2.8
Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php
2 parents 6123a8b + 74c4cda commit 8b1d07e

File tree

8 files changed

+66
-12
lines changed

8 files changed

+66
-12
lines changed

Compiler/ResolveDefinitionTemplatesPass.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ private function resolveDefinition(ContainerBuilder $container, DefinitionDecora
162162
if (isset($changes['lazy'])) {
163163
$def->setLazy($definition->isLazy());
164164
}
165+
if (isset($changes['decorated_service'])) {
166+
$decoratedService = $definition->getDecoratedService();
167+
if (null === $decoratedService) {
168+
$def->setDecoratedService($decoratedService);
169+
} else {
170+
$def->setDecoratedService($decoratedService[0], $decoratedService[1]);
171+
}
172+
}
165173

166174
// merge arguments
167175
foreach ($definition->getArguments() as $k => $v) {

DefinitionDecorator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ public function setLazy($boolean)
170170
return parent::setLazy($boolean);
171171
}
172172

173+
/**
174+
* {@inheritdoc}
175+
*/
176+
public function setDecoratedService($id, $renamedId = null)
177+
{
178+
$this->changes['decorated_service'] = true;
179+
180+
return parent::setDecoratedService($id, $renamedId);
181+
}
182+
173183
/**
174184
* Gets an argument to pass to the service constructor/factory method.
175185
*

Dumper/PhpDumper.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,11 +1301,6 @@ private function dumpValue($value, $interpolate = true)
13011301
foreach ($value->getArguments() as $argument) {
13021302
$arguments[] = $this->dumpValue($argument);
13031303
}
1304-
$class = $this->dumpValue($value->getClass());
1305-
1306-
if (false !== strpos($class, '$')) {
1307-
throw new RuntimeException('Cannot dump definitions which have a variable class name.');
1308-
}
13091304

13101305
if (null !== $value->getFactory()) {
13111306
$factory = $value->getFactory();
@@ -1343,6 +1338,15 @@ private function dumpValue($value, $interpolate = true)
13431338
}
13441339
}
13451340

1341+
$class = $value->getClass();
1342+
if (null === $class) {
1343+
throw new RuntimeException('Cannot dump definitions which have no class nor factory.');
1344+
}
1345+
$class = $this->dumpValue($class);
1346+
if (false !== strpos($class, '$')) {
1347+
throw new RuntimeException('Cannot dump definitions which have a variable class name.');
1348+
}
1349+
13461350
return sprintf('new \\%s(%s)', substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
13471351
} elseif ($value instanceof Variable) {
13481352
return '$'.$value;

Loader/XmlFileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private function parseDefinition(\DOMElement $service, $file)
151151
foreach (array('class', 'shared', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'lazy', 'abstract') as $key) {
152152
if ($value = $service->getAttribute($key)) {
153153
if (in_array($key, array('factory-class', 'factory-method', 'factory-service'))) {
154-
@trigger_error(sprintf('The "%s" attribute in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use the "factory" element instead.', $key, $file), E_USER_DEPRECATED);
154+
@trigger_error(sprintf('The "%s" attribute of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use the "factory" element instead.', $key, (string) $service->getAttribute('id'), $file), E_USER_DEPRECATED);
155155
}
156156
$method = 'set'.str_replace('-', '', $key);
157157
$definition->$method(XmlUtils::phpize($value));
@@ -172,7 +172,7 @@ private function parseDefinition(\DOMElement $service, $file)
172172
$triggerDeprecation = 'request' !== (string) $service->getAttribute('id');
173173

174174
if ($triggerDeprecation) {
175-
@trigger_error(sprintf('The "synchronized" attribute in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', $file), E_USER_DEPRECATED);
175+
@trigger_error(sprintf('The "synchronized" attribute of service "%s" in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', (string) $service->getAttribute('id'), $file), E_USER_DEPRECATED);
176176
}
177177

178178
$definition->setSynchronized(XmlUtils::phpize($value), $triggerDeprecation);

Loader/YamlFileLoader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private function parseDefinition($id, $service, $file)
179179
}
180180

181181
if (isset($service['synchronized'])) {
182-
@trigger_error(sprintf('The "synchronized" key in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', $file), E_USER_DEPRECATED);
182+
@trigger_error(sprintf('The "synchronized" key of service "%s" in file "%s" is deprecated since version 2.7 and will be removed in 3.0.', $id, $file), E_USER_DEPRECATED);
183183
$definition->setSynchronized($service['synchronized'], 'request' !== $id);
184184
}
185185

@@ -209,17 +209,17 @@ private function parseDefinition($id, $service, $file)
209209
}
210210

211211
if (isset($service['factory_class'])) {
212-
@trigger_error(sprintf('The "factory_class" key in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $file), E_USER_DEPRECATED);
212+
@trigger_error(sprintf('The "factory_class" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
213213
$definition->setFactoryClass($service['factory_class']);
214214
}
215215

216216
if (isset($service['factory_method'])) {
217-
@trigger_error(sprintf('The "factory_method" key in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $file), E_USER_DEPRECATED);
217+
@trigger_error(sprintf('The "factory_method" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
218218
$definition->setFactoryMethod($service['factory_method']);
219219
}
220220

221221
if (isset($service['factory_service'])) {
222-
@trigger_error(sprintf('The "factory_service" key in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $file), E_USER_DEPRECATED);
222+
@trigger_error(sprintf('The "factory_service" key of service "%s" in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use "factory" instead.', $id, $file), E_USER_DEPRECATED);
223223
$definition->setFactoryService($service['factory_service']);
224224
}
225225

Tests/Compiler/ResolveDefinitionTemplatesPassTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ public function testProcessDoesNotCopyTags()
120120
$this->assertEquals(array(), $def->getTags());
121121
}
122122

123+
public function testProcessDoesNotCopyDecoratedService()
124+
{
125+
$container = new ContainerBuilder();
126+
127+
$container
128+
->register('parent')
129+
->setDecoratedService('foo')
130+
;
131+
132+
$container
133+
->setDefinition('child', new DefinitionDecorator('parent'))
134+
;
135+
136+
$this->process($container);
137+
138+
$def = $container->getDefinition('child');
139+
$this->assertNull($def->getDecoratedService());
140+
}
141+
123142
public function testProcessHandlesMultipleInheritance()
124143
{
125144
$container = new ContainerBuilder();
@@ -212,6 +231,19 @@ public function testDeepDefinitionsResolving()
212231
$this->assertSame('parentClass', $methodCalls[0][1][0]->getClass());
213232
}
214233

234+
public function testSetDecoratedServiceOnServiceHasParent()
235+
{
236+
$container = new ContainerBuilder();
237+
238+
$container->register('parent', 'stdClass');
239+
240+
$container->setDefinition('child1', new DefinitionDecorator('parent'))
241+
->setDecoratedService('foo', 'foo_inner')
242+
;
243+
244+
$this->assertEquals(array('foo', 'foo_inner'), $container->getDefinition('child1')->getDecoratedService());
245+
}
246+
215247
protected function process(ContainerBuilder $container)
216248
{
217249
$pass = new ResolveDefinitionTemplatesPass();
Binary file not shown.

Tests/Fixtures/includes/createphar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ public function getAlias()
4444
</xsd:schema>
4545
EOT
4646
);
47-
$phar->setStub('<?php require_once "phar://ProjectWithXsdExtensionInPhar.phar/ProjectWithXsdExtensionInPhar.php"; __HALT_COMPILER(); ?>');
47+
$phar->setStub('<?php Phar::mapPhar("ProjectWithXsdExtensionInPhar.phar"); require_once "phar://ProjectWithXsdExtensionInPhar.phar/ProjectWithXsdExtensionInPhar.php"; __HALT_COMPILER(); ?>');

0 commit comments

Comments
 (0)