From 65d2f4c78058a4fc19c0b4797719efe18f9a467e Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Tue, 14 Oct 2025 14:51:47 -0400 Subject: [PATCH] Add a PHP routing file and deprecate the XML file --- Resources/config/routing/routing-sf4.xml | 6 +---- Resources/config/routing/routing.php | 32 ++++++++++++++++++++++++ Resources/doc/installation.rst | 2 +- composer.json | 3 ++- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 Resources/config/routing/routing.php diff --git a/Resources/config/routing/routing-sf4.xml b/Resources/config/routing/routing-sf4.xml index e75a19ad..9f0d5af7 100644 --- a/Resources/config/routing/routing-sf4.xml +++ b/Resources/config/routing/routing-sf4.xml @@ -3,9 +3,5 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - - fos_js_routing.controller::indexAction - js - js|json - + diff --git a/Resources/config/routing/routing.php b/Resources/config/routing/routing.php new file mode 100644 index 00000000..0bf59aaa --- /dev/null +++ b/Resources/config/routing/routing.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; +use Symfony\Component\Routing\Loader\XmlFileLoader; + +return function (RoutingConfigurator $routes): void { + foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT) as $trace) { + if (isset($trace['object']) && $trace['object'] instanceof XmlFileLoader && 'doImport' === $trace['function']) { + if (__DIR__ === dirname(realpath($trace['args'][3]))) { + trigger_deprecation('friendsofsymfony/jsrouting-bundle', '3.6', 'The "routing-sf4.xml" routing configuration file is deprecated, import "routing.php" instead.'); + + break; + } + } + } + + $routes->add('fos_js_routing_js', '/js/routing.{_format}') + ->methods(['GET']) + ->controller('fos_js_routing.controller::indexAction') + ->requirements(['_format' => 'js|json']) + ->defaults(['_format' => 'js']) + ; +}; diff --git a/Resources/doc/installation.rst b/Resources/doc/installation.rst index 64442015..5250b857 100644 --- a/Resources/doc/installation.rst +++ b/Resources/doc/installation.rst @@ -43,7 +43,7 @@ Load the bundle's routing definition in the application: .. code-block:: yaml fos_js_routing: - resource: "@FOSJsRoutingBundle/Resources/config/routing/routing-sf4.xml" + resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.php" Step 4: Publish the Assets -------------------------- diff --git a/composer.json b/composer.json index b417f4d0..f58a2f50 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,10 @@ ], "require": { "php": "^8.0", + "symfony/console": "^5.4|^6.0|^7.0", + "symfony/deprecation-contracts": "^2.1|^3.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": {