Skip to content

Commit 91f8003

Browse files
Merge branch '4.4' into 5.2
* 4.4: [HttpKernel] fix transient test [FrameworkBundle] Fix freshness checks with boolean parameters on routes [FrameworkBundle] fix registering "annotations.cache" on the "container.hot_path" Add some information about the username in CONTRIBUTORS
2 parents 8314733 + fd03c44 commit 91f8003

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

Resources/config/annotations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
service('cache.annotations'),
6262
]),
6363
])
64+
->tag('container.hot_path')
6465

6566
->alias('annotation_reader', 'annotations.reader')
6667
->alias(Reader::class, 'annotation_reader');

Routing/Router.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,16 @@ private function resolve($value)
180180

181181
$resolved = ($this->paramFetcher)($match[1]);
182182

183-
if (\is_bool($resolved)) {
184-
$resolved = (string) (int) $resolved;
185-
}
186-
187-
if (\is_string($resolved) || is_numeric($resolved)) {
183+
if (is_scalar($resolved)) {
188184
$this->collectedParameters[$match[1]] = $resolved;
189185

190-
return (string) $this->resolve($resolved);
186+
if (\is_string($resolved)) {
187+
$resolved = $this->resolve($resolved);
188+
}
189+
190+
if (is_scalar($resolved)) {
191+
return false === $resolved ? '0' : (string) $resolved;
192+
}
191193
}
192194

193195
throw new RuntimeException(sprintf('The container parameter "%s", used in the route configuration value "%s", must be a string or numeric, but it is of type "%s".', $match[1], $value, get_debug_type($resolved)));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foo:
2+
path: /foo
3+
condition: '%parameter.condition%'

Tests/Routing/RouterTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Psr\Container\ContainerInterface;
1616
use Symfony\Bundle\FrameworkBundle\Routing\Router;
17+
use Symfony\Component\Config\FileLocator;
1718
use Symfony\Component\Config\Loader\LoaderInterface;
19+
use Symfony\Component\Config\ResourceCheckerConfigCache;
20+
use Symfony\Component\Config\ResourceCheckerConfigCacheFactory;
1821
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
22+
use Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker;
1923
use Symfony\Component\DependencyInjection\Container;
2024
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
2125
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
26+
use Symfony\Component\Routing\Loader\YamlFileLoader;
2227
use Symfony\Component\Routing\Route;
2328
use Symfony\Component\Routing\RouteCollection;
2429

@@ -503,6 +508,51 @@ public function getNonStringValues()
503508
return [[null], [false], [true], [new \stdClass()], [['foo', 'bar']], [[[]]]];
504509
}
505510

511+
/**
512+
* @dataProvider getContainerParameterForRoute
513+
*/
514+
public function testCacheValiditiyWithContainerParameters($parameter)
515+
{
516+
$cacheDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('router_', true);
517+
518+
try {
519+
$container = new Container();
520+
$container->set('routing.loader', new YamlFileLoader(new FileLocator(__DIR__.'/Fixtures')));
521+
522+
$container->setParameter('parameter.condition', $parameter);
523+
524+
$router = new Router($container, 'with_condition.yaml', [
525+
'debug' => true,
526+
'cache_dir' => $cacheDir,
527+
]);
528+
529+
$resourceCheckers = [
530+
new ContainerParametersResourceChecker($container),
531+
];
532+
533+
$router->setConfigCacheFactory(new ResourceCheckerConfigCacheFactory($resourceCheckers));
534+
535+
$router->getMatcher(); // trigger cache build
536+
537+
$cache = new ResourceCheckerConfigCache($cacheDir.\DIRECTORY_SEPARATOR.'UrlMatcher.php', $resourceCheckers);
538+
539+
$this->assertTrue($cache->isFresh());
540+
} finally {
541+
if (is_dir($cacheDir)) {
542+
array_map('unlink', glob($cacheDir.\DIRECTORY_SEPARATOR.'*'));
543+
rmdir($cacheDir);
544+
}
545+
}
546+
}
547+
548+
public function getContainerParameterForRoute()
549+
{
550+
yield 'String' => ['"foo"'];
551+
yield 'Integer' => [0];
552+
yield 'Boolean true' => [true];
553+
yield 'Boolean false' => [false];
554+
}
555+
506556
private function getServiceContainer(RouteCollection $routes): Container
507557
{
508558
$loader = $this->createMock(LoaderInterface::class);

0 commit comments

Comments
 (0)