@@ -364,6 +364,8 @@ arbitrary matching logic:
364
364
condition : " context.getMethod() in ['GET', 'HEAD'] and request.headers.get('User-Agent') matches '/firefox/i'"
365
365
# expressions can also include configuration parameters:
366
366
# 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')"
367
369
368
370
.. code-block :: xml
369
371
@@ -378,6 +380,8 @@ arbitrary matching logic:
378
380
<condition >context.getMethod() in ['GET', 'HEAD'] and request.headers.get('User-Agent') matches '/firefox/i'</condition >
379
381
<!-- expressions can also include configuration parameters: -->
380
382
<!-- <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> -->
381
385
</route >
382
386
</routes >
383
387
@@ -392,7 +396,9 @@ arbitrary matching logic:
392
396
->controller([DefaultController::class, 'contact'])
393
397
->condition('context.getMethod() in ["GET", "HEAD"] and request.headers.get("User-Agent") matches "/firefox/i"')
394
398
// 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")')
396
402
;
397
403
};
398
404
@@ -408,6 +414,11 @@ and can use any of these variables created by Symfony:
408
414
The :ref: `Symfony Request <component-http-foundation-request >` object that
409
415
represents the current request.
410
416
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
+
411
422
Behind the scenes, expressions are compiled down to raw PHP. Because of this,
412
423
using the ``condition `` key causes no extra overhead beyond the time it takes
413
424
for the underlying PHP to execute.
0 commit comments