From 5dbc7db04a50c65b9f980d18d3c4032ad9a56714 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 9 Feb 2021 08:45:33 +0100 Subject: [PATCH 1/4] Add some information about the username in CONTRIBUTORS --- CONTRIBUTORS.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 5b8efba407..b64aa797a5 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,8 +1,11 @@ CONTRIBUTORS ============ -Symfony is the result of the work of many people who made the code better -(see https://symfony.com/contributors for more information): +Symfony is the result of the work of many people who made the code better. + +The Symfony Connect username in parenthesis allows to get more information +about contributors (like https://connect.symfony.com/profile/fabpot). See +https://symfony.com/contributors for more information. - Fabien Potencier (fabpot) - Nicolas Grekas (nicolas-grekas) From e196c1ecb361a5e65d5c8a9bf25a3b13184aaee8 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 9 Feb 2021 09:55:59 +0100 Subject: [PATCH 2/4] [FrameworkBundle] fix registering "annotations.cache" on the "container.hot_path" --- .../Bundle/FrameworkBundle/Resources/config/annotations.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml index 0ce6bf6594..69947a35f8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml @@ -48,6 +48,7 @@ + From af6db0cfafe133383fa360c47a58c2ed207fac43 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Wed, 27 Jan 2021 22:59:52 +0100 Subject: [PATCH 3/4] [FrameworkBundle] Fix freshness checks with boolean parameters on routes --- .../Bundle/FrameworkBundle/Routing/Router.php | 14 +++--- .../Routing/Fixtures/with_condition.yaml | 3 ++ .../Tests/Routing/RouterTest.php | 50 +++++++++++++++++++ 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Fixtures/with_condition.yaml diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php index cf2eadbd51..89e8f77aee 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php @@ -178,14 +178,16 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI $resolved = ($this->paramFetcher)($match[1]); - if (\is_bool($resolved)) { - $resolved = (string) (int) $resolved; - } - - if (\is_string($resolved) || is_numeric($resolved)) { + if (is_scalar($resolved)) { $this->collectedParameters[$match[1]] = $resolved; - return (string) $this->resolve($resolved); + if (\is_string($resolved)) { + $resolved = $this->resolve($resolved); + } + + if (is_scalar($resolved)) { + return false === $resolved ? '0' : (string) $resolved; + } } 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, \gettype($resolved))); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Fixtures/with_condition.yaml b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Fixtures/with_condition.yaml new file mode 100644 index 0000000000..c97edc1a42 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/Fixtures/with_condition.yaml @@ -0,0 +1,3 @@ +foo: + path: /foo + condition: '%parameter.condition%' diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php index ca66001ed9..9a96fb0f74 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php @@ -14,11 +14,16 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Routing; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use Symfony\Bundle\FrameworkBundle\Routing\Router; +use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\Config\ResourceCheckerConfigCache; +use Symfony\Component\Config\ResourceCheckerConfigCacheFactory; use Symfony\Component\DependencyInjection\Config\ContainerParametersResource; +use Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; +use Symfony\Component\Routing\Loader\YamlFileLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -503,6 +508,51 @@ class RouterTest extends TestCase return [[null], [false], [true], [new \stdClass()], [['foo', 'bar']], [[[]]]]; } + /** + * @dataProvider getContainerParameterForRoute + */ + public function testCacheValiditiyWithContainerParameters($parameter) + { + $cacheDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('router_', true); + + try { + $container = new Container(); + $container->set('routing.loader', new YamlFileLoader(new FileLocator(__DIR__.'/Fixtures'))); + + $container->setParameter('parameter.condition', $parameter); + + $router = new Router($container, 'with_condition.yaml', [ + 'debug' => true, + 'cache_dir' => $cacheDir, + ]); + + $resourceCheckers = [ + new ContainerParametersResourceChecker($container), + ]; + + $router->setConfigCacheFactory(new ResourceCheckerConfigCacheFactory($resourceCheckers)); + + $router->getMatcher(); // trigger cache build + + $cache = new ResourceCheckerConfigCache($cacheDir.\DIRECTORY_SEPARATOR.'UrlMatcher.php', $resourceCheckers); + + $this->assertTrue($cache->isFresh()); + } finally { + if (is_dir($cacheDir)) { + array_map('unlink', glob($cacheDir.\DIRECTORY_SEPARATOR.'*')); + rmdir($cacheDir); + } + } + } + + public function getContainerParameterForRoute() + { + yield 'String' => ['"foo"']; + yield 'Integer' => [0]; + yield 'Boolean true' => [true]; + yield 'Boolean false' => [false]; + } + private function getServiceContainer(RouteCollection $routes): Container { $loader = $this->createMock(LoaderInterface::class); From db66fb58389d07b99d3e5f576592b2fd8f702d37 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 10 Feb 2021 18:16:49 +0100 Subject: [PATCH 4/4] [HttpKernel] fix transient test --- src/Symfony/Component/HttpKernel/Tests/KernelTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 9e48e4274e..63fb4973f6 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -35,8 +36,10 @@ class KernelTest extends TestCase { protected function tearDown(): void { - $fs = new Filesystem(); - $fs->remove(__DIR__.'/Fixtures/var'); + try { + (new Filesystem())->remove(__DIR__.'/Fixtures/var'); + } catch (IOException $e) { + } } public function testConstructor() @@ -586,7 +589,7 @@ EOF public function testKernelReset() { - (new Filesystem())->remove(__DIR__.'/Fixtures/var/cache'); + $this->tearDown(); $kernel = new CustomProjectDirKernel(); $kernel->boot();