Skip to content

Commit 268b752

Browse files
Merge branch '2.8' into 3.1
* 2.8: [Routing] Fail properly when a route parameter name cannot be used as a PCRE subpattern name [FrameworkBundle] Improve performance of ControllerNameParser Update documentation link to the component [HttpFoundation] Add links to RFC-7231 [DI] Initialize properties before method calls Tag missing internals [WebProfilerBundle] Dont use request attributes in RouterController Fix complete config tests
2 parents 13d2f4f + e2035e9 commit 268b752

File tree

7 files changed

+63
-13
lines changed

7 files changed

+63
-13
lines changed

ContainerBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,15 +860,15 @@ private function createService(Definition $definition, $id, $tryProxy = true)
860860
$this->shareService($definition, $service, $id);
861861
}
862862

863-
foreach ($definition->getMethodCalls() as $call) {
864-
$this->callMethod($service, $call);
865-
}
866-
867863
$properties = $this->resolveServices($parameterBag->unescapeValue($parameterBag->resolveValue($definition->getProperties())));
868864
foreach ($properties as $name => $value) {
869865
$service->$name = $value;
870866
}
871867

868+
foreach ($definition->getMethodCalls() as $call) {
869+
$this->callMethod($service, $call);
870+
}
871+
872872
if ($callable = $definition->getConfigurator()) {
873873
if (is_array($callable)) {
874874
$callable[0] = $parameterBag->resolveValue($callable[0]);

Dumper/PhpDumper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ private function addServiceInlinedDefinitions($id, $definition)
334334
$code .= $this->addNewInstance($sDefinition, '$'.$name, ' = ', $id);
335335

336336
if (!$this->hasReference($id, $sDefinition->getMethodCalls(), true) && !$this->hasReference($id, $sDefinition->getProperties(), true)) {
337-
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
338337
$code .= $this->addServiceProperties(null, $sDefinition, $name);
338+
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
339339
$code .= $this->addServiceConfigurator(null, $sDefinition, $name);
340340
}
341341

@@ -504,8 +504,8 @@ private function addServiceInlinedDefinitionsSetup($id, Definition $definition)
504504
}
505505

506506
$name = (string) $this->definitionVariables->offsetGet($iDefinition);
507-
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
508507
$code .= $this->addServiceProperties(null, $iDefinition, $name);
508+
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
509509
$code .= $this->addServiceConfigurator(null, $iDefinition, $name);
510510
}
511511

@@ -663,8 +663,8 @@ private function addService($id, Definition $definition)
663663
$this->addServiceInlinedDefinitions($id, $definition).
664664
$this->addServiceInstance($id, $definition).
665665
$this->addServiceInlinedDefinitionsSetup($id, $definition).
666-
$this->addServiceMethodCalls($id, $definition).
667666
$this->addServiceProperties($id, $definition).
667+
$this->addServiceMethodCalls($id, $definition).
668668
$this->addServiceConfigurator($id, $definition).
669669
$this->addServiceReturn($id, $definition)
670670
;

Tests/ContainerBuilderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,20 @@ public function testLazyLoadedService()
756756
$this->assertTrue($classInList);
757757
}
758758

759+
public function testInitializePropertiesBeforeMethodCalls()
760+
{
761+
$container = new ContainerBuilder();
762+
$container->register('foo', 'stdClass');
763+
$container->register('bar', 'MethodCallClass')
764+
->setProperty('simple', 'bar')
765+
->setProperty('complex', new Reference('foo'))
766+
->addMethodCall('callMe');
767+
768+
$container->compile();
769+
770+
$this->assertTrue($container->get('bar')->callPassed(), '->compile() initializes properties before method calls');
771+
}
772+
759773
public function testAutowiring()
760774
{
761775
$container = new ContainerBuilder();

Tests/Dumper/PhpDumperTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,23 @@ public function testInlinedDefinitionReferencingServiceContainer()
295295
$dumper = new PhpDumper($container);
296296
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services13.php', $dumper->dump(), '->dump() dumps inline definitions which reference service_container');
297297
}
298+
299+
public function testInitializePropertiesBeforeMethodCalls()
300+
{
301+
require_once self::$fixturesPath.'/includes/classes.php';
302+
303+
$container = new ContainerBuilder();
304+
$container->register('foo', 'stdClass');
305+
$container->register('bar', 'MethodCallClass')
306+
->setProperty('simple', 'bar')
307+
->setProperty('complex', new Reference('foo'))
308+
->addMethodCall('callMe');
309+
$container->compile();
310+
311+
$dumper = new PhpDumper($container);
312+
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Properties_Before_Method_Calls')));
313+
314+
$container = new \Symfony_DI_PhpDumper_Test_Properties_Before_Method_Calls();
315+
$this->assertTrue($container->get('bar')->callPassed(), '->dump() initializes properties before method calls');
316+
}
298317
}

Tests/Fixtures/includes/classes.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,20 @@ public function __construct(BarClass $bar)
5959
$this->bar = $bar;
6060
}
6161
}
62+
63+
class MethodCallClass
64+
{
65+
public $simple;
66+
public $complex;
67+
private $callPassed = false;
68+
69+
public function callMe()
70+
{
71+
$this->callPassed = is_scalar($this->simple) && is_object($this->complex);
72+
}
73+
74+
public function callPassed()
75+
{
76+
return $this->callPassed;
77+
}
78+
}

Tests/Fixtures/php/services9.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ protected function getFooService()
221221

222222
$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo')), true, $this);
223223

224-
$instance->setBar($this->get('bar'));
225-
$instance->initialize();
226224
$instance->foo = 'bar';
227225
$instance->moo = $a;
228226
$instance->qux = array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo'));
227+
$instance->setBar($this->get('bar'));
228+
$instance->initialize();
229229
sc_configure($instance);
230230

231231
return $instance;
@@ -418,8 +418,8 @@ protected function getInlinedService()
418418
{
419419
$this->services['inlined'] = $instance = new \Bar();
420420

421-
$instance->setBaz($this->get('baz'));
422421
$instance->pub = 'pub';
422+
$instance->setBaz($this->get('baz'));
423423

424424
return $instance;
425425
}

Tests/Fixtures/php/services9_compiled.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ protected function getFooService()
224224

225225
$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this);
226226

227-
$instance->setBar($this->get('bar'));
228-
$instance->initialize();
229227
$instance->foo = 'bar';
230228
$instance->moo = $a;
231229
$instance->qux = array('bar' => 'foo is bar', 'foobar' => 'bar');
230+
$instance->setBar($this->get('bar'));
231+
$instance->initialize();
232232
sc_configure($instance);
233233

234234
return $instance;
@@ -275,8 +275,8 @@ protected function getFooWithInlineService()
275275

276276
$this->services['foo_with_inline'] = $instance = new \Foo();
277277

278-
$a->setBaz($this->get('baz'));
279278
$a->pub = 'pub';
279+
$a->setBaz($this->get('baz'));
280280

281281
$instance->setBar($a);
282282

0 commit comments

Comments
 (0)