Skip to content

Commit 886924c

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 3a03edf + 4b4eae9 commit 886924c

File tree

7 files changed

+45
-22
lines changed

7 files changed

+45
-22
lines changed

Command/ConfigDebugCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ protected function configure()
4747
<info>php %command.full_name% framework</info>
4848
<info>php %command.full_name% FrameworkBundle</info>
4949
50+
For dumping a specific option, add its path as second argument:
51+
52+
<info>php %command.full_name% framework serializer.enabled</info>
53+
5054
EOF
5155
)
5256
;

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();

DependencyInjection/Compiler/CachePoolClearerPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ final class CachePoolClearerPass implements CompilerPassInterface
2525
*/
2626
public function process(ContainerBuilder $container)
2727
{
28+
$container->getParameterBag()->remove('cache.prefix.seed');
29+
2830
foreach ($container->findTaggedServiceIds('cache.pool') as $id => $attributes) {
2931
foreach (array_reverse($attributes) as $attr) {
3032
if (isset($attr['clearer'])) {

DependencyInjection/Compiler/CachePoolPass.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ class CachePoolPass implements CompilerPassInterface
2929
*/
3030
public function process(ContainerBuilder $container)
3131
{
32-
$namespaceSuffix = '';
33-
34-
foreach (array('kernel.name', 'kernel.environment', 'kernel.debug', 'cache.prefix.seed') as $key) {
35-
if ($container->hasParameter($key)) {
36-
$namespaceSuffix .= '.'.$container->getParameter($key);
37-
}
32+
if ($container->hasParameter('cache.prefix.seed')) {
33+
$seed = '.'.$container->getParameterBag()->resolveValue($container->getParameter('cache.prefix.seed'));
34+
} else {
35+
$seed = '_'.$container->getParameter('kernel.root_dir');
3836
}
39-
$container->getParameterBag()->remove('cache.prefix.seed');
37+
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment').'.'.$container->getParameter('kernel.debug');
4038

4139
$aliases = $container->getAliases();
4240
$attributes = array(
@@ -56,7 +54,7 @@ public function process(ContainerBuilder $container)
5654
}
5755
}
5856
if (!isset($tags[0]['namespace'])) {
59-
$tags[0]['namespace'] = $this->getNamespace($namespaceSuffix, $id);
57+
$tags[0]['namespace'] = $this->getNamespace($seed, $id);
6058
}
6159
if (isset($tags[0]['clearer'])) {
6260
$clearer = strtolower($tags[0]['clearer']);
@@ -88,9 +86,9 @@ public function process(ContainerBuilder $container)
8886
}
8987
}
9088

91-
private function getNamespace($namespaceSuffix, $id)
89+
private function getNamespace($seed, $id)
9290
{
93-
return substr(str_replace('/', '-', base64_encode(hash('sha256', $id.$namespaceSuffix, true))), 0, 10);
91+
return substr(str_replace('/', '-', base64_encode(hash('sha256', $id.$seed, true))), 0, 10);
9492
}
9593

9694
/**

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 <[email protected]>
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;

Tests/DependencyInjection/Compiler/CachePoolClearerPassTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class CachePoolClearerPassTest extends \PHPUnit_Framework_TestCase
2424
public function testPoolRefsAreWeak()
2525
{
2626
$container = new ContainerBuilder();
27+
$container->setParameter('kernel.debug', false);
28+
$container->setParameter('kernel.name', 'app');
29+
$container->setParameter('kernel.environment', 'prod');
30+
$container->setParameter('kernel.root_dir', 'foo');
2731

2832
$publicPool = new Definition();
2933
$publicPool->addArgument('namespace');

Tests/DependencyInjection/Compiler/CachePoolPassTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ protected function setUp()
2929
public function testNamespaceArgumentIsReplaced()
3030
{
3131
$container = new ContainerBuilder();
32+
$container->setParameter('kernel.debug', false);
33+
$container->setParameter('kernel.name', 'app');
34+
$container->setParameter('kernel.environment', 'prod');
35+
$container->setParameter('kernel.root_dir', 'foo');
3236
$adapter = new Definition();
3337
$adapter->setAbstract(true);
3438
$adapter->addTag('cache.pool');
@@ -41,12 +45,16 @@ public function testNamespaceArgumentIsReplaced()
4145

4246
$this->cachePoolPass->process($container);
4347

44-
$this->assertSame('kRFqMp5odS', $cachePool->getArgument(0));
48+
$this->assertSame('C42Pcl9VBJ', $cachePool->getArgument(0));
4549
}
4650

4751
public function testArgsAreReplaced()
4852
{
4953
$container = new ContainerBuilder();
54+
$container->setParameter('kernel.debug', false);
55+
$container->setParameter('kernel.name', 'app');
56+
$container->setParameter('kernel.environment', 'prod');
57+
$container->setParameter('cache.prefix.seed', 'foo');
5058
$cachePool = new Definition();
5159
$cachePool->addTag('cache.pool', array(
5260
'provider' => 'foobar',
@@ -61,7 +69,7 @@ public function testArgsAreReplaced()
6169

6270
$this->assertInstanceOf(Reference::class, $cachePool->getArgument(0));
6371
$this->assertSame('foobar', (string) $cachePool->getArgument(0));
64-
$this->assertSame('kRFqMp5odS', $cachePool->getArgument(1));
72+
$this->assertSame('KO3xHaFEZU', $cachePool->getArgument(1));
6573
$this->assertSame(3, $cachePool->getArgument(2));
6674
}
6775

@@ -72,6 +80,10 @@ public function testArgsAreReplaced()
7280
public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
7381
{
7482
$container = new ContainerBuilder();
83+
$container->setParameter('kernel.debug', false);
84+
$container->setParameter('kernel.name', 'app');
85+
$container->setParameter('kernel.environment', 'prod');
86+
$container->setParameter('kernel.root_dir', 'foo');
7587
$adapter = new Definition();
7688
$adapter->setAbstract(true);
7789
$adapter->addTag('cache.pool');

0 commit comments

Comments
 (0)