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

Commitc42ea17

Browse files
committed
minor#11128 Addurl andquery_string processors (jderusse)
This PR was merged into the master branch.Discussion----------Add `url` and `query_string` processorsDocumentation forsymfony/symfony#28975Commits-------4fb0d0a Add `url` and `query_string` processors
2 parents1612b74 +4fb0d0a commitc42ea17

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
@@ -540,6 +540,128 @@ Symfony provides the following env var processors:
540540

541541
The ``default`` processor was introduced in Symfony 4.3.
542542

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

545667
..code-block::yaml

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp