Skip to content

Commit 5461c1e

Browse files
Merge branch '3.1' into 3.2
* 3.1: [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 b1e8771 + 966d45f commit 5461c1e

File tree

20 files changed

+144
-48
lines changed

20 files changed

+144
-48
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ public function __construct(KernelInterface $kernel)
4646
*/
4747
public function parse($controller)
4848
{
49-
$originalController = $controller;
50-
if (3 !== count($parts = explode(':', $controller))) {
49+
$parts = explode(':', $controller);
50+
if (3 !== count($parts) || in_array('', $parts, true)) {
5151
throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "a:b:c" controller string.', $controller));
5252
}
5353

54+
$originalController = $controller;
5455
list($bundle, $controller, $action) = $parts;
5556
$controller = str_replace('/', '\\', $controller);
5657
$bundles = array();

src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* DelegatingLoader delegates route loading to other loaders using a loader resolver.
2121
*
2222
* This implementation resolves the _controller attribute from the short notation
23-
* to the fully-qualified form (from a:b:c to class:method).
23+
* to the fully-qualified form (from a:b:c to class::method).
2424
*
2525
* @author Fabien Potencier <fabien@symfony.com>
2626
*/
@@ -75,15 +75,17 @@ public function load($resource, $type = null)
7575
}
7676

7777
foreach ($collection->all() as $route) {
78-
if ($controller = $route->getDefault('_controller')) {
79-
try {
80-
$controller = $this->parser->parse($controller);
81-
} catch (\InvalidArgumentException $e) {
82-
// unable to optimize unknown notation
83-
}
78+
if (!$controller = $route->getDefault('_controller')) {
79+
continue;
80+
}
8481

85-
$route->setDefault('_controller', $controller);
82+
try {
83+
$controller = $this->parser->parse($controller);
84+
} catch (\InvalidArgumentException $e) {
85+
// unable to optimize unknown notation
8686
}
87+
88+
$route->setDefault('_controller', $controller);
8789
}
8890

8991
return $collection;

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
2020
{
2121
private static $containerCache = array();
2222

23-
abstract protected function loadFromFile(ContainerBuilder $container, $file);
23+
abstract protected function getLoader(ContainerBuilder $container);
24+
25+
abstract protected function getFileExtension();
2426

2527
public function testRolesHierarchy()
2628
{
@@ -334,6 +336,8 @@ public function testUserCheckerConfigWithNoCheckers()
334336

335337
protected function getContainer($file)
336338
{
339+
$file = $file.'.'.$this->getFileExtension();
340+
337341
if (isset(self::$containerCache[$file])) {
338342
return self::$containerCache[$file];
339343
}
@@ -343,7 +347,7 @@ protected function getContainer($file)
343347

344348
$bundle = new SecurityBundle();
345349
$bundle->build($container); // Attach all default factories
346-
$this->loadFromFile($container, $file);
350+
$this->getLoader($container)->load($file);
347351

348352
$container->getCompilerPassConfig()->setOptimizationPasses(array());
349353
$container->getCompilerPassConfig()->setRemovingPasses(array());

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpCompleteConfigurationTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
class PhpCompleteConfigurationTest extends CompleteConfigurationTest
1919
{
20-
protected function loadFromFile(ContainerBuilder $container, $file)
20+
protected function getLoader(ContainerBuilder $container)
2121
{
22-
$loadXml = new PhpFileLoader($container, new FileLocator(__DIR__.'/Fixtures/php'));
23-
$loadXml->load($file.'.php');
22+
return new PhpFileLoader($container, new FileLocator(__DIR__.'/Fixtures/php'));
23+
}
24+
25+
protected function getFileExtension()
26+
{
27+
return 'php';
2428
}
2529
}

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCompleteConfigurationTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
class XmlCompleteConfigurationTest extends CompleteConfigurationTest
1919
{
20-
protected function loadFromFile(ContainerBuilder $container, $file)
20+
protected function getLoader(ContainerBuilder $container)
2121
{
22-
$loadXml = new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml'));
23-
$loadXml->load($file.'.xml');
22+
return new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/xml'));
23+
}
24+
25+
protected function getFileExtension()
26+
{
27+
return 'xml';
2428
}
2529
}

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlCompleteConfigurationTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
class YamlCompleteConfigurationTest extends CompleteConfigurationTest
1919
{
20-
protected function loadFromFile(ContainerBuilder $container, $file)
20+
protected function getLoader(ContainerBuilder $container)
2121
{
22-
$loadXml = new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/yml'));
23-
$loadXml->load($file.'.yml');
22+
return new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/yml'));
23+
}
24+
25+
protected function getFileExtension()
26+
{
27+
return 'yml';
2428
}
2529
}

src/Symfony/Component/DependencyInjection/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]);

src/Symfony/Component/DependencyInjection/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
;

src/Symfony/Component/DependencyInjection/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();

src/Symfony/Component/DependencyInjection/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
}

0 commit comments

Comments
 (0)