Skip to content

Commit 0feb2e3

Browse files
committed
Add PHP config support for routing
1 parent 0839cc6 commit 0feb2e3

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
7.3
55
---
66

7+
* Add `errors.php` and `webhook.php` routing configuration files (use them instead of their XML equivalent)
78
* Add support for the ObjectMapper component
89
* Add support for assets pre-compression
910
* Rename `TranslationUpdateCommand` to `TranslationExtractCommand`

Resources/config/routing/errors.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.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+
14+
return function (RoutingConfigurator $routes): void {
15+
$routes->add('_preview_error', '/{code}.{_format}')
16+
->controller('error_controller::preview')
17+
->defaults(['_format' => 'html'])
18+
->requirements(['code' => '\d+'])
19+
;
20+
};

Resources/config/routing/errors.xml

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

7-
<route id="_preview_error" path="/{code}.{_format}">
8-
<default key="_controller">error_controller::preview</default>
9-
<default key="_format">html</default>
10-
<requirement key="code">\d+</requirement>
11-
</route>
7+
<import resource="errors.php" type="php" />
128
</routes>

Resources/config/routing/webhook.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.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+
14+
return function (RoutingConfigurator $routes): void {
15+
$routes->add('_webhook_controller', '/{type}')
16+
->controller('webhook_controller::handle')
17+
->requirements(['type' => '.+'])
18+
;
19+
};

Resources/config/routing/webhook.xml

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

7-
<route id="_webhook_controller" path="/{type}">
8-
<default key="_controller">webhook.controller::handle</default>
9-
<requirement key="type">.+</requirement>
10-
</route>
7+
<import resource="webhook.php" type="php" />
118
</routes>

0 commit comments

Comments
 (0)