Skip to content

Commit a71cb66

Browse files
mbabkertobias-93
andauthored
Add a PHP routing file and deprecate the XML file (#499)
Co-authored-by: Tobias Feijten <[email protected]>
1 parent 51efc00 commit a71cb66

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

Resources/config/routing/routing-sf4.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,5 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
55

6-
<route id="fos_js_routing_js" path="/js/routing.{_format}" methods="GET">
7-
<default key="_controller">fos_js_routing.controller::indexAction</default>
8-
<default key="_format">js</default>
9-
<requirement key="_format">js|json</requirement>
10-
</route>
6+
<import resource="routing.php" type="php" />
117
</routes>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSJsRoutingBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
13+
use Symfony\Component\Routing\Loader\XmlFileLoader;
14+
15+
return function (RoutingConfigurator $routes): void {
16+
foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT) as $trace) {
17+
if (isset($trace['object']) && $trace['object'] instanceof XmlFileLoader && 'doImport' === $trace['function']) {
18+
if (__DIR__ === dirname(realpath($trace['args'][3]))) {
19+
trigger_deprecation('friendsofsymfony/jsrouting-bundle', '3.6', 'The "routing-sf4.xml" routing configuration file is deprecated, import "routing.php" instead.');
20+
21+
break;
22+
}
23+
}
24+
}
25+
26+
$routes->add('fos_js_routing_js', '/js/routing.{_format}')
27+
->methods(['GET'])
28+
->controller('fos_js_routing.controller::indexAction')
29+
->requirements(['_format' => 'js|json'])
30+
->defaults(['_format' => 'js'])
31+
;
32+
};

Resources/doc/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Load the bundle's routing definition in the application:
4343
.. code-block:: yaml
4444
4545
fos_js_routing:
46-
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing-sf4.xml"
46+
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.php"
4747
4848
Step 4: Publish the Assets
4949
--------------------------

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
],
1818
"require": {
1919
"php": "^8.0",
20+
"symfony/console": "^5.4|^6.4|^7.0",
21+
"symfony/deprecation-contracts": "^2.1|^3.0",
2022
"symfony/framework-bundle": "^5.4|^6.4|^7.0",
2123
"symfony/serializer": "^5.4|^6.4|^7.0",
22-
"symfony/console": "^5.4|^6.4|^7.0",
2324
"willdurand/jsonp-callback-validator": "~1.1|^2.0"
2425
},
2526
"require-dev": {

0 commit comments

Comments
 (0)