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

Addurl andquery_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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 1 commit intosymfony:masterfromjderusse:env-url
Mar 25, 2019
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletionsconfiguration/external_parameters.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:db_password@127.0.0.1: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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The -> the

javiereguiluz reacted with thumbs up emoji
``/`` 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Note: this is the same code block used above in that file

OskarStark reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for the info, maybe we should change them all. Not sure

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For information purposes: we decided a few days ago to usebash for "bash things" (such as displaying the content of.env files) and useterminal for real consoles (when we show commands and their outputs).


# .env
MONGODB_URL="mongodb://db_user:db_password@127.0.0.1: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
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp