Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ logging in, creating users, etc.

# app/config/routing.yml
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
resource: "@FOSUserBundle/Resources/config/routing/all.php"

.. code-block:: xml

<!-- app/config/routing.xml -->
<import resource="@FOSUserBundle/Resources/config/routing/all.xml"/>
<import resource="@FOSUserBundle/Resources/config/routing/all.php"/>

.. note::

Expand Down
22 changes: 11 additions & 11 deletions docs/routing.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Advanced routing configuration
==============================

By default, the routing file ``@FOSUserBundle/Resources/config/routing/all.xml`` imports
By default, the routing file ``@FOSUserBundle/Resources/config/routing/all.php`` imports
all the routing files and enables all the routes.
In the case you want to enable or disable the different available routes, just use the
single routing configuration files.
Expand All @@ -12,29 +12,29 @@ single routing configuration files.

# app/config/routing.yml
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
resource: "@FOSUserBundle/Resources/config/routing/security.php"

fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
resource: "@FOSUserBundle/Resources/config/routing/profile.php"
prefix: /profile

fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
resource: "@FOSUserBundle/Resources/config/routing/registration.php"
prefix: /register

fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
resource: "@FOSUserBundle/Resources/config/routing/resetting.php"
prefix: /resetting

fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
resource: "@FOSUserBundle/Resources/config/routing/change_password.php"
prefix: /profile

.. code-block:: xml

<!-- app/config/routing.xml -->
<import resource="@FOSUserBundle/Resources/config/routing/security.xml"/>
<import resource="@FOSUserBundle/Resources/config/routing/profile.xml" prefix="/profile" />
<import resource="@FOSUserBundle/Resources/config/routing/registration.xml" prefix="/register" />
<import resource="@FOSUserBundle/Resources/config/routing/resetting.xml" prefix="/resetting" />
<import resource="@FOSUserBundle/Resources/config/routing/change_password.xml" prefix="/profile" />
<import resource="@FOSUserBundle/Resources/config/routing/security.php"/>
<import resource="@FOSUserBundle/Resources/config/routing/profile.php" prefix="/profile" />
<import resource="@FOSUserBundle/Resources/config/routing/registration.php" prefix="/register" />
<import resource="@FOSUserBundle/Resources/config/routing/resetting.php" prefix="/resetting" />
<import resource="@FOSUserBundle/Resources/config/routing/change_password.php" prefix="/profile" />
28 changes: 28 additions & 0 deletions src/Resources/config/routing/all.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Routing\Loader\Configurator;

return static function (RoutingConfigurator $routes): void {
$routes->import('@FOSUserBundle/Resources/config/routing/security.php');

$routes->import('@FOSUserBundle/Resources/config/profile.php')
->prefix('/profile');

$routes->import('@FOSUserBundle/Resources/config/registration.php')
->prefix('/register');

$routes->import('@FOSUserBundle/Resources/config/resetting.php')
->prefix('/resetting');

$routes->import('@FOSUserBundle/Resources/config/change_password.php')
->prefix('/profile');
};
18 changes: 18 additions & 0 deletions src/Resources/config/routing/change_password.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Routing\Loader\Configurator;

return static function (RoutingConfigurator $routes): void {
$routes->add('fos_user_change_password', '/change-password')
->methods(['GET', 'POST'])
->controller('fos_user.change_password.controller::changePasswordAction');
};
22 changes: 22 additions & 0 deletions src/Resources/config/routing/profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Routing\Loader\Configurator;

return static function (RoutingConfigurator $routes): void {
$routes->add('fos_user_profile_show', '/')
->methods(['GET'])
->controller('fos_user.profile.controller::showAction');

$routes->add('fos_user_profile_edit', '/edit')
->methods(['GET', 'POST'])
->controller('fos_user.profile.controller::editAction');
};
30 changes: 30 additions & 0 deletions src/Resources/config/routing/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Routing\Loader\Configurator;

return static function (RoutingConfigurator $routes): void {
$routes->add('fos_user_registration_register', '/')
->methods(['GET', 'POST'])
->controller('fos_user.registration.controller::registerAction');

$routes->add('fos_user_registration_check_email', '/check-email')
->methods(['GET'])
->controller('fos_user.registration.controller::checkEmailAction');

$routes->add('fos_user_registration_confirm', '/confirm/{token}')
->methods(['GET'])
->controller('fos_user.registration.controller::confirmAction');

$routes->add('fos_user_registration_confirmed', '/confirmed')
->methods(['GET'])
->controller('fos_user.registration.controller::confirmedAction');
};
30 changes: 30 additions & 0 deletions src/Resources/config/routing/resetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Routing\Loader\Configurator;

