@@ -249,6 +249,68 @@ Use the ``methods`` option to restrict the verbs each route should respond to:
249249 automatically for you when the :ref: `framework.http_method_override <configuration-framework-http_method_override >`
250250 option is ``true ``.
251251
252+ Matching Environments
253+ ~~~~~~~~~~~~~~~~~~~~~
254+
255+ Use the ``env `` option to register a route only when the current
256+ :ref: `configuration environment <configuration-environments >` matches the
257+ given value:
258+
259+ .. configuration-block ::
260+
261+ .. code-block :: php-attributes
262+
263+ // src/Controller/DefaultController.php
264+ namespace App\Controller;
265+
266+ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
267+ use Symfony\Component\HttpFoundation\Response;
268+ use Symfony\Component\Routing\Attribute\Route;
269+
270+ class DefaultController extends AbstractController
271+ {
272+ #[Route('/tools', name: 'tools', env: 'dev')]
273+ public function developerTools(): Response
274+ {
275+ // ...
276+ }
277+ }
278+
279+ .. code-block :: yaml
280+
281+ # config/routes.yaml
282+ tools :
283+ path : /tools
284+ controller : App\Controller\DefaultController::developerTools
285+ env : dev
286+
287+ .. code-block :: xml
288+
289+ <!-- config/routes.xml -->
290+ <?xml version =" 1.0" encoding =" UTF-8" ?>
291+ <routes xmlns =" http://symfony.com/schema/routing"
292+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
293+ xsi : schemaLocation =" http://symfony.com/schema/routing
294+ https://symfony.com/schema/routing/routing-1.0.xsd" >
295+
296+ <route id =" tools" path =" /tools" controller =" App\Controller\DefaultController::developerTools" >
297+ <env >dev</env >
298+ </route >
299+ </routes >
300+
301+ .. code-block :: php
302+
303+ // config/routes.php
304+ use App\Controller\DefaultController;
305+ use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
306+
307+ return function (RoutingConfigurator $routes): void {
308+ $routes->add('tools', '/tools')
309+ ->controller([DefaultController::class, 'developerTools'])
310+ ->env('dev')
311+ ;
312+ };
313+
252314 .. _routing-matching-expressions :
253315
254316Matching Expressions
0 commit comments