@@ -364,6 +364,8 @@ arbitrary matching logic:
364364 condition : " context.getMethod() in ['GET', 'HEAD'] and request.headers.get('User-Agent') matches '/firefox/i'"
365365 # expressions can also include configuration parameters:
366366 # condition: "request.headers.get('User-Agent') matches '%app.allowed_browsers%'"
367+ # expressions can even use environment variables:
368+ # condition: "context.getHost() == env('APP_MAIN_HOST')"
367369
368370 .. code-block :: xml
369371
@@ -378,6 +380,8 @@ arbitrary matching logic:
378380 <condition >context.getMethod() in ['GET', 'HEAD'] and request.headers.get('User-Agent') matches '/firefox/i'</condition >
379381 <!-- expressions can also include configuration parameters: -->
380382 <!-- <condition>request.headers.get('User-Agent') matches '%app.allowed_browsers%'</condition> -->
383+ <!-- expressions can even use environment variables: -->
384+ <!-- <condition>context.getHost() == env('APP_MAIN_HOST')</condition> -->
381385 </route >
382386 </routes >
383387
@@ -392,7 +396,9 @@ arbitrary matching logic:
392396 ->controller([DefaultController::class, 'contact'])
393397 ->condition('context.getMethod() in ["GET", "HEAD"] and request.headers.get("User-Agent") matches "/firefox/i"')
394398 // expressions can also include configuration parameters:
395- // 'request.headers.get("User-Agent") matches "%app.allowed_browsers%"'
399+ // ->condition('request.headers.get("User-Agent") matches "%app.allowed_browsers%"')
400+ // expressions can even use environment variables:
401+ // ->condition('context.getHost() == env("APP_MAIN_HOST")')
396402 ;
397403 };
398404
@@ -408,6 +414,11 @@ and can use any of these variables created by Symfony:
408414 The :ref: `Symfony Request <component-http-foundation-request >` object that
409415 represents the current request.
410416
417+ You can also use this function:
418+
419+ ``env(string $name) ``
420+ Returns the value of a variable using :doc: `Environment Variable Processors <configuration/env_var_processors >`
421+
411422Behind the scenes, expressions are compiled down to raw PHP. Because of this,
412423using the ``condition `` key causes no extra overhead beyond the time it takes
413424for the underlying PHP to execute.
0 commit comments