Skip to content

[ConfigBuilder] Replace all framework config #15269

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
Apr 30, 2021
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
21 changes: 12 additions & 9 deletions bundles/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ as integration of other related components:

.. code-block:: php

$container->loadFromExtension('framework', [
'form' => true,
]);
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->form()->enabled(true);
};

Using the Bundle Extension
--------------------------
Expand Down Expand Up @@ -81,12 +83,13 @@ can add some configuration that looks like this:
.. code-block:: php

// config/packages/acme_social.php
$container->loadFromExtension('acme_social', [
'twitter' => [
'client_id' => 123,
'client_secret' => 'your_secret',
],
]);
use Symfony\Config\AcmeSocialConfig;

return static function (AcmeSocialConfig $acmeSocial) {
$acmeSocial->twitter()
->clientId(123)
->clientSecret('your_secret');
};

The basic idea is that instead of having the user override individual
parameters, you let the user configure just a few, specifically created,
Expand Down
217 changes: 106 additions & 111 deletions cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ adapter (template) they use by using the ``app`` and ``system`` key like:
.. code-block:: php

// config/packages/cache.php
$container->loadFromExtension('framework', [
'cache' => [
'app' => 'cache.adapter.filesystem',
'system' => 'cache.adapter.system',
],
]);
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->cache()
->app('cache.adapter.filesystem')
->system('cache.adapter.system')
;
};


The Cache component comes with a series of adapters pre-configured:

Expand Down Expand Up @@ -165,23 +168,24 @@ will create pools with service IDs that follow the pattern ``cache.[type]``.
.. code-block:: php

// config/packages/cache.php
$container->loadFromExtension('framework', [
'cache' => [
// Only used with cache.adapter.filesystem
'directory' => '%kernel.cache_dir%/pools',
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->cache()
// Only used with cache.adapter.filesystem
->directory('%kernel.cache_dir%/pools')
// Service: cache.doctrine
'default_doctrine_provider' => 'app.doctrine_cache',
->defaultDoctrineProvider('app.doctrine_cache')
// Service: cache.psr6
'default_psr6_provider' => 'app.my_psr6_service',
->defaultPsr6Provider('app.my_psr6_service')
// Service: cache.redis
'default_redis_provider' => 'redis://localhost',
->defaultRedisProvider('redis://localhost')
// Service: cache.memcached
'default_memcached_provider' => 'memcached://localhost',
->defaultMemcachedProvider('memcached://localhost')
// Service: cache.pdo
'default_pdo_provider' => 'doctrine.dbal.default_connection',
],
]);
->defaultPdoProvider('doctrine.dbal.default_connection')
;
};

.. _cache-create-pools:

Expand Down Expand Up @@ -267,43 +271,36 @@ You can also create more customized pools:
.. code-block:: php

// config/packages/cache.php
$container->loadFromExtension('framework', [
'cache' => [
'default_memcached_provider' => 'memcached://localhost',
'pools' => [
// creates a "custom_thing.cache" service
// autowireable via "CacheInterface $customThingCache"
// uses the "app" cache configuration
'custom_thing.cache' => [
'adapter' => 'cache.app',
],

// creates a "my_cache_pool" service
// autowireable via "CacheInterface $myCachePool"
'my_cache_pool' => [
'adapter' => 'cache.adapter.filesystem',
],

// uses the default_memcached_provider from above
'acme.cache' => [
'adapter' => 'cache.adapter.memcached',
],

// control adapter's configuration
'foobar.cache' => [
'adapter' => 'cache.adapter.memcached',
'provider' => 'memcached://user:password@example.com',
],

// uses the "foobar.cache" pool as its backend but controls
// the lifetime and (like all pools) has a separate cache namespace
'short_cache' => [
'adapter' => 'foobar.cache',
'default_lifetime' => 60,
],
],
],
]);
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$cache = $framework->cache();
$cache->defaultMemcachedProvider('memcached://localhost');

// creates a "custom_thing.cache" service
// autowireable via "CacheInterface $customThingCache"
// uses the "app" cache configuration
$cache->pool('custom_thing.cache')
->adapters(['cache.app']);

// creates a "my_cache_pool" service
// autowireable via "CacheInterface $myCachePool"
$cache->pool('my_cache_pool')
->adapters(['cache.adapter.filesystem']);

// uses the default_memcached_provider from above
$cache->pool('acme.cache')
->adapters(['cache.adapter.memcached']);

// control adapter's configuration
$cache->pool('foobar.cache')
->adapters(['cache.adapter.memcached'])
->provider('memcached://user:password@example.com');

$cache->pool('short_cache')
->adapters(['foobar.cache'])
->defaultLifetime(60);
};

Each pool manages a set of independent cache keys: keys from different pools
*never* collide, even if they share the same backend. This is achieved by prefixing
Expand Down Expand Up @@ -442,26 +439,25 @@ and use that when configuring the pool.

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

$container->loadFromExtension('framework', [
'cache' => [
'pools' => [
'cache.my_redis' => [
'adapter' => 'cache.adapter.redis',
'provider' => 'app.my_custom_redis_provider',
],
],
],
]);

$container->register('app.my_custom_redis_provider', \Redis::class)
->setFactory([RedisAdapter::class, 'createConnection'])
->addArgument('redis://localhost')
->addArgument([
'retry_interval' => 2,
'timeout' => 10
])
;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Config\FrameworkConfig;

return static function (ContainerBuilder $container, FrameworkConfig $framework) {
$framework->cache()
->pool('cache.my_redis')
->adapters(['cache.adapter.redis'])
->provider('app.my_custom_redis_provider');


$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 @@ -521,20 +517,19 @@ Symfony stores the item automatically in all the missing pools.
.. code-block:: php

// config/packages/cache.php
$container->loadFromExtension('framework', [
'cache' => [
'pools' => [
'my_cache_pool' => [
'default_lifetime' => 31536000, // One year
'adapters' => [
'cache.adapter.array',
'cache.adapter.apcu',
['name' => 'cache.adapter.redis', 'provider' => 'redis://user:password@example.com'],
],
],
],
],
]);
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->cache()
->pool('my_cache_pool')
->defaultLifetime(31536000) // One year
->adapters([
'cache.adapter.array',
'cache.adapter.apcu',
['name' => 'cache.adapter.redis', 'provider' => 'redis://user:password@example.com'],
])
;
};

Using Cache Tags
----------------
Expand Down Expand Up @@ -613,16 +608,15 @@ to enable this feature. This could be added by using the following configuration
.. code-block:: php

// config/packages/cache.php
$container->loadFromExtension('framework', [
'cache' => [
'pools' => [
'my_cache_pool' => [
'adapter' => 'cache.adapter.redis',
'tags' => true,
],
],
],
]);
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->cache()
->pool('my_cache_pool')
->tags(true)
->adapters(['cache.adapter.redis'])
;
};

Tags are stored in the same pool by default. This is good in most scenarios. But
sometimes it might be better to store the tags in a different pool. That could be
Expand Down Expand Up @@ -663,19 +657,20 @@ achieved by specifying the adapter.
.. code-block:: php

// config/packages/cache.php
$container->loadFromExtension('framework', [
'cache' => [
'pools' => [
'my_cache_pool' => [
'adapter' => 'cache.adapter.redis',
'tags' => 'tag_pool',
],
'tag_pool' => [
'adapter' => 'cache.adapter.apcu',
],
],
],
]);
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->cache()
->pool('my_cache_pool')
->tags('tag_pool')
->adapters(['cache.adapter.redis'])
;

$framework->cache()
->pool('tag_pool')
->adapters(['cache.adapter.apcu'])
;
};

.. note::

Expand Down
Loading