Skip to content

Minor fixes in configuration blocks #13217

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

Merged
merged 1 commit into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion bundles/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ Assuming the XSD file is called ``hello-1.0.xsd``, the schema location will be
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:acme-hello="http://acme_company.com/schema/dic/hello"
xsi:schemaLocation="http://acme_company.com/schema/dic/hello
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://acme_company.com/schema/dic/hello
https://acme_company.com/schema/dic/hello/hello-1.0.xsd">

<acme-hello:config>
Expand Down
7 changes: 6 additions & 1 deletion bundles/prepend_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ The above would be the equivalent of writing the following into the
xmlns:acme-something="http://example.org/schema/dic/acme_something"
xmlns:acme-other="http://example.org/schema/dic/acme_other"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">
https://symfony.com/schema/dic/services/services-1.0.xsd
http://example.org/schema/dic/acme_something
https://example.org/schema/dic/acme_something/acme_something-1.0.xsd
http://example.org/schema/dic/acme_other
https://example.org/schema/dic/acme_something/acme_other-1.0.xsd">

<acme-something:config use-acme-goodbye="false">
<!-- ... -->
<acme-something:entity-manager-name>non_default</acme-something:entity-manager-name>
</acme-something:config>

Expand Down
42 changes: 32 additions & 10 deletions cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ adapter (template) they use by using the ``app`` and ``system`` key like:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:cache app="cache.adapter.filesystem"
Expand Down Expand Up @@ -133,7 +135,9 @@ will create pool with service id of ``cache.[type]``
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<!--
Expand All @@ -143,6 +147,7 @@ will create pool with service id of ``cache.[type]``
default_memcached_provider: Service: cache.memcached
default_pdo_provider: Service: cache.pdo
-->
<!-- "directory" attribute is only used with cache.adapter.filesystem -->
<framework:cache directory="%kernel.cache_dir%/pools"
default_doctrine_provider="app.doctrine_cache"
default_psr6_provider="app.my_psr6_service"
Expand Down Expand Up @@ -204,7 +209,9 @@ You can also create more customized pools. All you need is an adapter:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:cache default_memcached_provider="memcached://localhost">
Expand Down Expand Up @@ -276,7 +283,9 @@ For advanced configurations it could sometimes be useful to use a pool as an ada
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:cache app="my_cache_pool">
Expand Down Expand Up @@ -354,7 +363,9 @@ and use that when configuring the pool.
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:cache>
Expand All @@ -364,6 +375,7 @@ and use that when configuring the pool.

<services>
<service id="app.my_custom_redis_provider" class="\Redis">
<factory class="Symfony\Component\Cache\Adapter\RedisAdapter" method="createConnection"/>
<argument>redis://localhost</argument>
<argument type="collection">
<argument key="retry_interval">2</argument>
Expand All @@ -376,6 +388,8 @@ and use that when configuring the pool.
.. code-block:: php

// app/config/config.php
use Symfony\Component\Cache\Adapter\RedisAdapter;

$container->loadFromExtension('framework', [
'cache' => [
'pools' => [
Expand All @@ -387,12 +401,14 @@ and use that when configuring the pool.
],
]);

$container->getDefinition('app.my_custom_redis_provider', \Redis::class)
$container->register('app.my_custom_redis_provider', \Redis::class)
->setFactory([RedisAdapter::class, 'createConnection'])
->addArgument('redis://localhost')
->addArgument([
'retry_interval' => 2,
'timeout' => 10
]);
])
;

Creating a Cache Chain
----------------------
Expand Down Expand Up @@ -448,7 +464,9 @@ Symfony stores the item automatically in all the missing pools.
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:cache>
Expand All @@ -474,6 +492,9 @@ Symfony stores the item automatically in all the missing pools.
.. code-block:: php

// app/config/config.php
use Symfony\Component\Cache\Adapter\ChainAdapter;
use Symfony\Component\DependencyInjection\Reference;

$container->loadFromExtension('framework', [
'cache' => [
'pools' => [
Expand All @@ -495,13 +516,14 @@ Symfony stores the item automatically in all the missing pools.
],
]);

$container->getDefinition('app.my_cache_chain_adapter', \Symfony\Component\Cache\Adapter\ChainAdapter::class)
$container->register('app.my_cache_chain_adapter', ChainAdapter::class)
->addArgument([
new Reference('cache.array'),
new Reference('cache.apcu'),
new Reference('cache.my_redis'),
])
->addArgument(31536000);
->addArgument(31536000)
;

.. note::

Expand Down
10 changes: 2 additions & 8 deletions configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The main configuration file is called ``config.yml``:

// Twig Configuration
$container->loadFromExtension('twig', [
'debug' => '%kernel.debug%',
'debug' => '%kernel.debug%',
'strict_variables' => '%kernel.debug%',
]);

Expand Down Expand Up @@ -196,14 +196,8 @@ can also load XML files or PHP files.
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xmlns:twig="http://symfony.com/schema/dic/twig"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd
http://symfony.com/schema/dic/twig
https://symfony.com/schema/dic/twig/twig-1.0.xsd">
https://symfony.com/schema/dic/services/services-1.0.xsd">

<imports>
<import resource="parameters.res" type="yml"/>
Expand Down
2 changes: 1 addition & 1 deletion configuration/environments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ this code and changing the environment string.

<doctrine:dbal logging="%kernel.debug%"/>

<!-- ... ->
</container>

.. code-block:: php
Expand All @@ -240,7 +241,6 @@ this code and changing the environment string.
'logging' => '%kernel.debug%',
// ...
],
// ...
]);

