-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add url
and query_string
processors
#11128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -537,6 +537,128 @@ Symfony provides the following env var processors: | |
|
||
The ``default`` processor was introduced in Symfony 4.3. | ||
|
||
``env(url:FOO)`` | ||
Parses an absolute URL and returns its components. | ||
|
||
.. code-block:: bash | ||
|
||
# .env | ||
MONGODB_URL="mongodb://db_user:[email protected]:27017/db_name" | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# config/packages/mongodb.yaml | ||
mongo_db_bundle: | ||
clients: | ||
default: | ||
hosts: | ||
- { host: '%env(key:host:url:MONGODB_URL)%', port: '%env(key:port:url:MONGODB_URL)%' } | ||
username: '%env(key:user:url:MONGODB_URL)%' | ||
password: '%env(key:pass:url:MONGODB_URL)%' | ||
connections: | ||
default: | ||
database_name: '%env(key:path:url:MONGODB_URL)%' | ||
|
||
.. code-block:: xml | ||
|
||
<!-- config/packages/mongodb.xml --> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<mongodb:config> | ||
<mongodb:client name="default" username="%env(key:user:url:MONGODB_URL)%" password="%env(key:pass:url:MONGODB_URL)%"> | ||
<mongodb:host host="%env(key:host:url:MONGODB_URL)%" port="%env(key:port:url:MONGODB_URL)%"/> | ||
</mongodb:client> | ||
<mongodb:connections name="default" database_name="%env(key:path:url:MONGODB_URL)%"/> | ||
</mongodb:config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
// config/packages/mongodb.php | ||
$container->loadFromExtension('mongodb', [ | ||
'clients' => [ | ||
'default' => [ | ||
'hosts' => [ | ||
[ | ||
'host' => '%env(key:host:url:MONGODB_URL)%', | ||
'port' => '%env(key:port:url:MONGODB_URL)%', | ||
], | ||
], | ||
'username' => '%env(key:user:url:MONGODB_URL)%', | ||
'password' => '%env(key:pass:url:MONGODB_URL)%', | ||
], | ||
], | ||
'connections' => [ | ||
'default' => [ | ||
'database_name' => '%env(key:path:url:MONGODB_URL)%', | ||
], | ||
], | ||
]); | ||
|
||
.. caution:: | ||
|
||
In order to ease extraction of the resource from the URL, The leading | ||
``/`` is trimed from the ``path`` component. | ||
|
||
.. versionadded:: 4.3 | ||
|
||
The ``url`` processor was introduced in Symfony 4.3. | ||
|
||
``env(query_string:FOO)`` | ||
Parses an encoded string as if it were the query string passed via a URL. | ||
|
||
.. code-block:: bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @javiereguiluz is bash ok or better terminal or text here for the code block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this is the same code block used above in that file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the info, maybe we should change them all. Not sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For information purposes: we decided a few days ago to use |
||
|
||
# .env | ||
MONGODB_URL="mongodb://db_user:[email protected]:27017/db_name?timeout=3000" | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# config/packages/mongodb.yaml | ||
mongo_db_bundle: | ||
clients: | ||
default: | ||
# ... | ||
connectTimeoutMS: '%env(int:key:timeout:query_string:MONGODB_URL)%' | ||
|
||
.. code-block:: xml | ||
|
||
<!-- config/packages/mongodb.xml --> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<mongodb:config> | ||
<mongodb:client name="default" connectTimeoutMS="%env(int:key:timeout:query_string:MONGODB_URL)%" /> | ||
</mongodb:config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
// config/packages/mongodb.php | ||
$container->loadFromExtension('mongodb', [ | ||
'clients' => [ | ||
'default' => [ | ||
// ... | ||
'connectTimeoutMS' => '%env(int:key:timeout:query_string:MONGODB_URL)%', | ||
], | ||
], | ||
]); | ||
|
||
.. versionadded:: 4.3 | ||
|
||
The ``query_string`` processor was introduced in Symfony 4.3. | ||
|
||
It is also possible to combine any number of processors: | ||
|
||
.. code-block:: yaml | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -> the