Skip to content

Commit 0623e9a

Browse files
committed
Provide PHP routing files in parallel of the XML ones
Symfony has deprecated the XML format for route definitions. The bundle now ships PHP routing files in addition to the XML ones (with tests ensuring they are in sync) and the documentation uses the PHP files. The XML files will be removed in the next major version of the bundle as removing them is a BC break.
1 parent 012d3a4 commit 0623e9a

9 files changed

Lines changed: 240 additions & 14 deletions

File tree

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ logging in, creating users, etc.
360360
361361
# app/config/routing.yml
362362
fos_user:
363-
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
363+
resource: "@FOSUserBundle/Resources/config/routing/all.php"
364364
365365
.. code-block:: xml
366366
367367
<!-- app/config/routing.xml -->
368-
<import resource="@FOSUserBundle/Resources/config/routing/all.xml"/>
368+
<import resource="@FOSUserBundle/Resources/config/routing/all.php"/>
369369
370370
.. note::
371371

docs/routing.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Advanced routing configuration
22
==============================
33

4-
By default, the routing file ``@FOSUserBundle/Resources/config/routing/all.xml`` imports
4+
By default, the routing file ``@FOSUserBundle/Resources/config/routing/all.php`` imports
55
all the routing files and enables all the routes.
66
In the case you want to enable or disable the different available routes, just use the
77
single routing configuration files.
@@ -12,29 +12,29 @@ single routing configuration files.
1212
1313
# app/config/routing.yml
1414
fos_user_security:
15-
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
15+
resource: "@FOSUserBundle/Resources/config/routing/security.php"
1616
1717
fos_user_profile:
18-
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
18+
resource: "@FOSUserBundle/Resources/config/routing/profile.php"
1919
prefix: /profile
2020
2121
fos_user_register:
22-
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
22+
resource: "@FOSUserBundle/Resources/config/routing/registration.php"
2323
prefix: /register
2424
2525
fos_user_resetting:
26-
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
26+
resource: "@FOSUserBundle/Resources/config/routing/resetting.php"
2727
prefix: /resetting
2828
2929
fos_user_change_password:
30-
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
30+
resource: "@FOSUserBundle/Resources/config/routing/change_password.php"
3131
prefix: /profile
3232
3333
.. code-block:: xml
3434
3535
<!-- app/config/routing.xml -->
36-
<import resource="@FOSUserBundle/Resources/config/routing/security.xml"/>
37-
<import resource="@FOSUserBundle/Resources/config/routing/profile.xml" prefix="/profile" />
38-
<import resource="@FOSUserBundle/Resources/config/routing/registration.xml" prefix="/register" />
39-
<import resource="@FOSUserBundle/Resources/config/routing/resetting.xml" prefix="/resetting" />
40-
<import resource="@FOSUserBundle/Resources/config/routing/change_password.xml" prefix="/profile" />
36+
<import resource="@FOSUserBundle/Resources/config/routing/security.php"/>
37+
<import resource="@FOSUserBundle/Resources/config/routing/profile.php" prefix="/profile" />
38+
<import resource="@FOSUserBundle/Resources/config/routing/registration.php" prefix="/register" />
39+
<import resource="@FOSUserBundle/Resources/config/routing/resetting.php" prefix="/resetting" />
40+
<import resource="@FOSUserBundle/Resources/config/routing/change_password.php" prefix="/profile" />
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle 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+
namespace Symfony\Component\Routing\Loader\Configurator;
13+
14+
return static function (RoutingConfigurator $routes): void {
15+
$routes->import('@FOSUserBundle/Resources/config/routing/security.php');
16+
17+
$routes->import('@FOSUserBundle/Resources/config/profile.php')
18+
->prefix('/profile');
19+
20+
$routes->import('@FOSUserBundle/Resources/config/registration.php')
21+
->prefix('/register');
22+
23+
$routes->import('@FOSUserBundle/Resources/config/resetting.php')
24+
->prefix('/resetting');
25+
26+
$routes->import('@FOSUserBundle/Resources/config/change_password.php')
27+
->prefix('/profile');
28+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle 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+
namespace Symfony\Component\Routing\Loader\Configurator;
13+
14+
return static function (RoutingConfigurator $routes): void {
15+
$routes->add('fos_user_change_password', '/change-password')
16+
->methods(['GET', 'POST'])
17+
->controller('fos_user.change_password.controller::changePasswordAction');
18+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle 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+
namespace Symfony\Component\Routing\Loader\Configurator;
13+
14+
return static function (RoutingConfigurator $routes): void {
15+
$routes->add('fos_user_profile_show', '/')
16+
->methods(['GET'])
17+
->controller('fos_user.profile.controller::showAction');
18+
19+
$routes->add('fos_user_profile_edit', '/edit')
20+
->methods(['GET', 'POST'])
21+
->controller('fos_user.profile.controller::editAction');
22+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle 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+
namespace Symfony\Component\Routing\Loader\Configurator;
13+
14+
return static function (RoutingConfigurator $routes): void {
15+
$routes->add('fos_user_registration_register', '/')
16+
->methods(['GET', 'POST'])
17+
->controller('fos_user.registration.controller::registerAction');
18+
19+
$routes->add('fos_user_registration_check_email', '/check-email')
20+
->methods(['GET'])
21+
->controller('fos_user.registration.controller::checkEmailAction');
22+
23+
$routes->add('fos_user_registration_confirm', '/confirm/{token}')
24+
->methods(['GET'])
25+
->controller('fos_user.registration.controller::confirmAction');
26+
27+
$routes->add('fos_user_registration_confirmed', '/confirmed')
28+
->methods(['GET'])
29+
->controller('fos_user.registration.controller::confirmedAction');
30+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle 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+
namespace Symfony\Component\Routing\Loader\Configurator;
13+
14+
return static function (RoutingConfigurator $routes): void {
15+
$routes->add('fos_user_resetting_request', '/request')
16+
->methods(['GET'])
17+
->controller('fos_user.resetting.controller::requestAction');
18+
19+
$routes->add('fos_user_resetting_send_email', '/send-email')
20+
->methods(['POST'])
21+
->controller('fos_user.resetting.controller::sendEmailAction');
22+
23+
$routes->add('fos_user_resetting_check_email', '/check-email')
24+
->methods(['GET'])
25+
->controller('fos_user.resetting.controller::checkEmailAction');
26+
27+
$routes->add('fos_user_resetting_reset', '/reset/{token}')
28+
->methods(['GET', 'POST'])
29+
->controller('fos_user.resetting.controller::resetAction');
30+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSUserBundle 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+
namespace Symfony\Component\Routing\Loader\Configurator;
13+
14+
return static function (RoutingConfigurator $routes): void {
15+
$routes->add('fos_user_security_login', '/login')
16+
->methods(['GET', 'POST'])
17+
->controller('fos_user.security.controller::loginAction');
18+
19+
$routes->add('fos_user_security_check', '/login_check')
20+
->methods(['POST'])
21+
->controller('fos_user.security.controller::checkAction');
22+
23+
$routes->add('fos_user_security_logout', '/logout')
24+
->methods(['GET', 'POST'])
25+
->controller('fos_user.security.controller::logoutAction');
26+
};

tests/Routing/RoutingTest.php

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\FileLocator;
16+
use Symfony\Component\Routing\Loader\PhpFileLoader;
1617
use Symfony\Component\Routing\Loader\XmlFileLoader;
1718
use Symfony\Component\Routing\RouteCollection;
1819

@@ -27,6 +28,43 @@ class RoutingTest extends TestCase
2728
*/
2829
public function testLoadRouting($routeName, $path, array $methods)
2930
{
31+
$locator = new FileLocator();
32+
$loader = new PhpFileLoader($locator);
33+
34+
$collection = new RouteCollection();
35+
$collection->addCollection($loader->load(__DIR__.'/../../src/Resources/config/routing/change_password.php'));
36+
$subCollection = $loader->load(__DIR__.'/../../src/Resources/config/routing/profile.php');
37+
$subCollection->addPrefix('/profile');
38+
$collection->addCollection($subCollection);
39+
$subCollection = $loader->load(__DIR__.'/../../src/Resources/config/routing/registration.php');
40+
$subCollection->addPrefix('/register');
41+
$collection->addCollection($subCollection);
42+
$subCollection = $loader->load(__DIR__.'/../../src/Resources/config/routing/resetting.php');
43+
$subCollection->addPrefix('/resetting');
44+
$collection->addCollection($subCollection);
45+
$collection->addCollection($loader->load(__DIR__.'/../../src/Resources/config/routing/security.php'));
46+
47+
$route = $collection->get($routeName);
48+
$this->assertNotNull($route, sprintf('The route "%s" should exists', $routeName));
49+
$this->assertSame($path, $route->getPath());
50+
$this->assertSame($methods, $route->getMethods());
51+
}
52+
53+
/**
54+
* @dataProvider loadRoutingProvider
55+
*
56+
* @group legacy
57+
*
58+
* @param string $routeName
59+
* @param string $path
60+
* @param string[] $methods
61+
*/
62+
public function testLoadRoutingLegacy($routeName, $path, array $methods)
63+
{
64+
if (!class_exists(XmlFileLoader::class)) {
65+
$this->markTestSkipped('XML routing files are not supported on Symfony 8.');
66+
}
67+
3068
$locator = new FileLocator();
3169
$loader = new XmlFileLoader($locator);
3270

@@ -52,7 +90,7 @@ public function testLoadRouting($routeName, $path, array $methods)
5290
/**
5391
* @return iterable<array{string, string, string[]}>
5492
*/
55-
public function loadRoutingProvider(): iterable
93+
public static function loadRoutingProvider(): iterable
5694
{
5795
return [
5896
['fos_user_change_password', '/change-password', ['GET', 'POST']],
@@ -75,4 +113,38 @@ public function loadRoutingProvider(): iterable
75113
['fos_user_security_logout', '/logout', ['GET', 'POST']],
76114
];
77115
}
116+
117+
/**
118+
* @dataProvider provideRouteFiles
119+
*
120+
* @group legacy
121+
*/
122+
public function testLegacyFileConsistency(string $filename): void
123+
{
124+
if (!class_exists(XmlFileLoader::class)) {
125+
$this->markTestSkipped('XML routing files are not supported on Symfony 8.');
126+
}
127+
128+
$locator = new FileLocator();
129+
130+
$phpLoader = new PhpFileLoader($locator);
131+
$xmlLoader = new XmlFileLoader($locator);
132+
133+
$phpCollection = $phpLoader->load(__DIR__.\sprintf('/../../src/Resources/config/routing/%s.php', $filename));
134+
$xmlCollection = $xmlLoader->load(__DIR__.\sprintf('/../../src/Resources/config/routing/%s.xml', $filename));
135+
136+
$this->assertEquals($phpCollection->all(), $xmlCollection->all());
137+
}
138+
139+
/**
140+
* @return iterable<array{string}>
141+
*/
142+
public static function provideRouteFiles(): iterable
143+
{
144+
yield ['profile'];
145+
yield ['registration'];
146+
yield ['resetting'];
147+
yield ['security'];
148+
}
78149
}
150+
// @php-cs-fixer-ignore php_unit_strict We intentionally use a non-strict comparison to verify that loaded routes are equivalent in the consistency test.

0 commit comments

Comments
 (0)