Skip to content

Commit 4d04c40

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 b928133 + e62b602 commit 4d04c40

File tree

21 files changed

+147
-50
lines changed

21 files changed

+147
-50
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: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* DelegatingLoader delegates route loading to other loaders using a loader resolver.
2222
*
2323
* This implementation resolves the _controller attribute from the short notation
24-
* to the fully-qualified form (from a:b:c to class:method).
24+
* to the fully-qualified form (from a:b:c to class::method).
2525
*
2626
* @author Fabien Potencier <fabien@symfony.com>
2727
*/
@@ -92,15 +92,17 @@ public function load($resource, $type = null)
9292
$this->loading = false;
9393

9494
foreach ($collection->all() as $route) {
95-
if ($controller = $route->getDefault('_controller')) {
96-
try {
97-
$controller = $this->parser->parse($controller);
98-
} catch (\InvalidArgumentException $e) {
99-
// unable to optimize unknown notation
100-
}
101-
102-
$route->setDefault('_controller', $controller);
95+
if (!$controller = $route->getDefault('_controller')) {
96+
continue;
10397
}
98+
99+
try {
100+
$controller = $this->parser->parse($controller);
101+
} catch (\InvalidArgumentException $e) {
102+
// unable to optimize unknown notation
103+
}
104+
105+
$route->setDefault('_controller', $controller);
104106
}
105107

106108
return $collection;

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

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

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

2628
public function testRolesHierarchy()
2729
{
@@ -259,6 +261,8 @@ public function testUserCheckerConfigWithNoCheckers()
259261

260262
protected function getContainer($file)
261263
{
264+
$file = $file.'.'.$this->getFileExtension();
265+
262266
if (isset(self::$containerCache[$file])) {
263267
return self::$containerCache[$file];
264268
}
@@ -268,7 +272,7 @@ protected function getContainer($file)
268272

269273
$bundle = new SecurityBundle();
270274
$bundle->build($container); // Attach all default factories
271-
$this->loadFromFile($container, $file);
275+
$this->getLoader($container)->load($file);
272276

273277
$container->getCompilerPassConfig()->setOptimizationPasses(array());
274278
$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/Bundle/WebProfilerBundle/Controller/RouterController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private function getTraces(RequestDataCollector $request, $method)
8787
$traceRequest = Request::create(
8888
$request->getPathInfo(),
8989
$request->getRequestServer()->get('REQUEST_METHOD'),
90-
$request->getRequestAttributes()->all(),
90+
array(),
9191
$request->getRequestCookies()->all(),
9292
array(),
9393
$request->getRequestServer()->all()

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

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

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

0 commit comments

Comments
 (0)