Skip to content

Add PHP config support for routing #60232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 27, 2025
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
57 changes: 57 additions & 0 deletions UPGRADE-7.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,33 @@ FrameworkBundle
public function __construct(#[Autowire('@serializer.normalizer.object')] NormalizerInterface $normalizer) {}
```

* The XML routing configuration files (`errors.xml` and `webhook.xml`) are
deprecated, use their PHP equivalent ones:

*Before*
```yaml
when@dev:
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error

webhook:
resource: '@FrameworkBundle/Resources/config/routing/webhook.xml'
prefix: /webhook
```

*After*
```yaml
when@dev:
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.php'
prefix: /_error

webhook:
resource: '@FrameworkBundle/Resources/config/routing/webhook.php'
prefix: /webhook
```

HttpFoundation
--------------

Expand Down Expand Up @@ -112,6 +139,36 @@ PropertyInfo
* Deprecate the `PropertyTypeExtractorInterface::getTypes()` method, use `PropertyTypeExtractorInterface::getType()` instead
* Deprecate the `ConstructorArgumentTypeExtractorInterface::getTypesFromConstructor()` method, use `ConstructorArgumentTypeExtractorInterface::getTypeFromConstructor()` instead

Routing
-------

* The XML routing configuration files (`profiler.xml` and `wdt.xml`) are
deprecated, use their PHP equivalent ones:

*Before*
```yaml
when@dev:
web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
prefix: /_wdt

web_profiler_profiler:
resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
prefix: /_profiler
```

*After*
```yaml
when@dev:
web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.php'
prefix: /_wdt

web_profiler_profiler:
resource: '@WebProfilerBundle/Resources/config/routing/profiler.php
prefix: /_profiler
```

Security
--------

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
7.3
---

* Add `errors.php` and `webhook.php` routing configuration files (use them instead of their XML equivalent)
* Add support for the ObjectMapper component
* Add support for assets pre-compression
* Rename `TranslationUpdateCommand` to `TranslationExtractCommand`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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;

return function (RoutingConfigurator $routes): void {
$routes->add('_preview_error', '/{code}.{_format}')
->controller('error_controller::preview')
->defaults(['_format' => 'html'])
->requirements(['code' => '\d+'])
;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">

<route id="_preview_error" path="/{code}.{_format}">
<default key="_controller">error_controller::preview</default>
<default key="_format">html</default>
<requirement key="code">\d+</requirement>
</route>
<import resource="errors.php" type="php" />
</routes>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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;

return function (RoutingConfigurator $routes): void {
$routes->add('_webhook_controller', '/{type}')
->controller('webhook_controller::handle')
->requirements(['type' => '.+'])
;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">

<route id="_webhook_controller" path="/{type}">
<default key="_controller">webhook.controller::handle</default>
<requirement key="type">.+</requirement>
</route>
<import resource="webhook.php" type="php" />
</routes>
1 change: 1 addition & 0 deletions src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
7.3
---

* Add `profiler.php` and `wdt.php` routing configuration files (use them instead of their XML equivalent)
* Add `ajax_replace` option for replacing toolbar on AJAX requests

7.2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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('symfony/routing', '7.3', 'The "profiler.xml" routing configuration file is deprecated, import "profile.php" instead.');

break;
}
}
}

$routes->add('_profiler_home', '/')
->controller('web_profiler.controller.profiler::homeAction')
;
$routes->add('_profiler_search', '/search')
->controller('web_profiler.controller.profiler::searchAction')
;
$routes->add('_profiler_search_bar', '/search_bar')
->controller('web_profiler.controller.profiler::searchBarAction')
;
$routes->add('_profiler_phpinfo', '/phpinfo')
->controller('web_profiler.controller.profiler::phpinfoAction')
;
$routes->add('_profiler_xdebug', '/xdebug')
->controller('web_profiler.controller.profiler::xdebugAction')
;
$routes->add('_profiler_font', '/font/{fontName}.woff2')
->controller('web_profiler.controller.profiler::fontAction')
;
$routes->add('_profiler_search_results', '/{token}/search/results')
->controller('web_profiler.controller.profiler::searchResultsAction')
;
$routes->add('_profiler_open_file', '/open')
->controller('web_profiler.controller.profiler::openAction')
;
$routes->add('_profiler', '/{token}')
->controller('web_profiler.controller.profiler::panelAction')
;
$routes->add('_profiler_router', '/{token}/router')
->controller('web_profiler.controller.router::panelAction')
;
$routes->add('_profiler_exception', '/{token}/exception')
->controller('web_profiler.controller.exception_panel::body')
;
$routes->add('_profiler_exception_css', '/{token}/exception.css')
->controller('web_profiler.controller.exception_panel::stylesheet')
;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,5 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">

<route id="_profiler_home" path="/">
<default key="_controller">web_profiler.controller.profiler::homeAction</default>
</route>

<route id="_profiler_search" path="/search">
<default key="_controller">web_profiler.controller.profiler::searchAction</default>
</route>

<route id="_profiler_search_bar" path="/search_bar">
<default key="_controller">web_profiler.controller.profiler::searchBarAction</default>
</route>

<route id="_profiler_phpinfo" path="/phpinfo">
<default key="_controller">web_profiler.controller.profiler::phpinfoAction</default>
</route>

<route id="_profiler_xdebug" path="/xdebug">
<default key="_controller">web_profiler.controller.profiler::xdebugAction</default>
</route>

<route id="_profiler_font" path="/font/{fontName}.woff2">
<default key="_controller">web_profiler.controller.profiler::fontAction</default>
</route>

<route id="_profiler_search_results" path="/{token}/search/results">
<default key="_controller">web_profiler.controller.profiler::searchResultsAction</default>
</route>

<route id="_profiler_open_file" path="/open">
<default key="_controller">web_profiler.controller.profiler::openAction</default>
</route>

<route id="_profiler" path="/{token}">
<default key="_controller">web_profiler.controller.profiler::panelAction</default>
</route>

<route id="_profiler_router" path="/{token}/router">
<default key="_controller">web_profiler.controller.router::panelAction</default>
</route>

<route id="_profiler_exception" path="/{token}/exception">
<default key="_controller">web_profiler.controller.exception_panel::body</default>
</route>

<route id="_profiler_exception_css" path="/{token}/exception.css">
<default key="_controller">web_profiler.controller.exception_panel::stylesheet</default>
</route>

<import resource="profiler.php" type="php" />
</routes>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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('symfony/routing', '7.3', 'The "xdt.xml" routing configuration file is deprecated, import "xdt.php" instead.');

break;
}
}
}

$routes->add('_wdt_stylesheet', '/styles')
->controller('web_profiler.controller.profiler::toolbarStylesheetAction')
;
$routes->add('_wdt', '/{token}')
->controller('web_profiler.controller.profiler::toolbarAction')
;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,5 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">

<route id="_wdt_stylesheet" path="/styles">
<default key="_controller">web_profiler.controller.profiler::toolbarStylesheetAction</default>
</route>

<route id="_wdt" path="/{token}">
<default key="_controller">web_profiler.controller.profiler::toolbarAction</default>
</route>
<import resource="wdt.php" type="php" />
</routes>
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function registerBundles(): iterable

protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->import(__DIR__.'/../../Resources/config/routing/profiler.xml')->prefix('/_profiler');
$routes->import(__DIR__.'/../../Resources/config/routing/wdt.xml')->prefix('/_wdt');
$routes->import(__DIR__.'/../../Resources/config/routing/profiler.php')->prefix('/_profiler');
$routes->import(__DIR__.'/../../Resources/config/routing/wdt.php')->prefix('/_wdt');
$routes->add('_', '/')->controller('kernel::homepageController');
}

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/WebProfilerBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"php": ">=8.2",
"composer-runtime-api": ">=2.1",
"symfony/config": "^7.3",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/http-kernel": "^6.4|^7.0",
"symfony/routing": "^6.4|^7.0",
Expand Down
Loading