Skip to content

Commit 3e61303

Browse files
Merge branch '3.2'
* 3.2: [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 [Bridge/Doctrine] Use cache.prefix.seed parameter for generating cache namespace Tag missing internals Add missing example for 'path' argument in debug:config [WebProfilerBundle] Dont use request attributes in RouterController Fix complete config tests
2 parents 0a61402 + f5419ad commit 3e61303

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
@@ -901,15 +901,15 @@ private function createService(Definition $definition, $id, $tryProxy = true)
901901
$this->shareService($definition, $service, $id);
902902
}
903903

904-
foreach ($definition->getMethodCalls() as $call) {
905-
$this->callMethod($service, $call);
906-
}
907-
908904
$properties = $this->resolveServices($parameterBag->unescapeValue($parameterBag->resolveValue($definition->getProperties())));
909905
foreach ($properties as $name => $value) {
910906
$service->$name = $value;
911907
}
912908

909+
foreach ($definition->getMethodCalls() as $call) {
910+
$this->callMethod($service, $call);
911+
}
912+
913913
if ($callable = $definition->getConfigurator()) {
914914
if (is_array($callable)) {
915915
$callable[0] = $parameterBag->resolveValue($callable[0]);

Dumper/PhpDumper.php

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

349349
if (!$this->hasReference($id, $sDefinition->getMethodCalls(), true) && !$this->hasReference($id, $sDefinition->getProperties(), true)) {
350-
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
351350
$code .= $this->addServiceProperties(null, $sDefinition, $name);
351+
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
352352
$code .= $this->addServiceConfigurator(null, $sDefinition, $name);
353353
}
354354

@@ -517,8 +517,8 @@ private function addServiceInlinedDefinitionsSetup($id, Definition $definition)
517517
}
518518

519519
$name = (string) $this->definitionVariables->offsetGet($iDefinition);
520-
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
521520
$code .= $this->addServiceProperties(null, $iDefinition, $name);
521+
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
522522
$code .= $this->addServiceConfigurator(null, $iDefinition, $name);
523523
}
524524

@@ -678,8 +678,8 @@ private function addService($id, Definition $definition)
678678
$this->addServiceInlinedDefinitions($id, $definition).
679679
$this->addServiceInstance($id, $definition).
680680
$this->addServiceInlinedDefinitionsSetup($id, $definition).
681-
$this->addServiceMethodCalls($id, $definition).
682681
$this->addServiceProperties($id, $definition).
682+
$this->addServiceMethodCalls($id, $definition).
683683
$this->addServiceConfigurator($id, $definition).
684684
$this->addServiceReturn($id, $definition)
685685
;

Tests/ContainerBuilderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,20 @@ public function testLazyLoadedService()
796796
$this->assertTrue($classInList);
797797
}
798798

799+
public function testInitializePropertiesBeforeMethodCalls()
800+
{
801+
$container = new ContainerBuilder();
802+
$container->register('foo', 'stdClass');
803+
$container->register('bar', 'MethodCallClass')
804+
->setProperty('simple', 'bar')
805+
->setProperty('complex', new Reference('foo'))
806+
->addMethodCall('callMe');
807+
808+
$container->compile();
809+
810+
$this->assertTrue($container->get('bar')->callPassed(), '->compile() initializes properties before method calls');
811+
}
812+
799813
public function testAutowiring()
800814
{
801815
$container = new ContainerBuilder();

Tests/Dumper/PhpDumperTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,23 @@ public function testInlinedDefinitionReferencingServiceContainer()
321321
$dumper = new PhpDumper($container);
322322
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services13.php', $dumper->dump(), '->dump() dumps inline definitions which reference service_container');
323323
}
324+
325+
public function testInitializePropertiesBeforeMethodCalls()
326+
{
327+
require_once self::$fixturesPath.'/includes/classes.php';
328+
329+
$container = new ContainerBuilder();
330+
$container->register('foo', 'stdClass');
331+
$container->register('bar', 'MethodCallClass')
332+
->setProperty('simple', 'bar')
333+
->setProperty('complex', new Reference('foo'))
334+
->addMethodCall('callMe');
335+
$container->compile();
336+
337+
$dumper = new PhpDumper($container);
338+
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Properties_Before_Method_Calls')));
339+
340+
$container = new \Symfony_DI_PhpDumper_Test_Properties_Before_Method_Calls();
341+
$this->assertTrue($container->get('bar')->callPassed(), '->dump() initializes properties before method calls');
342+
}
324343
}

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
@@ -228,11 +228,11 @@ protected function getFooService()
228228

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

231-
$instance->setBar($this->get('bar'));
232-
$instance->initialize();
233231
$instance->foo = 'bar';
234232
$instance->moo = $a;
235233
$instance->qux = array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo'));
234+
$instance->setBar($this->get('bar'));
235+
$instance->initialize();
236236
sc_configure($instance);
237237

238238
return $instance;
@@ -425,8 +425,8 @@ protected function getInlinedService()
425425
{
426426
$this->services['inlined'] = $instance = new \Bar();
427427

428-
$instance->setBaz($this->get('baz'));
429428
$instance->pub = 'pub';
429+
$instance->setBaz($this->get('baz'));
430430

431431
return $instance;
432432
}

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)