return static function (RoutingConfigurator $routes): void {
$routes->add('fos_user_resetting_request', '/request')
->methods(['GET'])
->controller('fos_user.resetting.controller::requestAction');

$routes->add('fos_user_resetting_send_email', '/send-email')
->methods(['POST'])
->controller('fos_user.resetting.controller::sendEmailAction');

$routes->add('fos_user_resetting_check_email', '/check-email')
->methods(['GET'])
->controller('fos_user.resetting.controller::checkEmailAction');

$routes->add('fos_user_resetting_reset', '/reset/{token}')
->methods(['GET', 'POST'])
->controller('fos_user.resetting.controller::resetAction');
};
26 changes: 26 additions & 0 deletions src/Resources/config/routing/security.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Routing\Loader\Configurator;

return static function (RoutingConfigurator $routes): void {
$routes->add('fos_user_security_login', '/login')
->methods(['GET', 'POST'])
->controller('fos_user.security.controller::loginAction');

$routes->add('fos_user_security_check', '/login_check')
->methods(['POST'])
->controller('fos_user.security.controller::checkAction');

$routes->add('fos_user_security_logout', '/logout')
->methods(['GET', 'POST'])
->controller('fos_user.security.controller::logoutAction');
};
74 changes: 73 additions & 1 deletion tests/Routing/RoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\PhpFileLoader;
use Symfony\Component\Routing\Loader\XmlFileLoader;
use Symfony\Component\Routing\RouteCollection;

Expand All @@ -27,6 +28,43 @@ class RoutingTest extends TestCase
*/
public function testLoadRouting($routeName, $path, array $methods)
{
$locator = new FileLocator();
$loader = new PhpFileLoader($locator);

$collection = new RouteCollection();
$collection->addCollection($loader->load(__DIR__.'/../../src/Resources/config/routing/change_password.php'));
$subCollection = $loader->load(__DIR__.'/../../src/Resources/config/routing/profile.php');
$subCollection->addPrefix('/profile');
$collection->addCollection($subCollection);
$subCollection = $loader->load(__DIR__.'/../../src/Resources/config/routing/registration.php');
$subCollection->addPrefix('/register');
$collection->addCollection($subCollection);
$subCollection = $loader->load(__DIR__.'/../../src/Resources/config/routing/resetting.php');
$subCollection->addPrefix('/resetting');
$collection->addCollection($subCollection);
$collection->addCollection($loader->load(__DIR__.'/../../src/Resources/config/routing/security.php'));

$route = $collection->get($routeName);
$this->assertNotNull($route, sprintf('The route "%s" should exists', $routeName));
$this->assertSame($path, $route->getPath());
$this->assertSame($methods, $route->getMethods());
}

/**
* @dataProvider loadRoutingProvider
*
* @group legacy
*
* @param string $routeName
* @param string $path
* @param string[] $methods
*/
public function testLoadRoutingLegacy($routeName, $path, array $methods)
{
if (!class_exists(XmlFileLoader::class)) {
$this->markTestSkipped('XML routing files are not supported on Symfony 8.');
}

$locator = new FileLocator();
$loader = new XmlFileLoader($locator);

Expand All @@ -52,7 +90,7 @@ public function testLoadRouting($routeName, $path, array $methods)
/**
* @return iterable<array{string, string, string[]}>
*/
public function loadRoutingProvider(): iterable
public static function loadRoutingProvider(): iterable
{
return [
['fos_user_change_password', '/change-password', ['GET', 'POST']],
Expand All @@ -75,4 +113,38 @@ public function loadRoutingProvider(): iterable
['fos_user_security_logout', '/logout', ['GET', 'POST']],
];
}

/**
* @dataProvider provideRouteFiles
*
* @group legacy
*/
public function testLegacyFileConsistency(string $filename): void
{
if (!class_exists(XmlFileLoader::class)) {
$this->markTestSkipped('XML routing files are not supported on Symfony 8.');
}

$locator = new FileLocator();

$phpLoader = new PhpFileLoader($locator);
$xmlLoader = new XmlFileLoader($locator);

$phpCollection = $phpLoader->load(__DIR__.\sprintf('/../../src/Resources/config/routing/%s.php', $filename));
$xmlCollection = $xmlLoader->load(__DIR__.\sprintf('/../../src/Resources/config/routing/%s.xml', $filename));

$this->assertEquals($phpCollection->all(), $xmlCollection->all());
}

/**
* @return iterable<array{string}>
*/
public static function provideRouteFiles(): iterable
{
yield ['profile'];
yield ['registration'];
yield ['resetting'];
yield ['security'];
}
}
// @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.