Selecting the Environment for Console Commands
Expand Down
59 changes: 35 additions & 24 deletions configuration/external_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ variable in your service container configuration, you can reference it using
https://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<doctrine:config>
<doctrine:dbal
host="%env(DATABASE_HOST)%"
/>
<doctrine:dbal host="%env(DATABASE_HOST)%"/>
</doctrine:config>

</container>
Expand Down Expand Up @@ -81,7 +79,8 @@ will be used whenever the corresponding environment variable is *not* found:
<?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 https://symfony.com/schema/dic/services/services-1.0.xsd">
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="database_host">%env(DATABASE_HOST)%</parameter>
Expand Down Expand Up @@ -160,7 +159,7 @@ turn the value of the ``HTTP_PORT`` env var into an integer:
# app/config/config.yml
framework:
router:
http_port: env(int:HTTP_PORT)
http_port: '%env(int:HTTP_PORT)%'

.. code-block:: xml

Expand Down Expand Up @@ -379,7 +378,7 @@ Symfony provides the following env var processors:
parameters:
env(HOST): '10.0.0.1'
sentry_host: '%env(HOST)%'
env(SENTRY_DSN): 'http://%sentry_host%/project'
env(SENTRY_DSN): 'https://%sentry_host%/project'
sentry:
dsn: '%env(resolve:SENTRY_DSN)%'

Expand All @@ -388,14 +387,15 @@ Symfony provides the following env var processors:
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:sentry="http://symfony.com/schema/dic/sentry"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="env(HOST)">10.0.0.1</parameter>
<parameter key="sentry_host">%env(HOST)%</parameter>
<parameter key="env(SENTRY_DSN)">http://%sentry_host%/project</parameter>
<parameter key="env(SENTRY_DSN)">https://%sentry_host%/project</parameter>
</parameters>

<sentry:config dsn="%env(resolve:SENTRY_DSN)%"/>
Expand All @@ -406,7 +406,7 @@ Symfony provides the following env var processors:
// app/config/config.php
$container->setParameter('env(HOST)', '10.0.0.1');
$container->setParameter('sentry_host', '%env(HOST)%');
$container->setParameter('env(SENTRY_DSN)', 'http://%sentry_host%/project');
$container->setParameter('env(SENTRY_DSN)', 'https://%sentry_host%/project');
$container->loadFromExtension('sentry', [
'dsn' => '%env(resolve:SENTRY_DSN)%',
]);
Expand All @@ -420,49 +420,59 @@ Symfony provides the following env var processors:

# app/config/config.yml
parameters:
env(AUTH_FILE): '../config/auth.json'
google:
auth: '%env(file:AUTH_FILE)%'
env(AUTH_FILE): '../auth.json'

services:
some_authenticator:
arguments:
$auth: '%env(file:AUTH_FILE)%'

.. code-block:: xml

<!-- app/config/config.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"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<parameters>
<parameter key="env(AUTH_FILE)">../config/auth.json</parameter>
<parameter key="env(AUTH_FILE)">../auth.json</parameter>
</parameters>

<google auth="%env(file:AUTH_FILE)%"/>
<services>
<service id="some_authenticator">
<argument key="$auth">"%env(file:AUTH_FILE)%"<argument/>
<service>
</services>
</container>

.. code-block:: php

// app/config/config.php
$container->setParameter('env(AUTH_FILE)', '../config/auth.json');
$container->loadFromExtension('google', [
'auth' => '%env(file:AUTH_FILE)%',
]);
$container->setParameter('env(AUTH_FILE)', __DIR__.'/../auth.json');

$container->register('some_authenticator')
->setArgument('$auth', '%env(file:AUTH_FILE)%')
;

It is also possible to combine any number of processors:

.. code-block:: yaml

parameters:
env(AUTH_FILE): "%kernel.project_dir%/config/auth.json"
google:
# 1. gets the value of the AUTH_FILE env var
# 2. replaces the values of any config param to get the config path
# 3. gets the content of the file stored in that path
# 4. JSON-decodes the content of the file and returns it
auth: '%env(json:file:resolve:AUTH_FILE)%'

services:
some_authenticator:
arguments:
# 1. gets the value of the AUTH_FILE env var
# 2. replaces the values of any config param to get the config path
# 3. gets the content of the file stored in that path
# 4. JSON-decodes the content of the file and returns it
$auth: '%env(json:file:resolve:AUTH_FILE)%'

Custom Environment Variable Processors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -550,3 +560,4 @@ the Symfony service container::
// app/config/parameters.php
include_once('/path/to/drupal/sites/default/settings.php');
$container->setParameter('drupal.database.url', $db_url);

6 changes: 5 additions & 1 deletion configuration/using_parameters_in_dic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ Now, examine the results to see this closely:

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:my-bundle="http://example.org/schema/dic/my_bundle">
xmlns:my-bundle="http://example.org/schema/dic/my_bundle"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://example.org/schema/dic/my_bundle
https://example.org/schema/dic/my_bundle/my_bundle-1.0.xsd">

<my-bundle:config logging="true"/>
<!-- true, as expected -->
Expand Down
9 changes: 5 additions & 4 deletions console/commands_as_services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,22 @@ Or set the ``command`` attribute on the ``console.command`` tag in your service
.. code-block:: yaml

services:
# ...

AppBundle\Command\SunshineCommand:
tags:
- { name: 'console.command', command: 'app:sunshine' }
# ...

.. code-block:: 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 https://symfony.com/schema/dic/services/services-1.0.xsd">
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<!-- ... -->

<service id="AppBundle\Command\SunshineCommand">
<tag name="console.command" command="app:sunshine"/>
Expand All @@ -124,8 +126,7 @@ Or set the ``command`` attribute on the ``console.command`` tag in your service

// ...

$container
->register(SunshineCommand::class)
$container->register(SunshineCommand::class)
->addTag('console.command', ['command' => 'app:sunshine'])
;

Expand Down
Loading