@@ -254,6 +254,72 @@ Use the ``methods`` option to restrict the verbs each route should respond to:
254
254
255
255
.. _routing-matching-expressions :
256
256
257
+ Matching Environments
258
+ ~~~~~~~~~~~~~~~~~~~~~
259
+
260
+ The ``env `` option can be used to make a route conditional on the
261
+ :ref: `configuration environment <configuration-environments >`, the route will
262
+ only be registered if the environment matches.
263
+
264
+ .. configuration-block ::
265
+
266
+ .. code-block :: php-attributes
267
+
268
+ // src/Controller/DefaultController.php
269
+ namespace App\Controller;
270
+
271
+ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
272
+ use Symfony\Component\HttpFoundation\Response;
273
+ use Symfony\Component\Routing\Attribute\Route;
274
+
275
+ class DefaultController extends AbstractController
276
+ {
277
+ #[Route(
278
+ '/tools',
279
+ name: 'tools',
280
+ env: 'dev',
281
+ )]
282
+ public function developerTools(): Response
283
+ {
284
+ // ...
285
+ }
286
+ }
287
+
288
+ .. code-block :: yaml
289
+
290
+ # config/routes.yaml
291
+ tools :
292
+ path : /tools
293
+ controller : App\Controller\DefaultController::developerTools
294
+ env : dev
295
+
296
+ .. code-block :: xml
297
+
298
+ <!-- config/routes.xml -->
299
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
300
+ <routes xmlns =" http://symfony.com/schema/routing"
301
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
302
+ xsi : schemaLocation =" http://symfony.com/schema/routing
303
+ https://symfony.com/schema/routing/routing-1.0.xsd" >
304
+
305
+ <route id =" tools" path =" /tools" controller =" App\Controller\DefaultController::developerTools" >
306
+ <env >dev</env >
307
+ </route >
308
+ </routes >
309
+
310
+ .. code-block :: php
311
+
312
+ // config/routes.php
313
+ use App\Controller\DefaultController;
314
+ use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
315
+
316
+ return function (RoutingConfigurator $routes): void {
317
+ $routes->add('tools', '/tools')
318
+ ->controller([DefaultController::class, 'developerTools'])
319
+ ->env('dev')
320
+ ;
321
+ };
322
+
257
323
Matching Expressions
258
324
~~~~~~~~~~~~~~~~~~~~
259
325
0 commit comments