Skip to content

Commit 966d45f

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 3918fff + 4d04c40 commit 966d45f

File tree

21 files changed

+146
-49
lines changed

21 files changed

+146
-49
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
{
@@ -257,6 +259,8 @@ public function testUserCheckerConfigWithNoCheckers()
257259

258260
protected function getContainer($file)
259261
{
262+
$file = $file.'.'.$this->getFileExtension();
263+
260264
if (isset(self::$containerCache[$file])) {
261265
return self::$containerCache[$file];
262266
}
@@ -266,7 +270,7 @@ protected function getContainer($file)
266270

267271
$bundle = new SecurityBundle();
268272
$bundle->build($container); // Attach all default factories
269-
$this->loadFromFile($container, $file);
273+
$this->getLoader($container)->load($file);
270274

271275
$container->getCompilerPassConfig()->setOptimizationPasses(array());
272276
$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
@@ -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]);

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

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

0 commit comments

Comments
 (0)