Skip to content

Commit e2035e9

Browse files
Merge branch '2.7' into 2.8
* 2.7: [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 c1002fa + 46574a9 commit e2035e9

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
@@ -937,15 +937,15 @@ public function createService(Definition $definition, $id, $tryProxy = true)
937937
$this->shareService($definition, $service, $id);
938938
}
939939

940-
foreach ($definition->getMethodCalls() as $call) {
941-
$this->callMethod($service, $call);
942-
}
943-
944940
$properties = $this->resolveServices($parameterBag->unescapeValue($parameterBag->resolveValue($definition->getProperties())));
945941
foreach ($properties as $name => $value) {
946942
$service->$name = $value;
947943
}
948944

945+
foreach ($definition->getMethodCalls() as $call) {
946+
$this->callMethod($service, $call);
947+
}
948+
949949
if ($callable = $definition->getConfigurator()) {
950950
if (is_array($callable)) {
951951
$callable[0] = $parameterBag->resolveValue($callable[0]);

Dumper/PhpDumper.php

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

337337
if (!$this->hasReference($id, $sDefinition->getMethodCalls(), true) && !$this->hasReference($id, $sDefinition->getProperties(), true)) {
338-
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
339338
$code .= $this->addServiceProperties(null, $sDefinition, $name);
339+
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
340340
$code .= $this->addServiceConfigurator(null, $sDefinition, $name);
341341
}
342342

@@ -507,8 +507,8 @@ private function addServiceInlinedDefinitionsSetup($id, Definition $definition)
507507
}
508508

509509
$name = (string) $this->definitionVariables->offsetGet($iDefinition);
510-
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
511510
$code .= $this->addServiceProperties(null, $iDefinition, $name);
511+
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
512512
$code .= $this->addServiceConfigurator(null, $iDefinition, $name);
513513
}
514514

@@ -683,8 +683,8 @@ private function addService($id, Definition $definition)
683683
$this->addServiceInlinedDefinitions($id, $definition).
684684
$this->addServiceInstance($id, $definition).
685685
$this->addServiceInlinedDefinitionsSetup($id, $definition).
686-
$this->addServiceMethodCalls($id, $definition).
687686
$this->addServiceProperties($id, $definition).
687+
$this->addServiceMethodCalls($id, $definition).
688688
$this->addServiceConfigurator($id, $definition).
689689
$this->addServiceReturn($id, $definition)
690690
;

Tests/ContainerBuilderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,20 @@ public function testLazyLoadedService()
858858
$this->assertTrue($classInList);
859859
}
860860

861+
public function testInitializePropertiesBeforeMethodCalls()
862+
{
863+
$container = new ContainerBuilder();
864+
$container->register('foo', 'stdClass');
865+
$container->register('bar', 'MethodCallClass')
866+
->setProperty('simple', 'bar')
867+
->setProperty('complex', new Reference('foo'))
868+
->addMethodCall('callMe');
869+
870+
$container->compile();
871+
872+
$this->assertTrue($container->get('bar')->callPassed(), '->compile() initializes properties before method calls');
873+
}
874+
861875
public function testAutowiring()
862876
{
863877
$container = new ContainerBuilder();

Tests/Dumper/PhpDumperTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,23 @@ public function testInlinedDefinitionReferencingServiceContainer()
275275
$dumper = new PhpDumper($container);
276276
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services13.php', $dumper->dump(), '->dump() dumps inline definitions which reference service_container');
277277
}
278+
279+
public function testInitializePropertiesBeforeMethodCalls()
280+
{
281+
require_once self::$fixturesPath.'/includes/classes.php';
282+
283+
$container = new ContainerBuilder();
284+
$container->register('foo', 'stdClass');
285+
$container->register('bar', 'MethodCallClass')
286+
->setProperty('simple', 'bar')
287+
->setProperty('complex', new Reference('foo'))
288+
->addMethodCall('callMe');
289+
$container->compile();
290+
291+
$dumper = new PhpDumper($container);
292+
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Properties_Before_Method_Calls')));
293+
294+
$container = new \Symfony_DI_PhpDumper_Test_Properties_Before_Method_Calls();
295+
$this->assertTrue($container->get('bar')->callPassed(), '->dump() initializes properties before method calls');
296+
}
278297
}

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

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

191-
$instance->setBar($this->get('bar'));
192-
$instance->initialize();
193191
$instance->foo = 'bar';
194192
$instance->moo = $a;
195193
$instance->qux = array($this->getParameter('foo') => 'foo is '.$this->getParameter('foo').'', 'foobar' => $this->getParameter('foo'));
194+
$instance->setBar($this->get('bar'));
195+
$instance->initialize();
196196
sc_configure($instance);
197197

198198
return $instance;
@@ -351,8 +351,8 @@ protected function getInlinedService()
351351
{
352352
$this->services['inlined'] = $instance = new \Bar();
353353

354-
$instance->setBaz($this->get('baz'));
355354
$instance->pub = 'pub';
355+
$instance->setBaz($this->get('baz'));
356356

357357
return $instance;
358358
}

Tests/Fixtures/php/services9_compiled.php

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

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

200-
$instance->setBar($this->get('bar'));
201-
$instance->initialize();
202200
$instance->foo = 'bar';
203201
$instance->moo = $a;
204202
$instance->qux = array('bar' => 'foo is bar', 'foobar' => 'bar');
203+
$instance->setBar($this->get('bar'));
204+
$instance->initialize();
205205
sc_configure($instance);
206206

207207
return $instance;
@@ -248,8 +248,8 @@ protected function getFooWithInlineService()
248248

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

251-
$a->setBaz($this->get('baz'));
252251
$a->pub = 'pub';
252+
$a->setBaz($this->get('baz'));
253253

254254
$instance->setBar($a);
255255

0 commit comments

Comments
 (0)