Skip to content

Commit 302939e

Browse files
committed
feature #62302 [Routing] Simplify importing routes defined on controller services (nicolas-grekas)
This PR was merged into the 7.4 branch. Discussion ---------- [Routing] Simplify importing routes defined on controller services | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Fine-tuning #61492 Before: ```yaml controllers: resource: attributes type: tagged_services ``` After: ```yaml controllers: resource: routing.controllers ``` And when using `MicroKernelTrait` (the default recipe), there's nothing to configure to have routes loaded from `#[Route]` attributes: ```yaml #config/routes.yaml # the file can be just empty from any config, and only have a comment saying what it's for ``` ```php // config/routes.php return Routes::config([ ]); ``` The way to opt-out from this `routing.controllers` import would be to override the `Kernel::configureRoutes()` method. Commits ------- 13e25caae7d [Routing] Simplify importing routes defined on controller services
2 parents a812d59 + 58adaf5 commit 302939e

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

Kernel/MicroKernelTrait.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,13 @@ private function configureRoutes(RoutingConfigurator $routes): void
7979
$routes->import($configDir.'/{routes}/'.$this->environment.'/*.{php,yaml}');
8080
$routes->import($configDir.'/{routes}/*.{php,yaml}');
8181

82+
$routes->import('routing.controllers');
83+
8284
if (is_file($this->getConfigDir().'/routes.yaml')) {
8385
$routes->import($configDir.'/routes.yaml');
8486
} else {
8587
$routes->import($configDir.'/{routes}.php');
8688
}
87-
88-
if ($fileName = (new \ReflectionObject($this))->getFileName()) {
89-
$routes->import($fileName, 'attribute');
90-
}
9189
}
9290

9391
/**

Tests/Fixtures/reference.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ public static function config(array $config): array
187187
*
188188
* return Routes::config([
189189
* 'controllers' => [
190-
* 'resource' => 'attributes',
191-
* 'type' => 'tagged_services',
190+
* 'resource' => 'routing.controllers',
192191
* ],
193192
* ]);
194193
* ```

0 commit comments

Comments
 (0)