From db0846a67e6299e25ee30efbd639ccf53ac0da8b Mon Sep 17 00:00:00 2001 From: Tofandel Date: Fri, 1 Jul 2022 11:39:57 +0200 Subject: [PATCH 01/33] fix: fosRoute.json dir created at root --- Resources/webpack/FosRouting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/webpack/FosRouting.js b/Resources/webpack/FosRouting.js index d8a1996..e812d03 100644 --- a/Resources/webpack/FosRouting.js +++ b/Resources/webpack/FosRouting.js @@ -66,7 +66,7 @@ class FosRouting { const content = await readFile(this.options.target); await rmFile(this.options.target); if (!prevContent || content.compare(prevContent) !== 0) { - await makeDir(path.basename(this.finalTarget), {recursive: true}) + await makeDir(path.dirname(this.finalTarget), {recursive: true}); await writeFile(this.finalTarget, content); prevContent = content; if (comp.modifiedFiles && !comp.modifiedFiles.has(this.finalTarget)) { From fb188bfe352ccd7ecff06c08eca05fed47f30de4 Mon Sep 17 00:00:00 2001 From: Tobias Feijten Date: Fri, 1 Jul 2022 13:50:22 +0200 Subject: [PATCH 02/33] Prepare 3.2.1 release --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92537f6..0063ba1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v3.2.1 - 2022-07-01 +- fix for webpack plugin: fosRoute.json dir created at root ([#443](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/443)) + ## v3.2.0 - 2022-06-30 - [BC break] Use Symfony Flex default path. Will break if you're still using the `web` directory and not defining the path ([#433](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/433)) - Add webpack plugin to automatically load the routes with no user interactions ([#429](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/429)) From 171df43e934cfa1619db37ed2be2ca9b1608b10c Mon Sep 17 00:00:00 2001 From: David Maicher Date: Tue, 6 Jun 2023 16:14:00 +0200 Subject: [PATCH 03/33] fix Symfony 6.3 deprecation: add getSupportedTypes() --- .github/workflows/code_checks.yaml | 1 + Serializer/Denormalizer/RouteCollectionDenormalizer.php | 5 +++++ Serializer/Normalizer/RouteCollectionNormalizer.php | 5 +++++ Serializer/Normalizer/RoutesResponseNormalizer.php | 5 +++++ 4 files changed, 16 insertions(+) diff --git a/.github/workflows/code_checks.yaml b/.github/workflows/code_checks.yaml index b1efaba..d1a0595 100644 --- a/.github/workflows/code_checks.yaml +++ b/.github/workflows/code_checks.yaml @@ -63,6 +63,7 @@ jobs: - name: Require Symfony version if: matrix.symfony != '*' run: | + composer global config --no-plugins allow-plugins.symfony/flex true composer global require --no-interaction --no-progress symfony/flex:^1.11 composer config extra.symfony.require ${{ matrix.symfony }} diff --git a/Serializer/Denormalizer/RouteCollectionDenormalizer.php b/Serializer/Denormalizer/RouteCollectionDenormalizer.php index 03eb3d7..741c0c0 100644 --- a/Serializer/Denormalizer/RouteCollectionDenormalizer.php +++ b/Serializer/Denormalizer/RouteCollectionDenormalizer.php @@ -65,4 +65,9 @@ public function supportsDenormalization(mixed $data, string $type, string $forma return true; } + + public function getSupportedTypes(?string $format): array + { + return ['*' => false]; + } } diff --git a/Serializer/Normalizer/RouteCollectionNormalizer.php b/Serializer/Normalizer/RouteCollectionNormalizer.php index a5e7b62..657ccf2 100644 --- a/Serializer/Normalizer/RouteCollectionNormalizer.php +++ b/Serializer/Normalizer/RouteCollectionNormalizer.php @@ -51,4 +51,9 @@ public function supportsNormalization(mixed $data, string $format = null, array { return $data instanceof RouteCollection; } + + public function getSupportedTypes(?string $format): array + { + return [RouteCollection::class => true]; + } } diff --git a/Serializer/Normalizer/RoutesResponseNormalizer.php b/Serializer/Normalizer/RoutesResponseNormalizer.php index 0ec5617..46c6a63 100644 --- a/Serializer/Normalizer/RoutesResponseNormalizer.php +++ b/Serializer/Normalizer/RoutesResponseNormalizer.php @@ -44,4 +44,9 @@ public function supportsNormalization(mixed $data, string $format = null, array { return $data instanceof RoutesResponse; } + + public function getSupportedTypes(?string $format): array + { + return [RoutesResponse::class => true]; + } } From 9493cbd025a4557022e4646561f546058058199a Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 11 May 2023 13:17:21 +0200 Subject: [PATCH 04/33] Prefer static call and precise exception --- Controller/Controller.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Controller/Controller.php b/Controller/Controller.php index 22f8305..b320347 100644 --- a/Controller/Controller.php +++ b/Controller/Controller.php @@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag; -use Symfony\Component\HttpKernel\Exception\HttpException; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; /** * Controller class. @@ -82,9 +82,8 @@ public function indexAction(Request $request, $_format): Response $content = $this->serializer->serialize($routesResponse, 'json'); if (null !== $callback = $request->query->get('callback')) { - $validator = new \JsonpCallbackValidator(); - if (!$validator->validate($callback)) { - throw new HttpException(400, 'Invalid JSONP callback value'); + if (!\JsonpCallbackValidator::validate($callback)) { + throw new BadRequestHttpException('Invalid JSONP callback value'); } $content = '/**/'.$callback.'('.$content.');'; From 6478092ab986cfc9cac6e97befcd5e4d0cd00ec5 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 13 Apr 2023 23:56:09 +0200 Subject: [PATCH 05/33] Add gitattributes file --- .gitattributes | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..45c4b62 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +.* export-ignore +Tests export-ignore +phpunit export-ignore +phpunit.xml.dist export-ignore From eab4899a21cb87d3c7967d29c0c3044708d08f53 Mon Sep 17 00:00:00 2001 From: Tobias Feijten Date: Tue, 4 Jul 2023 19:17:16 +0200 Subject: [PATCH 06/33] Add .gitattributes for Resources/js --- Resources/js/.gitattributes | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Resources/js/.gitattributes diff --git a/Resources/js/.gitattributes b/Resources/js/.gitattributes new file mode 100644 index 0000000..4ae5633 --- /dev/null +++ b/Resources/js/.gitattributes @@ -0,0 +1,3 @@ +router.test.js export-ignore +router_test.html export-ignore +run_jsunit.js export-ignore From 52e2fb54f24351cb14622e174e46d41769dd195b Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Thu, 22 Dec 2022 16:11:06 +0100 Subject: [PATCH 07/33] chore: php8 language level migration --- Command/DumpCommand.php | 4 +--- DependencyInjection/FOSJsRoutingExtension.php | 2 +- Extractor/ExposedRoutesExtractor.php | 2 +- Tests/Command/DumpCommandTest.php | 9 ++++--- .../Command/RouterDebugExposedCommandTest.php | 6 +++-- Tests/Controller/ControllerTest.php | 13 +++++----- .../FOSJsRoutingExtensionTest.php | 4 ++-- .../Extractor/ExposedRoutesExtractorTest.php | 24 ++++++++----------- .../RouteCollectionNormalizerTest.php | 7 +++--- .../RoutesResponseNormalizerTest.php | 5 ++-- 10 files changed, 39 insertions(+), 37 deletions(-) diff --git a/Command/DumpCommand.php b/Command/DumpCommand.php index 2935d69..5f3f2a9 100644 --- a/Command/DumpCommand.php +++ b/Command/DumpCommand.php @@ -132,9 +132,7 @@ private function doDump(InputInterface $input, OutputInterface $output): void $output->writeln('[file+] '.$targetPath); - $baseUrl = null !== $this->requestContextBaseUrl ? - $this->requestContextBaseUrl : - $this->extractor->getBaseUrl() + $baseUrl = $this->requestContextBaseUrl ?? $this->extractor->getBaseUrl() ; if ($input->getOption('pretty-print')) { diff --git a/DependencyInjection/FOSJsRoutingExtension.php b/DependencyInjection/FOSJsRoutingExtension.php index 8034835..aeab79c 100644 --- a/DependencyInjection/FOSJsRoutingExtension.php +++ b/DependencyInjection/FOSJsRoutingExtension.php @@ -51,7 +51,7 @@ public function load(array $configs, ContainerBuilder $container): void $container->setParameter( 'fos_js_routing.request_context_base_url', - $config['request_context_base_url'] ? $config['request_context_base_url'] : null + $config['request_context_base_url'] ?: null ); if (isset($config['cache_control'])) { diff --git a/Extractor/ExposedRoutesExtractor.php b/Extractor/ExposedRoutesExtractor.php index 50be07c..a2d7d6f 100644 --- a/Extractor/ExposedRoutesExtractor.php +++ b/Extractor/ExposedRoutesExtractor.php @@ -189,7 +189,7 @@ protected function getDomainByRouteMatches($matches, $name): int|string|null $matches = array_flip(array_intersect_key($matches, array_flip($this->availableDomains))); - return isset($matches[$name]) ? $matches[$name] : null; + return $matches[$name] ?? null; } protected function extractDomainPatterns($routesToExpose): array diff --git a/Tests/Command/DumpCommandTest.php b/Tests/Command/DumpCommandTest.php index 7f9df10..810ab66 100644 --- a/Tests/Command/DumpCommandTest.php +++ b/Tests/Command/DumpCommandTest.php @@ -16,6 +16,9 @@ use FOS\JsRoutingBundle\Command\DumpCommand; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\Serializer\SerializerInterface; +use Symfony\Component\Routing\Router; +use FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor; class DumpCommandTest extends TestCase { @@ -25,15 +28,15 @@ class DumpCommandTest extends TestCase public function setUp(): void { - $this->extractor = $this->getMockBuilder('FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor') + $this->extractor = $this->getMockBuilder(ExposedRoutesExtractor::class) ->disableOriginalConstructor() ->getMock(); - $this->router = $this->getMockBuilder('Symfony\Component\Routing\Router') + $this->router = $this->getMockBuilder(Router::class) ->disableOriginalConstructor() ->getMock(); - $this->serializer = $this->getMockBuilder('Symfony\Component\Serializer\SerializerInterface') + $this->serializer = $this->getMockBuilder(SerializerInterface::class) ->disableOriginalConstructor() ->getMock(); } diff --git a/Tests/Command/RouterDebugExposedCommandTest.php b/Tests/Command/RouterDebugExposedCommandTest.php index 0e604de..a410de0 100644 --- a/Tests/Command/RouterDebugExposedCommandTest.php +++ b/Tests/Command/RouterDebugExposedCommandTest.php @@ -18,6 +18,8 @@ use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\Router; +use FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor; class RouterDebugExposedCommandTest extends TestCase { @@ -26,11 +28,11 @@ class RouterDebugExposedCommandTest extends TestCase public function setUp(): void { - $this->extractor = $this->getMockBuilder('FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor') + $this->extractor = $this->getMockBuilder(ExposedRoutesExtractor::class) ->disableOriginalConstructor() ->getMock(); - $this->router = $this->getMockBuilder('Symfony\Component\Routing\Router') + $this->router = $this->getMockBuilder(Router::class) ->disableOriginalConstructor() ->getMock(); } diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php index 41608d2..fd94a5a 100644 --- a/Tests/Controller/ControllerTest.php +++ b/Tests/Controller/ControllerTest.php @@ -24,10 +24,11 @@ use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Serializer; +use FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractorInterface; class ControllerTest extends TestCase { - private $cachePath; + private string $cachePath; public function setUp(): void { @@ -119,7 +120,7 @@ public function testGenerateWithCallback($callback): void ); } - public static function dataProviderForTestGenerateWithCallback() + public static function dataProviderForTestGenerateWithCallback(): array { return [ ['fos.Router.data'], @@ -223,7 +224,7 @@ private function getExtractor(RouteCollection $exposedRoutes = null, $baseUrl = $exposedRoutes = new RouteCollection(); } - $extractor = $this->getMockBuilder('FOS\\JsRoutingBundle\\Extractor\\ExposedRoutesExtractorInterface')->getMock(); + $extractor = $this->getMockBuilder(ExposedRoutesExtractorInterface::class)->getMock(); $extractor ->expects($this->any()) ->method('getRoutes') @@ -258,9 +259,9 @@ private function getExtractor(RouteCollection $exposedRoutes = null, $baseUrl = return $extractor; } - private function getSerializer() + private function getSerializer(): Serializer { - if (!class_exists('Symfony\\Component\\Serializer\\Serializer')) { + if (!class_exists(Serializer::class)) { $this->markTestSkipped('The Serializer component is not available.'); } @@ -273,7 +274,7 @@ private function getSerializer() ]); } - private function getRequest($uri, $method = 'GET', $parameters = [], $cookies = [], $files = [], $server = [], $content = null) + private function getRequest($uri, $method = 'GET', $parameters = [], $cookies = [], $files = [], $server = [], $content = null): Request { return Request::create($uri, $method, $parameters, $cookies, $files, $server, $content); } diff --git a/Tests/DependencyInjection/FOSJsRoutingExtensionTest.php b/Tests/DependencyInjection/FOSJsRoutingExtensionTest.php index 94ee92a..b22cf1d 100644 --- a/Tests/DependencyInjection/FOSJsRoutingExtensionTest.php +++ b/Tests/DependencyInjection/FOSJsRoutingExtensionTest.php @@ -21,7 +21,7 @@ class FOSJsRoutingExtensionTest extends TestCase { public function setUp(): void { - if (!class_exists('Symfony\Component\DependencyInjection\ContainerBuilder')) { + if (!class_exists(ContainerBuilder::class)) { $this->markTestSkipped('The DependencyInjection component is not available.'); } } @@ -56,7 +56,7 @@ public function testLoadSetupsSerializerIfNotGiven(): void $this->assertEquals('{"foo":"bar"}', $serializer->serialize(['foo' => 'bar'], 'json')); } - private function load(array $configs) + private function load(array $configs): ContainerBuilder { $container = new ContainerBuilder(); diff --git a/Tests/Extractor/ExposedRoutesExtractorTest.php b/Tests/Extractor/ExposedRoutesExtractorTest.php index 3e3ea2a..e631b95 100644 --- a/Tests/Extractor/ExposedRoutesExtractorTest.php +++ b/Tests/Extractor/ExposedRoutesExtractorTest.php @@ -18,6 +18,7 @@ use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\Router; /** * ExposedRoutesExtractorTest class. @@ -26,11 +27,11 @@ */ class ExposedRoutesExtractorTest extends TestCase { - private $cacheDir; + private string $cacheDir; public function setUp(): void { - if (!class_exists('Symfony\\Component\\Routing\\Route')) { + if (!class_exists(Route::class)) { $this->markTestSkipped('The Routing component is not available.'); } @@ -85,7 +86,7 @@ public function testGetRoutesWithPatterns(): void public function testGetCachePath(): void { - $router = $this->getMockBuilder('Symfony\\Component\\Routing\\Router') + $router = $this->getMockBuilder(Router::class) ->disableOriginalConstructor() ->getMock(); @@ -100,7 +101,7 @@ public function testGetHostOverHttp($host, $httpPort, $expected): void { $requestContext = new RequestContext('/app_dev.php', 'GET', $host, 'http', $httpPort); - $router = $this->getMockBuilder('Symfony\\Component\\Routing\\Router') + $router = $this->getMockBuilder(Router::class) ->disableOriginalConstructor() ->getMock(); $router->expects($this->atLeastOnce()) @@ -115,7 +116,7 @@ public function testGetHostOverHttp($host, $httpPort, $expected): void /** * @return array */ - public function provideTestGetHostOverHttp() + public function provideTestGetHostOverHttp(): array { return [ 'HTTP Standard' => ['127.0.0.1', 80, '127.0.0.1'], @@ -130,7 +131,7 @@ public function testGetHostOverHttps($host, $httpsPort, $expected): void { $requestContext = new RequestContext('/app_dev.php', 'GET', $host, 'https', 80, $httpsPort); - $router = $this->getMockBuilder('Symfony\\Component\\Routing\\Router') + $router = $this->getMockBuilder(Router::class) ->disableOriginalConstructor() ->getMock(); $router->expects($this->atLeastOnce()) @@ -167,10 +168,7 @@ public function testExposeFalse(): void } } - /** - * @return array - */ - public function provideTestGetHostOverHttps() + public function provideTestGetHostOverHttps(): array { return [ 'HTTPS Standard' => ['127.0.0.1', 443, '127.0.0.1'], @@ -180,12 +178,10 @@ public function provideTestGetHostOverHttps() /** * Get a mock object which represents a Router. - * - * @return \Symfony\Component\Routing\Router */ - private function getRouter(RouteCollection $routes) + private function getRouter(RouteCollection $routes): \Symfony\Component\Routing\Router { - $router = $this->getMockBuilder('Symfony\\Component\\Routing\\Router') + $router = $this->getMockBuilder(Router::class) ->disableOriginalConstructor() ->getMock(); $router diff --git a/Tests/Serializer/Normalizer/RouteCollectionNormalizerTest.php b/Tests/Serializer/Normalizer/RouteCollectionNormalizerTest.php index 5400bf7..6884a6b 100644 --- a/Tests/Serializer/Normalizer/RouteCollectionNormalizerTest.php +++ b/Tests/Serializer/Normalizer/RouteCollectionNormalizerTest.php @@ -17,6 +17,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\RouteCompiler; /** * Class RouteCollectionNormalizerTest. @@ -47,7 +48,7 @@ public function testNormalize(): void 'defaults' => [], 'requirements' => [], 'options' => [ - 'compiler_class' => 'Symfony\Component\Routing\RouteCompiler', + 'compiler_class' => RouteCompiler::class, ], 'schemes' => [], 'methods' => [], @@ -59,7 +60,7 @@ public function testNormalize(): void 'defaults' => [], 'requirements' => [], 'options' => [ - 'compiler_class' => 'Symfony\Component\Routing\RouteCompiler', + 'compiler_class' => RouteCompiler::class, ], 'schemes' => [], 'methods' => [], @@ -71,7 +72,7 @@ public function testNormalize(): void 'defaults' => [], 'requirements' => [], 'options' => [ - 'compiler_class' => 'Symfony\Component\Routing\RouteCompiler', + 'compiler_class' => RouteCompiler::class, ], 'schemes' => [], 'methods' => [], diff --git a/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php b/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php index 0daa830..bd71b08 100644 --- a/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php +++ b/Tests/Serializer/Normalizer/RoutesResponseNormalizerTest.php @@ -16,13 +16,14 @@ use FOS\JsRoutingBundle\Serializer\Normalizer\RouteCollectionNormalizer; use FOS\JsRoutingBundle\Serializer\Normalizer\RoutesResponseNormalizer; use PHPUnit\Framework\TestCase; +use FOS\JsRoutingBundle\Response\RoutesResponse; class RoutesResponseNormalizerTest extends TestCase { public function testSupportsNormalization(): void { $normalizer = new RoutesResponseNormalizer(new RouteCollectionNormalizer()); - $response = $this->getMockBuilder('FOS\JsRoutingBundle\Response\RoutesResponse') + $response = $this->getMockBuilder(RoutesResponse::class) ->disableOriginalConstructor() ->getMock(); @@ -33,7 +34,7 @@ public function testSupportsNormalization(): void public function testNormalize(): void { $normalizer = new RoutesResponseNormalizer(new RouteCollectionNormalizer()); - $response = $this->getMockBuilder('FOS\JsRoutingBundle\Response\RoutesResponse') + $response = $this->getMockBuilder(RoutesResponse::class) ->disableOriginalConstructor() ->getMock(); From bcee50e047bb4f4f5ccb1ac743f5886028dbc53e Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Thu, 22 Dec 2022 15:48:36 +0100 Subject: [PATCH 08/33] tests: migrate phpunit config-file --- phpunit.xml.dist | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2d684b2..05cd3a3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,19 +1,21 @@ - - - - ./Tests - - - - - - ./ - - ./Resources/ - ./Tests/ - ./vendor/ - - - + + + + ./ + + + ./Resources/ + ./Tests/ + ./vendor/ + + + + + ./Tests + + From 551e0e3a71a7b3346d441f66ede3f6ca47a0631d Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 4 Jul 2023 19:26:45 +0200 Subject: [PATCH 09/33] tests: php 8.2, bump github action version (#449) * tests: adjust tests for php 8.2, use latest action versions * tests: adjust tests for php 8.2, use latest action versions * tests: adjust tests for php 8.2, use latest action versions * tests: adjust tests for php 8.2, use latest action versions * tests: adjust tests for php 8.2, use latest action versions * tests: adjust tests for php 8.2, use latest action versions --------- Co-authored-by: Christopher Georg Co-authored-by: Tobias Feijten --- .github/workflows/code_checks.yaml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/code_checks.yaml b/.github/workflows/code_checks.yaml index d1a0595..7b203a9 100644 --- a/.github/workflows/code_checks.yaml +++ b/.github/workflows/code_checks.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install JS dependencies run: | @@ -24,7 +24,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.0', '8.1'] + php: ['8.0', '8.1', '8.2'] dependencies: [highest] symfony: ['*'] include: @@ -34,11 +34,11 @@ jobs: symfony: '*' # Minimum supported dependencies with the latest supported PHP version - - php: '8.1' + - php: '8.2' dependencies: lowest symfony: '*' - - php: '8.1' + - php: '8.2' dependencies: highest symfony: '*' @@ -51,9 +51,13 @@ jobs: - php: '8.0' dependencies: highest symfony: '6.0.*' + + - php: '8.1' + dependencies: highest + symfony: '6.2.*' steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -64,16 +68,16 @@ jobs: if: matrix.symfony != '*' run: | composer global config --no-plugins allow-plugins.symfony/flex true - composer global require --no-interaction --no-progress symfony/flex:^1.11 + composer global require --no-interaction --no-progress symfony/flex:^2.2 composer config extra.symfony.require ${{ matrix.symfony }} - name: Update project dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: dependency-versions: ${{ matrix.dependencies }} - name: Cache PHPUnit - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: vendor/bin/.phpunit key: ${{ runner.os }}-phpunit-${{ matrix.php }} From c9f8d5ef98aa0aa289e23582f81a7d9e3bb29df5 Mon Sep 17 00:00:00 2001 From: Tofandel Date: Thu, 21 Jul 2022 20:34:59 +0200 Subject: [PATCH 10/33] fix: add support for windows --- Resources/webpack/FosRouting.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Resources/webpack/FosRouting.js b/Resources/webpack/FosRouting.js index e812d03..f224c79 100644 --- a/Resources/webpack/FosRouting.js +++ b/Resources/webpack/FosRouting.js @@ -18,6 +18,7 @@ class FosRouting { locale: '', prettyPrint: false, domain: [], + php: 'php', }; constructor(options = {}) { @@ -62,7 +63,7 @@ class FosRouting { } return pass; }, []); - await execFile('bin/console', ['fos:js-routing:dump', ...args]); + await execFile(this.options.php, ['bin/console', 'fos:js-routing:dump', ...args]); const content = await readFile(this.options.target); await rmFile(this.options.target); if (!prevContent || content.compare(prevContent) !== 0) { @@ -86,7 +87,7 @@ class FosRouting { new InjectPlugin(() => { return 'import Routing from "fos-router";' + - 'import routes from "' + this.finalTarget + '";' + + 'import routes from '+JSON.stringify(this.finalTarget)+';' + 'Routing.setRoutingData(routes);'; }).apply(compiler); } From 0398dbde5419bbd4ea8520cf81e2c289a0b53ef8 Mon Sep 17 00:00:00 2001 From: Tofandel Date: Tue, 26 Jul 2022 16:03:13 +0200 Subject: [PATCH 11/33] fix: soft fail on error --- Resources/package.json | 2 +- Resources/webpack/FosRouting.js | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Resources/package.json b/Resources/package.json index 3a71964..0d2e198 100755 --- a/Resources/package.json +++ b/Resources/package.json @@ -1,6 +1,6 @@ { "name": "fos-router", - "version": "2.4.3", + "version": "2.4.6", "description": "A pretty nice way to use the routes generated by the FOSJsRoutingBundle in your JavaScript.", "keywords": [ "router", diff --git a/Resources/webpack/FosRouting.js b/Resources/webpack/FosRouting.js index f224c79..e99ff1a 100644 --- a/Resources/webpack/FosRouting.js +++ b/Resources/webpack/FosRouting.js @@ -64,15 +64,20 @@ class FosRouting { return pass; }, []); await execFile(this.options.php, ['bin/console', 'fos:js-routing:dump', ...args]); - const content = await readFile(this.options.target); - await rmFile(this.options.target); - if (!prevContent || content.compare(prevContent) !== 0) { - await makeDir(path.dirname(this.finalTarget), {recursive: true}); - await writeFile(this.finalTarget, content); - prevContent = content; - if (comp.modifiedFiles && !comp.modifiedFiles.has(this.finalTarget)) { - comp.modifiedFiles.add(this.finalTarget); + try { + const content = await readFile(this.options.target); + await rmFile(this.options.target); + if (!prevContent || content.compare(prevContent) !== 0) { + await makeDir(path.dirname(this.finalTarget), {recursive: true}); + await writeFile(this.finalTarget, content); + prevContent = content; + if (comp.modifiedFiles && !comp.modifiedFiles.has(this.finalTarget)) { + comp.modifiedFiles.add(this.finalTarget); + } } + } catch (e) { + const logger = compiler.getInfrastructureLogger('FosRouting'); + logger.error(e.toString()); } callback(); }; From fd1ad1c891cfccbe7e283e2e564d90b998550a4c Mon Sep 17 00:00:00 2001 From: Alexandre Segura Date: Sat, 20 Jun 2020 09:02:28 +0200 Subject: [PATCH 12/33] Make sure cache control headers are set. --- Util/CacheControlConfig.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Util/CacheControlConfig.php b/Util/CacheControlConfig.php index 14893f5..9b863b6 100644 --- a/Util/CacheControlConfig.php +++ b/Util/CacheControlConfig.php @@ -14,6 +14,7 @@ namespace FOS\JsRoutingBundle\Util; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener; class CacheControlConfig { @@ -27,6 +28,8 @@ public function apply(Response $response): void return; } + $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true'); + $this->parameters['public'] ? $response->setPublic() : $response->setPrivate(); if (is_int($this->parameters['maxage'])) { From 4daa2620d1d1afbbaec620e158fffe10f9fb5d4c Mon Sep 17 00:00:00 2001 From: Tobias Feijten Date: Tue, 4 Jul 2023 19:41:13 +0200 Subject: [PATCH 13/33] Prepare 3.3.0 release --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0063ba1..f38cc36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## v3.3.0 - 2023-07-04 +- add support for Windows when using the webpack plugin ([#444](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/444)) +- Add PHP 8.2 tests ([#449](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/449)) +- Phpunit config file migration ([#450](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/450))) +- Deprecation fixes (PHP 8 ([#451](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/451)) and Symfony 6.3 ([#460](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/460))) +- JSON Callback validator static call instead of new object ([#458](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/458)) +- Optimize package size by excluding tests ([#457](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/457)) + ## v3.2.1 - 2022-07-01 - fix for webpack plugin: fosRoute.json dir created at root ([#443](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/443)) From f527f75b2885a4b31930d297eed8bc3b300e9f56 Mon Sep 17 00:00:00 2001 From: Bob van de Vijver Date: Wed, 19 Jul 2023 22:59:21 +0200 Subject: [PATCH 14/33] Update console note --- Resources/doc/commands.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Resources/doc/commands.rst b/Resources/doc/commands.rst index d26d8f9..d0c8c40 100644 --- a/Resources/doc/commands.rst +++ b/Resources/doc/commands.rst @@ -38,7 +38,11 @@ Or inside assetic, do .. caution:: You should follow the Symfony documentation about generating URLs - in the console: `Configuring The Request Context Globally`_. + in the console: `Forcing HTTPS on Generated URLs`_, as the console is unaware + of the host/port combination you use during a request. You can also set the + `HTTP_HOST` environment variable to hold your hostname including the port you + use (i.e. `localhost:8443`). You can also use the `setHost` and `setPort` + methods on the `Router` object to set it at runtime. .. tip:: @@ -58,4 +62,4 @@ This command lists all exposed routes: # Symfony 3 $ php bin/console fos:js-routing:debug [name] -.. _`Configuring The Request Context Globally`: http://symfony.com/doc/current/cookbook/console/sending_emails.html#configuring-the-request-context-globally +.. _`Forcing HTTPS on Generated URLs`: https://symfony.com/doc/current/routing.html#forcing-https-on-generated-urls From c00642dbc421ea3da4c5e52e8743fb7f9309b930 Mon Sep 17 00:00:00 2001 From: Olek Kaim <135211410+olekans@users.noreply.github.com> Date: Thu, 30 Nov 2023 08:13:50 +0100 Subject: [PATCH 15/33] Allow symfony 7.0 (#471) * Allow symfony 7.0 * retrigger checks * update all user Symfony components allow version 7 * add SF7 to code checks configuration --- .github/workflows/code_checks.yaml | 4 ++++ composer.json | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/code_checks.yaml b/.github/workflows/code_checks.yaml index 7b203a9..2c82bf4 100644 --- a/.github/workflows/code_checks.yaml +++ b/.github/workflows/code_checks.yaml @@ -55,6 +55,10 @@ jobs: - php: '8.1' dependencies: highest symfony: '6.2.*' + + - php: '8.2' + dependencies: highest + symfony: '7.0.*' steps: - name: Checkout uses: actions/checkout@v3 diff --git a/composer.json b/composer.json index 1ff67e3..b417f4d 100644 --- a/composer.json +++ b/composer.json @@ -17,14 +17,14 @@ ], "require": { "php": "^8.0", - "symfony/framework-bundle": "^5.4|^6.0", - "symfony/serializer": "^5.4|^6.0.1", - "symfony/console": "^5.4|^6.0", + "symfony/framework-bundle": "^5.4|^6.0|^7.0", + "symfony/serializer": "^5.4|^6.0.1|^7.0", + "symfony/console": "^5.4|^6.0|^7.0", "willdurand/jsonp-callback-validator": "~1.1|^2.0" }, "require-dev": { - "symfony/expression-language": "^5.4|^6.0", - "symfony/phpunit-bridge": "^5.4|^6.0" + "symfony/expression-language": "^5.4|^6.0|^7.0", + "symfony/phpunit-bridge": "^5.4|^6.0|^7.0" }, "autoload": { "psr-4": { "FOS\\JsRoutingBundle\\": "" }, From 901768bcb7c691ab07b9981d8d02887c0af21699 Mon Sep 17 00:00:00 2001 From: Tac Tacelosky Date: Thu, 30 Nov 2023 06:54:53 -0500 Subject: [PATCH 16/33] remove $ so gitclip works --- Resources/doc/installation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/doc/installation.rst b/Resources/doc/installation.rst index c829ef3..3b85c2e 100644 --- a/Resources/doc/installation.rst +++ b/Resources/doc/installation.rst @@ -52,7 +52,7 @@ Execute the following command to publish the assets required by the bundle: .. code-block:: bash - $ php bin/console assets:install --symlink public + php bin/console assets:install --symlink public .. _`installation chapter`: https://getcomposer.org/doc/00-intro.md @@ -60,4 +60,4 @@ Step 5: If you are using webpack, install the npm package locally ----------------------------------------------------------------- .. code-block:: bash - $ yarn add -D ./vendor/friendsofsymfony/jsrouting-bundle/Resources/ + yarn add -D ./vendor/friendsofsymfony/jsrouting-bundle/Resources/ From 23b8ec9fd4bebbd42ad505d76da02846ed950bcf Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Fri, 11 Aug 2023 14:27:10 +0100 Subject: [PATCH 17/33] fix: remove webpack-inject-plugin dependency As mentioned in https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/issues/454 --- Resources/package.json | 5 +---- Resources/webpack/FosRouting.js | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Resources/package.json b/Resources/package.json index 0d2e198..828361e 100755 --- a/Resources/package.json +++ b/Resources/package.json @@ -34,8 +34,8 @@ "google-closure-library": "^20220104.0.0", "gulp": "^4.0.2", "gulp-rename": "^2.0.0", - "gulp-uglify": "^3.0.2", "gulp-typescript": "^6.0.0-alpha.1", + "gulp-uglify": "^3.0.2", "gulp-wrap": "^0.15.0", "jasmine": "^4.0.2", "tsd": "^0.19.1", @@ -47,8 +47,5 @@ "test": "npm run build && npm run test:types && phantomjs js/run_jsunit.js js/router_test.html", "test:types": "tsd", "prepublish": "npm run build" - }, - "dependencies": { - "webpack-inject-plugin": "^1.5.5" } } diff --git a/Resources/webpack/FosRouting.js b/Resources/webpack/FosRouting.js index e99ff1a..1c1a2b8 100644 --- a/Resources/webpack/FosRouting.js +++ b/Resources/webpack/FosRouting.js @@ -4,8 +4,7 @@ const fs = require('fs'); const path = require('path'); const util = require('util'); - -const InjectPlugin = require('webpack-inject-plugin').default; +const webpack = require("webpack"); const execFile = util.promisify(require('child_process').execFile); const readFile = util.promisify(fs.readFile); @@ -90,11 +89,17 @@ class FosRouting { } }); - new InjectPlugin(() => { - return 'import Routing from "fos-router";' + - 'import routes from '+JSON.stringify(this.finalTarget)+';' + - 'Routing.setRoutingData(routes);'; - }).apply(compiler); + new webpack.BannerPlugin({ + entryOnly: true, + include: this.finalTarget ? this.finalTarget + ".js" : /\.js$/, + raw: true, + banner: + 'import Routing from "fos-router";' + + "import routes from " + + JSON.stringify(this.finalTarget) + + ";" + + "Routing.setRoutingData(routes);", + }).apply(compiler); } } From 80835feb9caa57b23cb3d1ef405440098d57dca0 Mon Sep 17 00:00:00 2001 From: Tobias Feijten Date: Tue, 12 Dec 2023 14:19:40 +0100 Subject: [PATCH 18/33] Prepare 3.4.0 release --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f38cc36..5d576dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v3.4.0 - 2023-12-12 +- Allow Symfony 7.0 ([#471](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/471)) +- fix: remove webpack-inject-plugin dependency ([#464](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/464)) +- Docs only: remove $ so gitclip works ([#472](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/472)) +- Docs only: Update console note ([#463](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/463)) + ## v3.3.0 - 2023-07-04 - add support for Windows when using the webpack plugin ([#444](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/444)) - Add PHP 8.2 tests ([#449](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/449)) From c61c92d28afabf0ff888b93700878aff44692dfe Mon Sep 17 00:00:00 2001 From: Tobias Feijten Date: Fri, 15 Dec 2023 23:52:41 +0100 Subject: [PATCH 19/33] Revert "fix: remove webpack-inject-plugin dependency" This reverts commit 23b8ec9fd4bebbd42ad505d76da02846ed950bcf. --- Resources/package.json | 5 ++++- Resources/webpack/FosRouting.js | 19 +++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Resources/package.json b/Resources/package.json index 828361e..0d2e198 100755 --- a/Resources/package.json +++ b/Resources/package.json @@ -34,8 +34,8 @@ "google-closure-library": "^20220104.0.0", "gulp": "^4.0.2", "gulp-rename": "^2.0.0", - "gulp-typescript": "^6.0.0-alpha.1", "gulp-uglify": "^3.0.2", + "gulp-typescript": "^6.0.0-alpha.1", "gulp-wrap": "^0.15.0", "jasmine": "^4.0.2", "tsd": "^0.19.1", @@ -47,5 +47,8 @@ "test": "npm run build && npm run test:types && phantomjs js/run_jsunit.js js/router_test.html", "test:types": "tsd", "prepublish": "npm run build" + }, + "dependencies": { + "webpack-inject-plugin": "^1.5.5" } } diff --git a/Resources/webpack/FosRouting.js b/Resources/webpack/FosRouting.js index 1c1a2b8..e99ff1a 100644 --- a/Resources/webpack/FosRouting.js +++ b/Resources/webpack/FosRouting.js @@ -4,7 +4,8 @@ const fs = require('fs'); const path = require('path'); const util = require('util'); -const webpack = require("webpack"); + +const InjectPlugin = require('webpack-inject-plugin').default; const execFile = util.promisify(require('child_process').execFile); const readFile = util.promisify(fs.readFile); @@ -89,17 +90,11 @@ class FosRouting { } }); - new webpack.BannerPlugin({ - entryOnly: true, - include: this.finalTarget ? this.finalTarget + ".js" : /\.js$/, - raw: true, - banner: - 'import Routing from "fos-router";' + - "import routes from " + - JSON.stringify(this.finalTarget) + - ";" + - "Routing.setRoutingData(routes);", - }).apply(compiler); + new InjectPlugin(() => { + return 'import Routing from "fos-router";' + + 'import routes from '+JSON.stringify(this.finalTarget)+';' + + 'Routing.setRoutingData(routes);'; + }).apply(compiler); } } From 3e1aa859b29b847b9888a0931851b8821bc8e5f3 Mon Sep 17 00:00:00 2001 From: Tobias Feijten Date: Fri, 15 Dec 2023 23:56:13 +0100 Subject: [PATCH 20/33] Switch to a somewhat newer webpack-inject-plugin fork to fix dependency vulnerability --- Resources/package.json | 4 ++-- Resources/webpack/FosRouting.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Resources/package.json b/Resources/package.json index 0d2e198..5d3ab5c 100755 --- a/Resources/package.json +++ b/Resources/package.json @@ -1,6 +1,6 @@ { "name": "fos-router", - "version": "2.4.6", + "version": "2.5.0", "description": "A pretty nice way to use the routes generated by the FOSJsRoutingBundle in your JavaScript.", "keywords": [ "router", @@ -49,6 +49,6 @@ "prepublish": "npm run build" }, "dependencies": { - "webpack-inject-plugin": "^1.5.5" + "@bpnetguy/webpack-inject-plugin": "^2.0.4" } } diff --git a/Resources/webpack/FosRouting.js b/Resources/webpack/FosRouting.js index e99ff1a..1fc02ed 100644 --- a/Resources/webpack/FosRouting.js +++ b/Resources/webpack/FosRouting.js @@ -5,7 +5,7 @@ const fs = require('fs'); const path = require('path'); const util = require('util'); -const InjectPlugin = require('webpack-inject-plugin').default; +const InjectPlugin = require('@bpnetguy/webpack-inject-plugin').default; const execFile = util.promisify(require('child_process').execFile); const readFile = util.promisify(fs.readFile); From 2b88ce924741614d2716a9fec5f06a2c27972ab2 Mon Sep 17 00:00:00 2001 From: Tobias Feijten Date: Sat, 16 Dec 2023 00:00:48 +0100 Subject: [PATCH 21/33] Prepare 3.4.1 release --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d576dd..b0b0649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v3.4.1 - 2023-12-15 +- fix: do not use BannerPlugin but newer webpack-inject-plugin instead to fix vulnerability + ## v3.4.0 - 2023-12-12 - Allow Symfony 7.0 ([#471](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/471)) - fix: remove webpack-inject-plugin dependency ([#464](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/464)) From 8afcc2bb4a6d4d247dd6fdb674133db4bf9f655e Mon Sep 17 00:00:00 2001 From: Nils Minten Date: Tue, 23 Jan 2024 14:22:18 +0100 Subject: [PATCH 22/33] Fix TypeScript error when `verbatimModuleSyntax` is enabled When `verbatimModuleSyntax` is enabled in TypeScript when building your application two Type errors would pop up. ```console TS1484: 'RoutesMap' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. ``` ```console TS1484: 'Route' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. ``` --- Resources/ts/router.test-d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Resources/ts/router.test-d.ts b/Resources/ts/router.test-d.ts index e9aadf7..862f183 100644 --- a/Resources/ts/router.test-d.ts +++ b/Resources/ts/router.test-d.ts @@ -1,6 +1,6 @@ import { expectType } from 'tsd'; -import { RoutesMap } from '../js/router'; -import { Route, Router, Routing } from './router'; +import type { RoutesMap } from '../js/router'; +import { Route, Router, type Routing } from './router'; import routes from './routes.json'; expectType(Router.getInstance()); From 6650f94cc1d0648c1bc8ad4b789bb6e129b957eb Mon Sep 17 00:00:00 2001 From: Nils Minten Date: Tue, 23 Jan 2024 14:53:01 +0100 Subject: [PATCH 23/33] Actually change the correct import --- Resources/ts/router.test-d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/ts/router.test-d.ts b/Resources/ts/router.test-d.ts index 862f183..4b65185 100644 --- a/Resources/ts/router.test-d.ts +++ b/Resources/ts/router.test-d.ts @@ -1,6 +1,6 @@ import { expectType } from 'tsd'; import type { RoutesMap } from '../js/router'; -import { Route, Router, type Routing } from './router'; +import { type Route, Router, Routing } from './router'; import routes from './routes.json'; expectType(Router.getInstance()); From 92c6d04f042278a98446430bfc10fcc471f04ac6 Mon Sep 17 00:00:00 2001 From: Pierre Kerfurus Date: Tue, 12 Dec 2023 09:53:04 +0100 Subject: [PATCH 24/33] Define RoutesResponse as a Service --- Command/DumpCommand.php | 33 +++++++------- Controller/Controller.php | 31 +++++++------ Resources/config/controllers.xml | 1 + Resources/config/services.xml | 4 +- Response/RoutesResponse.php | 75 +++++++++++++++++++++++++++----- 5 files changed, 101 insertions(+), 43 deletions(-) diff --git a/Command/DumpCommand.php b/Command/DumpCommand.php index 5f3f2a9..5218851 100644 --- a/Command/DumpCommand.php +++ b/Command/DumpCommand.php @@ -30,8 +30,13 @@ #[AsCommand('fos:js-routing:dump', 'Dumps exposed routes to the filesystem')] class DumpCommand extends Command { - public function __construct(private ExposedRoutesExtractorInterface $extractor, private SerializerInterface $serializer, private string $projectDir, private ?string $requestContextBaseUrl = null) - { + public function __construct( + private RoutesResponse $routesResponse, + private ExposedRoutesExtractorInterface $extractor, + private SerializerInterface $serializer, + private string $projectDir, + private ?string $requestContextBaseUrl = null, + ) { parent::__construct(); } @@ -141,20 +146,16 @@ private function doDump(InputInterface $input, OutputInterface $output): void $params = []; } - $content = $serializer->serialize( - new RoutesResponse( - $baseUrl, - $extractor->getRoutes(), - $extractor->getPrefix($input->getOption('locale')), - $extractor->getHost(), - $extractor->getPort(), - $extractor->getScheme(), - $input->getOption('locale'), - $domain - ), - 'json', - $params - ); + $this->routesResponse->setBaseUrl($baseUrl); + $this->routesResponse->setRoutes($extractor->getRoutes()); + $this->routesResponse->setPrefix($extractor->getPrefix($input->getOption('locale'))); + $this->routesResponse->setHost($extractor->getHost()); + $this->routesResponse->setPort($extractor->getPort()); + $this->routesResponse->setScheme($extractor->getScheme()); + $this->routesResponse->setLocale($input->getOption('locale')); + $this->routesResponse->setDomains($domain); + + $content = $serializer->serialize($this->routesResponse, 'json', $params); if ('js' == $input->getOption('format')) { $content = sprintf('%s(%s);', $input->getOption('callback'), $content); diff --git a/Controller/Controller.php b/Controller/Controller.php index b320347..8480eb5 100644 --- a/Controller/Controller.php +++ b/Controller/Controller.php @@ -38,8 +38,13 @@ class Controller * @param ExposedRoutesExtractorInterface $exposedRoutesExtractor the extractor service * @param bool $debug */ - public function __construct(private mixed $serializer, private ExposedRoutesExtractorInterface $exposedRoutesExtractor, array $cacheControl = [], private bool $debug = false) - { + public function __construct( + private RoutesResponse $routesResponse, + private mixed $serializer, + private ExposedRoutesExtractorInterface $exposedRoutesExtractor, + array $cacheControl = [], + private bool $debug = false, + ) { $this->cacheControlConfig = new CacheControlConfig($cacheControl); } @@ -68,18 +73,16 @@ public function indexAction(Request $request, $_format): Response ); } - $routesResponse = new RoutesResponse( - $this->exposedRoutesExtractor->getBaseUrl(), - $exposedRoutes, - $this->exposedRoutesExtractor->getPrefix($request->getLocale()), - $this->exposedRoutesExtractor->getHost(), - $this->exposedRoutesExtractor->getPort(), - $this->exposedRoutesExtractor->getScheme(), - $request->getLocale(), - $request->query->has('domain') ? explode(',', $request->query->get('domain')) : [] - ); - - $content = $this->serializer->serialize($routesResponse, 'json'); + $this->routesResponse->setBaseUrl($this->exposedRoutesExtractor->getBaseUrl()); + $this->routesResponse->setRoutes($exposedRoutes); + $this->routesResponse->setPrefix($this->exposedRoutesExtractor->getPrefix($request->getLocale())); + $this->routesResponse->setHost($this->exposedRoutesExtractor->getHost()); + $this->routesResponse->setPort($this->exposedRoutesExtractor->getPort()); + $this->routesResponse->setScheme($this->exposedRoutesExtractor->getScheme()); + $this->routesResponse->setLocale($request->getLocale()); + $this->routesResponse->setDomains($request->query->has('domain') ? explode(',', $request->query->get('domain')) : []); + + $content = $this->serializer->serialize($this->routesResponse, 'json'); if (null !== $callback = $request->query->get('callback')) { if (!\JsonpCallbackValidator::validate($callback)) { diff --git a/Resources/config/controllers.xml b/Resources/config/controllers.xml index ecc7e54..5413804 100644 --- a/Resources/config/controllers.xml +++ b/Resources/config/controllers.xml @@ -7,6 +7,7 @@ + %fos_js_routing.cache_control% diff --git a/Resources/config/services.xml b/Resources/config/services.xml index efdd671..cd71b95 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -5,6 +5,7 @@ FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractor + FOS\JsRoutingBundle\Response\RoutesResponse @@ -14,8 +15,9 @@ %kernel.cache_dir% %kernel.bundles% - + + %kernel.project_dir% diff --git a/Response/RoutesResponse.php b/Response/RoutesResponse.php index e4b9aa9..9d18aac 100644 --- a/Response/RoutesResponse.php +++ b/Response/RoutesResponse.php @@ -17,24 +17,25 @@ class RoutesResponse { - private $routes; - - public function __construct(private string $baseUrl, RouteCollection $routes = null, - private ?string $prefix = null, private ?string $host = null, - private ?string $port = null, private ?string $scheme = null, - private ?string $locale = null, private array $domains = []) - { + protected $routes; + + public function __construct( + protected ?string $baseUrl = null, + RouteCollection $routes = null, + protected ?string $prefix = null, + protected ?string $host = null, + protected ?string $port = null, + protected ?string $scheme = null, + protected ?string $locale = null, + protected array $domains = [], + ) { $this->routes = $routes ?: new RouteCollection(); } - public function getBaseUrl(): string - { - return $this->baseUrl; - } - public function getRoutes(): array { $exposedRoutes = []; + foreach ($this->routes->all() as $name => $route) { if (!$route->hasOption('expose')) { $domain = 'default'; @@ -74,28 +75,78 @@ public function getRoutes(): array return $exposedRoutes; } + public function setRoutes(RouteCollection $routes): void + { + $this->routes = $routes; + } + + public function getBaseUrl(): string + { + return $this->baseUrl; + } + + public function setBaseUrl(string $baseUrl): void + { + $this->baseUrl = $baseUrl; + } + public function getPrefix(): ?string { return $this->prefix; } + public function setPrefix(?string $prefix): void + { + $this->prefix = $prefix; + } + public function getHost(): ?string { return $this->host; } + public function setHost(?string $host): void + { + $this->host = $host; + } + public function getPort(): ?string { return $this->port; } + public function setPort(?string $port): void + { + $this->port = $port; + } + public function getScheme(): ?string { return $this->scheme; } + public function setScheme(?string $scheme): void + { + $this->scheme = $scheme; + } + public function getLocale(): ?string { return $this->locale; } + + public function setLocale(?string $locale): void + { + $this->locale = $locale; + } + + public function getDomains(): array + { + return $this->domains; + } + + public function setDomains(array $domains): void + { + $this->domains = $domains; + } } From 8aaf3aeb32a42252d53d0f201cdc9df18eeee2cf Mon Sep 17 00:00:00 2001 From: Pierre Kerfurus Date: Thu, 14 Dec 2023 15:31:23 +0100 Subject: [PATCH 25/33] Update PHPUnit tests --- Tests/Command/DumpCommandTest.php | 42 ++++++++++++++++++++++++---- Tests/Controller/ControllerTest.php | 43 +++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 14 deletions(-) diff --git a/Tests/Command/DumpCommandTest.php b/Tests/Command/DumpCommandTest.php index 810ab66..583ecda 100644 --- a/Tests/Command/DumpCommandTest.php +++ b/Tests/Command/DumpCommandTest.php @@ -14,6 +14,7 @@ namespace FOS\JsRoutingBundle\Tests\Command; use FOS\JsRoutingBundle\Command\DumpCommand; +use FOS\JsRoutingBundle\Response\RoutesResponse; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Serializer\SerializerInterface; @@ -22,12 +23,17 @@ class DumpCommandTest extends TestCase { + protected RoutesResponse $routesResponse; protected $extractor; protected $router; private $serializer; public function setUp(): void { + $this->routesResponse = $this->getMockBuilder(RoutesResponse::class) + ->disableOriginalConstructor() + ->getMock(); + $this->extractor = $this->getMockBuilder(ExposedRoutesExtractor::class) ->disableOriginalConstructor() ->getMock(); @@ -47,7 +53,12 @@ public function testExecute(): void ->method('serialize') ->will($this->returnValue('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[]},"blog":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]]}},"prefix":"","host":"","scheme":""}')); - $command = new DumpCommand($this->extractor, $this->serializer, '/root/dir'); + $command = new DumpCommand( + $this->routesResponse, + $this->extractor, + $this->serializer, + '/root/dir', + ); $tester = new CommandTester($command); $tester->execute(['--target' => '/tmp/dump-command-test']); @@ -64,7 +75,12 @@ public function testExecuteCallbackOption(): void ->method('serialize') ->will($this->returnValue('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[]},"blog":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]]}},"prefix":"","host":"","scheme":""}')); - $command = new DumpCommand($this->extractor, $this->serializer, '/root/dir'); + $command = new DumpCommand( + $this->routesResponse, + $this->extractor, + $this->serializer, + '/root/dir', + ); $tester = new CommandTester($command); $tester->execute([ @@ -86,7 +102,12 @@ public function testExecuteFormatOption(): void ->method('serialize') ->will($this->returnValue($json)); - $command = new DumpCommand($this->extractor, $this->serializer, '/root/dir'); + $command = new DumpCommand( + $this->routesResponse, + $this->extractor, + $this->serializer, + '/root/dir', + ); $tester = new CommandTester($command); $tester->execute([ @@ -104,7 +125,13 @@ public function testExecuteUnableToCreateDirectory(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Unable to create directory /root/dir/public/js'); - $command = new DumpCommand($this->extractor, $this->serializer, '/root/dir'); + + $command = new DumpCommand( + $this->routesResponse, + $this->extractor, + $this->serializer, + '/root/dir', + ); $tester = new CommandTester($command); $tester->execute([]); @@ -118,7 +145,12 @@ public function testExecuteUnableToWriteFile(): void ->method('serialize') ->will($this->returnValue('{"base_url":"","routes":{"literal":{"tokens":[["text","\/homepage"]],"defaults":[],"requirements":[],"hosttokens":[]},"blog":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog-post"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]]}},"prefix":"","host":"","scheme":""}')); - $command = new DumpCommand($this->extractor, $this->serializer, '/root/dir'); + $command = new DumpCommand( + $this->routesResponse, + $this->extractor, + $this->serializer, + '/root/dir', + ); $tester = new CommandTester($command); $tester->execute(['--target' => '/tmp']); diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php index fd94a5a..9ef10fe 100644 --- a/Tests/Controller/ControllerTest.php +++ b/Tests/Controller/ControllerTest.php @@ -14,6 +14,7 @@ namespace FOS\JsRoutingBundle\Tests\Controller; use FOS\JsRoutingBundle\Controller\Controller; +use FOS\JsRoutingBundle\Response\RoutesResponse; use FOS\JsRoutingBundle\Serializer\Denormalizer\RouteCollectionDenormalizer; use FOS\JsRoutingBundle\Serializer\Normalizer\RouteCollectionNormalizer; use FOS\JsRoutingBundle\Serializer\Normalizer\RoutesResponseNormalizer; @@ -28,10 +29,12 @@ class ControllerTest extends TestCase { + protected RoutesResponse $routesResponse; private string $cachePath; public function setUp(): void { + $this->routesResponse = new RoutesResponse(); $this->cachePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'fosJsRouting'.DIRECTORY_SEPARATOR.'data.json'; } @@ -47,8 +50,9 @@ public function testIndexAction(): void $routes->add('blog', new Route('/blog-post/{slug}', [], [], [], 'localhost')); $controller = new Controller( + $this->routesResponse, $this->getSerializer(), - $this->getExtractor($routes) + $this->getExtractor($routes), ); $response = $controller->indexAction($this->getRequest('/'), 'json'); @@ -63,8 +67,9 @@ public function testIndexWithExplicitTokenAction(): void $routes->add('blog', new Route('/blog-post/{!slug}', [], [], [], 'localhost')); $controller = new Controller( + $this->routesResponse, $this->getSerializer(), - $this->getExtractor($routes) + $this->getExtractor($routes), ); $response = $controller->indexAction($this->getRequest('/'), 'json'); @@ -79,8 +84,9 @@ public function testIndexActionWithLocalizedRoutes(): void $routes->add('blog', new Route('/blog-post/{slug}/{_locale}', [], [], [], 'localhost')); $controller = new Controller( + $this->routesResponse, $this->getSerializer(), - $this->getExtractor($routes) + $this->getExtractor($routes), ); $response = $controller->indexAction($this->getRequest('/'), 'json'); @@ -94,8 +100,9 @@ public function testConfigCache(): void $routes->add('literal', new Route('/homepage')); $controller = new Controller( + $this->routesResponse, $this->getSerializer(), - $this->getExtractor($routes) + $this->getExtractor($routes), ); $response = $controller->indexAction($this->getRequest('/'), 'json'); @@ -111,7 +118,11 @@ public function testConfigCache(): void */ public function testGenerateWithCallback($callback): void { - $controller = new Controller($this->getSerializer(), $this->getExtractor()); + $controller = new Controller( + $this->routesResponse, + $this->getSerializer(), + $this->getExtractor(), + ); $response = $controller->indexAction($this->getRequest('/', 'GET', ['callback' => $callback]), 'json'); $this->assertEquals( @@ -131,13 +142,21 @@ public static function dataProviderForTestGenerateWithCallback(): array public function testGenerateWithInvalidCallback(): void { $this->expectException(HttpException::class); - $controller = new Controller($this->getSerializer(), $this->getExtractor()); + $controller = new Controller( + $this->routesResponse, + $this->getSerializer(), + $this->getExtractor(), + ); $controller->indexAction($this->getRequest('/', 'GET', ['callback' => '(function xss(x) {evil()})']), 'json'); } public function testIndexActionWithoutRoutes(): void { - $controller = new Controller($this->getSerializer(), $this->getExtractor()); + $controller = new Controller( + $this->routesResponse, + $this->getSerializer(), + $this->getExtractor(), + ); $response = $controller->indexAction($this->getRequest('/'), 'json'); $this->assertEquals('{"base_url":"","routes":[],"prefix":"","host":"","port":null,"scheme":"","locale":"en"}', $response->getContent()); @@ -161,7 +180,12 @@ public function testCacheControl(): void 'vary' => [], ]; - $controller = new Controller($this->getSerializer(), $this->getExtractor(), $cacheControlConfig); + $controller = new Controller( + $this->routesResponse, + $this->getSerializer(), + $this->getExtractor(), + $cacheControlConfig, + ); $response = $controller->indexAction($this->getRequest('/'), 'json'); $this->assertTrue($response->headers->hasCacheControlDirective('public')); @@ -189,8 +213,9 @@ public function testExposeDomain(): void ['expose' => 'blog'], 'localhost')); $controller = new Controller( + $this->routesResponse, $this->getSerializer(), - $this->getExtractor($routes) + $this->getExtractor($routes), ); $response = $controller->indexAction($this->getRequest('/'), 'json'); From 77de7e4130153f35e7eaa546aa68e94d124b521e Mon Sep 17 00:00:00 2001 From: Christian Fahnemann Date: Thu, 2 Nov 2023 04:48:38 +0100 Subject: [PATCH 26/33] Ignore session in stateless requests Changed to same code as in toolbarAction from symfony 6.3 WebProfilerBundle/Controller/ProfilerController.php --- Controller/Controller.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Controller/Controller.php b/Controller/Controller.php index 8480eb5..f67a1e1 100644 --- a/Controller/Controller.php +++ b/Controller/Controller.php @@ -50,9 +50,9 @@ public function __construct( public function indexAction(Request $request, $_format): Response { - $session = $request->hasSession() ? $request->getSession() : null; - - if ($request->hasPreviousSession() && $session->getFlashBag() instanceof AutoExpireFlashBag) { + if (!$request->attributes->getBoolean('_stateless') && $request->hasSession() + && ($session = $request->getSession())->isStarted() && $session->getFlashBag() instanceof AutoExpireFlashBag + ) { // keep current flashes for one more request if using AutoExpireFlashBag $session->getFlashBag()->setAll($session->getFlashBag()->peekAll()); } From 770cb4259c55b84e2055cf101a43c7db822a8393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Ro=CC=88=C3=9Fner?= Date: Tue, 18 Jul 2023 13:45:18 +0200 Subject: [PATCH 27/33] add skipCompile option to webpack plugin. This way you can compile the finalTarget e.g. in a separate process and don't need php during compile time. --- Resources/webpack/FosRouting.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Resources/webpack/FosRouting.js b/Resources/webpack/FosRouting.js index 1fc02ed..1bfd1f2 100644 --- a/Resources/webpack/FosRouting.js +++ b/Resources/webpack/FosRouting.js @@ -19,6 +19,7 @@ class FosRouting { prettyPrint: false, domain: [], php: 'php', + skipCompile: false }; constructor(options = {}) { @@ -29,6 +30,7 @@ class FosRouting { if (this.options.target === this.finalTarget) { this.options.target += '.tmp'; } + this.compile = false === this.options.skipCompile; } // Values don't need to be escaped because node already does that @@ -81,14 +83,17 @@ class FosRouting { } callback(); }; - compiler.hooks.beforeRun.tapAsync('RouteDump', compile); - compiler.hooks.watchRun.tapAsync('RouteDump_Watch', (comp, callback) => { - if (!comp.modifiedFiles || !comp.modifiedFiles.has(this.finalTarget)) { - compile(comp, callback); - } else { - callback(); - } - }); + + if (this.compile) { + compiler.hooks.beforeRun.tapAsync('RouteDump', compile); + compiler.hooks.watchRun.tapAsync('RouteDump_Watch', (comp, callback) => { + if (!comp.modifiedFiles || !comp.modifiedFiles.has(this.finalTarget)) { + compile(comp, callback); + } else { + callback(); + } + }); + } new InjectPlugin(() => { return 'import Routing from "fos-router";' + From 167ca0ec47de11ac69ba66bdc35e1a1e43c3b39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Ro=CC=88=C3=9Fner?= Date: Tue, 18 Jul 2023 14:04:29 +0200 Subject: [PATCH 28/33] move skipCompile from options to constructir argument, so it won't be passed to the php command as argument. --- Resources/webpack/FosRouting.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Resources/webpack/FosRouting.js b/Resources/webpack/FosRouting.js index 1bfd1f2..4dccfee 100644 --- a/Resources/webpack/FosRouting.js +++ b/Resources/webpack/FosRouting.js @@ -18,11 +18,10 @@ class FosRouting { locale: '', prettyPrint: false, domain: [], - php: 'php', - skipCompile: false + php: 'php' }; - constructor(options = {}) { + constructor(options = {}, registerCompileHooks = true) { this.options = Object.assign({target: 'var/cache/fosRoutes.json'}, this.default, options, {format: 'json'}); this.finalTarget = path.resolve(process.cwd(), this.options.target); this.options.target = path.resolve(process.cwd(), this.options.target.replace(/\.json$/, '.tmp.json')); @@ -30,7 +29,7 @@ class FosRouting { if (this.options.target === this.finalTarget) { this.options.target += '.tmp'; } - this.compile = false === this.options.skipCompile; + this.registerCompileHooks = registerCompileHooks; } // Values don't need to be escaped because node already does that @@ -84,7 +83,7 @@ class FosRouting { callback(); }; - if (this.compile) { + if (this.registerCompileHooks === true) { compiler.hooks.beforeRun.tapAsync('RouteDump', compile); compiler.hooks.watchRun.tapAsync('RouteDump_Watch', (comp, callback) => { if (!comp.modifiedFiles || !comp.modifiedFiles.has(this.finalTarget)) { From 42422c87834937fba4b928059e6c09e80d8a8d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Ro=CC=88=C3=9Fner?= Date: Tue, 18 Jul 2023 15:00:03 +0200 Subject: [PATCH 29/33] adopt usage.rst --- Resources/doc/usage.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Resources/doc/usage.rst b/Resources/doc/usage.rst index 8aa080c..cb04cc9 100644 --- a/Resources/doc/usage.rst +++ b/Resources/doc/usage.rst @@ -34,6 +34,22 @@ If you are using webpack and Encore to package your assets you can use the webpa Then use it simply by importing ``import Routing from 'fos-router';`` in your js or ts code +The plugin hooks into the webpack `build` and `watch` process and triggers the `fos:js-routing:dump` command automatically, +once routes have been changed. + +To avoid that, e.g. when building the frontend on a machine or docker image/layer, where no PHP is present, you can configure the +plugin to use a static dumped `routes.json` and suppress automatic recompilation of the file, by passing some options to the plugin: + +.. code-block:: js + + const FosRouting = require('fos-router/webpack/FosRouting'); + //... + Encore + .addPlugin(new FosRouting( + { target: './assets/js/routes.json' }, // <- path to dumped routes.json + false // <- set false to suppress automatic recompilation of the file + ) + ) Alternatively you can use the dump command and export your routes to json, this command will create a json file into the ``public/js`` folder: From 571de55de958d02655561cfe295b4ede2ef3669e Mon Sep 17 00:00:00 2001 From: Tobias Feijten Date: Tue, 23 Jan 2024 22:30:47 +0100 Subject: [PATCH 30/33] Prepare 3.5.0 release --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0b0649..c7fd7f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v3.5.0 - 2024-01-23 +- Fix TypeScript error when verbatimModuleSyntax is enabled ([#476](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/476)) +- Define RoutesResponse as a Service ([#474](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/474)) +- Ignore session in stateless requests ([#468](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/468)) +- Add option to skip registering compile hooks ([#462](https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/pull/462)) + ## v3.4.1 - 2023-12-15 - fix: do not use BannerPlugin but newer webpack-inject-plugin instead to fix vulnerability From 57ba412d813bb150b8a4ff9b65d4513725e31a1d Mon Sep 17 00:00:00 2001 From: Hlavtox Date: Wed, 20 Nov 2024 12:52:06 +0100 Subject: [PATCH 31/33] Fix PHP 8.4 deprecation notices --- Extractor/ExposedRoutesExtractor.php | 2 +- Response/RoutesResponse.php | 2 +- Serializer/Denormalizer/RouteCollectionDenormalizer.php | 4 ++-- Serializer/Normalizer/RouteCollectionNormalizer.php | 4 ++-- Serializer/Normalizer/RoutesResponseNormalizer.php | 4 ++-- Tests/Controller/ControllerTest.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Extractor/ExposedRoutesExtractor.php b/Extractor/ExposedRoutesExtractor.php index a2d7d6f..1c8e475 100644 --- a/Extractor/ExposedRoutesExtractor.php +++ b/Extractor/ExposedRoutesExtractor.php @@ -143,7 +143,7 @@ public function getScheme(): string /** * {@inheritDoc} */ - public function getCachePath(string $locale = null): string + public function getCachePath(?string $locale = null): string { $cachePath = $this->cacheDir.DIRECTORY_SEPARATOR.'fosJsRouting'; if (!file_exists($cachePath)) { diff --git a/Response/RoutesResponse.php b/Response/RoutesResponse.php index 9d18aac..332217b 100644 --- a/Response/RoutesResponse.php +++ b/Response/RoutesResponse.php @@ -21,7 +21,7 @@ class RoutesResponse public function __construct( protected ?string $baseUrl = null, - RouteCollection $routes = null, + ?RouteCollection $routes = null, protected ?string $prefix = null, protected ?string $host = null, protected ?string $port = null, diff --git a/Serializer/Denormalizer/RouteCollectionDenormalizer.php b/Serializer/Denormalizer/RouteCollectionDenormalizer.php index 741c0c0..53ef704 100644 --- a/Serializer/Denormalizer/RouteCollectionDenormalizer.php +++ b/Serializer/Denormalizer/RouteCollectionDenormalizer.php @@ -22,7 +22,7 @@ class RouteCollectionDenormalizer implements DenormalizerInterface /** * {@inheritDoc} */ - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): RouteCollection + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): RouteCollection { $collection = new RouteCollection(); @@ -45,7 +45,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar /** * {@inheritDoc} */ - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool + public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool { if (!is_array($data)) { return false; diff --git a/Serializer/Normalizer/RouteCollectionNormalizer.php b/Serializer/Normalizer/RouteCollectionNormalizer.php index 657ccf2..eef523c 100644 --- a/Serializer/Normalizer/RouteCollectionNormalizer.php +++ b/Serializer/Normalizer/RouteCollectionNormalizer.php @@ -24,7 +24,7 @@ class RouteCollectionNormalizer implements NormalizerInterface /** * {@inheritDoc} */ - public function normalize(mixed $object, string $format = null, array $context = []): array + public function normalize(mixed $object, ?string $format = null, array $context = []): array { $collection = []; @@ -47,7 +47,7 @@ public function normalize(mixed $object, string $format = null, array $context = /** * {@inheritDoc} */ - public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof RouteCollection; } diff --git a/Serializer/Normalizer/RoutesResponseNormalizer.php b/Serializer/Normalizer/RoutesResponseNormalizer.php index 46c6a63..5586916 100644 --- a/Serializer/Normalizer/RoutesResponseNormalizer.php +++ b/Serializer/Normalizer/RoutesResponseNormalizer.php @@ -24,7 +24,7 @@ class RoutesResponseNormalizer implements NormalizerInterface /** * {@inheritDoc} */ - public function normalize(mixed $object, string $format = null, array $context = []): array + public function normalize(mixed $object, ?string $format = null, array $context = []): array { return [ 'base_url' => $object->getBaseUrl(), @@ -40,7 +40,7 @@ public function normalize(mixed $object, string $format = null, array $context = /** * {@inheritDoc} */ - public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof RoutesResponse; } diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php index 9ef10fe..9183b58 100644 --- a/Tests/Controller/ControllerTest.php +++ b/Tests/Controller/ControllerTest.php @@ -243,7 +243,7 @@ public function testExposeDomain(): void $this->assertEquals('{"base_url":"","routes":{"homepage":{"tokens":[["text","\/"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"admin_index":{"tokens":[["text","\/admin"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"admin_pages":{"tokens":[["text","\/admin\/path"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"blog_index":{"tokens":[["text","\/blog"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]],"methods":[],"schemes":[]},"blog_post":{"tokens":[["variable","\/","[^\/]++","slug"],["text","\/blog"]],"defaults":[],"requirements":[],"hosttokens":[["text","localhost"]],"methods":[],"schemes":[]}},"prefix":"","host":"","port":null,"scheme":"","locale":"en"}', $response->getContent()); } - private function getExtractor(RouteCollection $exposedRoutes = null, $baseUrl = '') + private function getExtractor(?RouteCollection $exposedRoutes = null, $baseUrl = '') { if (null === $exposedRoutes) { $exposedRoutes = new RouteCollection(); From 8ddcbb13df72761b32b10a7c3b414bf27f7977e2 Mon Sep 17 00:00:00 2001 From: Florian Le Goff Date: Mon, 17 Jun 2024 14:39:47 +0200 Subject: [PATCH 32/33] fix: DI Extension deprecated since Symfony 7.1 --- DependencyInjection/FOSJsRoutingExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/FOSJsRoutingExtension.php b/DependencyInjection/FOSJsRoutingExtension.php index aeab79c..aac5d86 100644 --- a/DependencyInjection/FOSJsRoutingExtension.php +++ b/DependencyInjection/FOSJsRoutingExtension.php @@ -17,8 +17,8 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** * @author William DURAND From af2ee3a5406a3b57dfe1a0c010d2a29c2fdbfeed Mon Sep 17 00:00:00 2001 From: Johan Vlaar Date: Mon, 8 Apr 2024 14:09:33 +0200 Subject: [PATCH 33/33] Make sure the command is copy pastable by removing $ --- Resources/doc/installation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/doc/installation.rst b/Resources/doc/installation.rst index 3b85c2e..6444201 100644 --- a/Resources/doc/installation.rst +++ b/Resources/doc/installation.rst @@ -9,7 +9,7 @@ following command to download the latest stable version of this bundle: .. code-block:: bash - $ composer require friendsofsymfony/jsrouting-bundle + composer require friendsofsymfony/jsrouting-bundle This command requires you to have Composer installed globally, as explained in the `installation chapter`_ of the Composer documentation.