Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4fb0d0a

Browse files
committed
Addurl andquery_string processors
1 parent0c1aa7d commit4fb0d0a

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

‎configuration/external_parameters.rst‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,128 @@ Symfony provides the following env var processors:
537537

538538
The ``default`` processor was introduced in Symfony 4.3.
539539

540+
``env(url:FOO)``
541+
Parses an absolute URL and returns its components.
542+
543+
..code-block::bash
544+
545+
# .env
546+
MONGODB_URL="mongodb://db_user:db_password@127.0.0.1:27017/db_name"
547+
548+
..configuration-block::
549+
550+
..code-block::yaml
551+
552+
# config/packages/mongodb.yaml
553+
mongo_db_bundle:
554+
clients:
555+
default:
556+
hosts:
557+
-{ host: '%env(key:host:url:MONGODB_URL)%', port: '%env(key:port:url:MONGODB_URL)%' }
558+
username:'%env(key:user:url:MONGODB_URL)%'
559+
password:'%env(key:pass:url:MONGODB_URL)%'
560+
connections:
561+
default:
562+
database_name:'%env(key:path:url:MONGODB_URL)%'
563+
564+
..code-block::xml
565+
566+
<!-- config/packages/mongodb.xml-->
567+
<?xml version="1.0" encoding="UTF-8" ?>
568+
<containerxmlns="http://symfony.com/schema/dic/services"
569+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
570+
xsi:schemaLocation="http://symfony.com/schema/dic/services
571+
http://symfony.com/schema/dic/services/services-1.0.xsd">
572+
573+
<mongodb:config>
574+
<mongodb:clientname="default"username="%env(key:user:url:MONGODB_URL)%"password="%env(key:pass:url:MONGODB_URL)%">
575+
<mongodb:hosthost="%env(key:host:url:MONGODB_URL)%"port="%env(key:port:url:MONGODB_URL)%"/>
576+
</mongodb:client>
577+
<mongodb:connectionsname="default"database_name="%env(key:path:url:MONGODB_URL)%"/>
578+
</mongodb:config>
579+
</container>
580+
581+
..code-block::php
582+
583+
// config/packages/mongodb.php
584+
$container->loadFromExtension('mongodb', [
585+
'clients' => [
586+
'default' => [
587+
'hosts' => [
588+
[
589+
'host' => '%env(key:host:url:MONGODB_URL)%',
590+
'port' => '%env(key:port:url:MONGODB_URL)%',
591+
],
592+
],
593+
'username' => '%env(key:user:url:MONGODB_URL)%',
594+
'password' => '%env(key:pass:url:MONGODB_URL)%',
595+
],
596+
],
597+
'connections' => [
598+
'default' => [
599+
'database_name' => '%env(key:path:url:MONGODB_URL)%',
600+
],
601+
],
602+
]);
603+
604+
..caution::
605+
606+
In order to ease extraction of the resource from the URL, The leading
607+
``/`` is trimed from the ``path`` component.
608+
609+
..versionadded::4.3
610+
611+
The ``url`` processor was introduced in Symfony 4.3.
612+
613+
``env(query_string:FOO)``
614+
Parses an encoded string as if it were the query string passed via a URL.
615+
616+
..code-block::bash
617+
618+
# .env
619+
MONGODB_URL="mongodb://db_user:db_password@127.0.0.1:27017/db_name?timeout=3000"
620+
621+
..configuration-block::
622+
623+
..code-block::yaml
624+
625+
# config/packages/mongodb.yaml
626+
mongo_db_bundle:
627+
clients:
628+
default:
629+
# ...
630+
connectTimeoutMS:'%env(int:key:timeout:query_string:MONGODB_URL)%'
631+
632+
..code-block::xml
633+
634+
<!-- config/packages/mongodb.xml-->
635+
<?xml version="1.0" encoding="UTF-8" ?>
636+
<containerxmlns="http://symfony.com/schema/dic/services"
637+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
638+
xsi:schemaLocation="http://symfony.com/schema/dic/services
639+
http://symfony.com/schema/dic/services/services-1.0.xsd">
640+
641+
<mongodb:config>
642+
<mongodb:clientname="default"connectTimeoutMS="%env(int:key:timeout:query_string:MONGODB_URL)%" />
643+
</mongodb:config>
644+
</container>
645+
646+
..code-block::php
647+
648+
// config/packages/mongodb.php
649+
$container->loadFromExtension('mongodb', [
650+
'clients' => [
651+
'default' => [
652+
// ...
653+
'connectTimeoutMS' => '%env(int:key:timeout:query_string:MONGODB_URL)%',
654+
],
655+
],
656+
]);
657+
658+
..versionadded::4.3
659+
660+
The ``query_string`` processor was introduced in Symfony 4.3.
661+
540662
It is also possible to combine any number of processors:
541663

542664
..code-block::yaml

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp