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

Commit15a5862

Browse files
committed
minor#15269 [ConfigBuilder] Replace all framework config (Nyholm)
This PR was squashed before being merged into the 5.3-dev branch.Discussion----------[ConfigBuilder] Replace all framework configThis PR will replace all framework configuration with the new ConfigBuilders.Commits-------e57adb9 [ConfigBuilder] Replace all framework config
2 parents2824979 +e57adb9 commit15a5862

34 files changed

+1204
-1155
lines changed

‎bundles/configuration.rst‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ as integration of other related components:
4040
4141
..code-block::php
4242
43-
$container->loadFromExtension('framework', [
44-
'form' => true,
45-
]);
43+
use Symfony\Config\FrameworkConfig;
44+
45+
return static function (FrameworkConfig $framework) {
46+
$framework->form()->enabled(true);
47+
};
4648
4749
Using the Bundle Extension
4850
--------------------------
@@ -81,12 +83,13 @@ can add some configuration that looks like this:
8183
..code-block::php
8284
8385
// config/packages/acme_social.php
84-
$container->loadFromExtension('acme_social', [
85-
'twitter' => [
86-
'client_id' => 123,
87-
'client_secret' => 'your_secret',
88-
],
89-
]);
86+
use Symfony\Config\AcmeSocialConfig;
87+
88+
return static function (AcmeSocialConfig $acmeSocial) {
89+
$acmeSocial->twitter()
90+
->clientId(123)
91+
->clientSecret('your_secret');
92+
};
9093
9194
The basic idea is that instead of having the user override individual
9295
parameters, you let the user configure just a few, specifically created,

‎cache.rst‎

Lines changed: 106 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,15 @@ adapter (template) they use by using the ``app`` and ``system`` key like:
8585
..code-block::php
8686
8787
// config/packages/cache.php
88-
$container->loadFromExtension('framework', [
89-
'cache' => [
90-
'app' => 'cache.adapter.filesystem',
91-
'system' => 'cache.adapter.system',
92-
],
93-
]);
88+
use Symfony\Config\FrameworkConfig;
89+
90+
return static function (FrameworkConfig $framework) {
91+
$framework->cache()
92+
->app('cache.adapter.filesystem')
93+
->system('cache.adapter.system')
94+
;
95+
};
96+
9497
9598
The Cache component comes with a series of adapters pre-configured:
9699

@@ -165,23 +168,24 @@ will create pools with service IDs that follow the pattern ``cache.[type]``.
165168
..code-block::php
166169
167170
// config/packages/cache.php
168-
$container->loadFromExtension('framework', [
169-
'cache' => [
170-
// Only used with cache.adapter.filesystem
171-
'directory' => '%kernel.cache_dir%/pools',
171+
use Symfony\Config\FrameworkConfig;
172172
173+
return static function (FrameworkConfig $framework) {
174+
$framework->cache()
175+
// Only used with cache.adapter.filesystem
176+
->directory('%kernel.cache_dir%/pools')
173177
// Service: cache.doctrine
174-
'default_doctrine_provider' =>'app.doctrine_cache',
178+
->defaultDoctrineProvider('app.doctrine_cache')
175179
// Service: cache.psr6
176-
'default_psr6_provider' =>'app.my_psr6_service',
180+
->defaultPsr6Provider('app.my_psr6_service')
177181
// Service: cache.redis
178-
'default_redis_provider' =>'redis://localhost',
182+
->defaultRedisProvider('redis://localhost')
179183
// Service: cache.memcached
180-
'default_memcached_provider' =>'memcached://localhost',
184+
->defaultMemcachedProvider('memcached://localhost')
181185
// Service: cache.pdo
182-
'default_pdo_provider' =>'doctrine.dbal.default_connection',
183-
],
184-
]);
186+
->defaultPdoProvider('doctrine.dbal.default_connection')
187+
;
188+
};
185189
186190
.. _cache-create-pools:
187191

@@ -267,43 +271,36 @@ You can also create more customized pools:
267271
..code-block::php
268272
269273
// config/packages/cache.php
270-
$container->loadFromExtension('framework', [
271-
'cache' => [
272-
'default_memcached_provider' => 'memcached://localhost',
273-
'pools' => [
274-
// creates a "custom_thing.cache" service
275-
// autowireable via "CacheInterface $customThingCache"
276-
// uses the "app" cache configuration
277-
'custom_thing.cache' => [
278-
'adapter' => 'cache.app',
279-
],
280-
281-
// creates a "my_cache_pool" service
282-
// autowireable via "CacheInterface $myCachePool"
283-
'my_cache_pool' => [
284-
'adapter' => 'cache.adapter.filesystem',
285-
],
286-
287-
// uses the default_memcached_provider from above
288-
'acme.cache' => [
289-
'adapter' => 'cache.adapter.memcached',
290-
],
291-
292-
// control adapter's configuration
293-
'foobar.cache' => [
294-
'adapter' => 'cache.adapter.memcached',
295-
'provider' => 'memcached://user:password@example.com',
296-
],
297-
298-
// uses the "foobar.cache" pool as its backend but controls
299-
// the lifetime and (like all pools) has a separate cache namespace
300-
'short_cache' => [
301-
'adapter' => 'foobar.cache',
302-
'default_lifetime' => 60,
303-
],
304-
],
305-
],
306-
]);
274+
use Symfony\Config\FrameworkConfig;
275+
276+
return static function (FrameworkConfig $framework) {
277+
$cache = $framework->cache();
278+
$cache->defaultMemcachedProvider('memcached://localhost');
279+
280+
// creates a "custom_thing.cache" service
281+
// autowireable via "CacheInterface $customThingCache"
282+
// uses the "app" cache configuration
283+
$cache->pool('custom_thing.cache')
284+
->adapters(['cache.app']);
285+
286+
// creates a "my_cache_pool" service
287+
// autowireable via "CacheInterface $myCachePool"
288+
$cache->pool('my_cache_pool')
289+
->adapters(['cache.adapter.filesystem']);
290+
291+
// uses the default_memcached_provider from above
292+
$cache->pool('acme.cache')
293+
->adapters(['cache.adapter.memcached']);
294+
295+
// control adapter's configuration
296+
$cache->pool('foobar.cache')
297+
->adapters(['cache.adapter.memcached'])
298+
->provider('memcached://user:password@example.com');
299+
300+
$cache->pool('short_cache')
301+
->adapters(['foobar.cache'])
302+
->defaultLifetime(60);
303+
};
307304
308305
Each pool manages a set of independent cache keys: keys from different pools
309306
*never* collide, even if they share the same backend. This is achieved by prefixing
@@ -442,26 +439,25 @@ and use that when configuring the pool.
442439
443440
// config/packages/cache.php
444441
use Symfony\Component\Cache\Adapter\RedisAdapter;
445-
446-
$container->loadFromExtension('framework', [
447-
'cache' => [
448-
'pools' => [
449-
'cache.my_redis' => [
450-
'adapter' => 'cache.adapter.redis',
451-
'provider' => 'app.my_custom_redis_provider',
452-
],
453-
],
454-
],
455-
]);
456-
457-
$container->register('app.my_custom_redis_provider', \Redis::class)
458-
->setFactory([RedisAdapter::class, 'createConnection'])
459-
->addArgument('redis://localhost')
460-
->addArgument([
461-
'retry_interval' => 2,
462-
'timeout' => 10
463-
])
464-
;
442+
use Symfony\Component\DependencyInjection\ContainerBuilder;
443+
use Symfony\Config\FrameworkConfig;
444+
445+
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
446+
$framework->cache()
447+
->pool('cache.my_redis')
448+
->adapters(['cache.adapter.redis'])
449+
->provider('app.my_custom_redis_provider');
450+
451+
452+
$container->register('app.my_custom_redis_provider', \Redis::class)
453+
->setFactory([RedisAdapter::class, 'createConnection'])
454+
->addArgument('redis://localhost')
455+
->addArgument([
456+
'retry_interval' => 2,
457+
'timeout' => 10
458+
])
459+
;
460+
};
465461
466462
Creating a Cache Chain
467463
----------------------
@@ -521,20 +517,19 @@ Symfony stores the item automatically in all the missing pools.
521517
..code-block::php
522518
523519
// config/packages/cache.php
524-
$container->loadFromExtension('framework', [
525-
'cache' => [
526-
'pools' => [
527-
'my_cache_pool' => [
528-
'default_lifetime' => 31536000, // One year
529-
'adapters' => [
530-
'cache.adapter.array',
531-
'cache.adapter.apcu',
532-
['name' => 'cache.adapter.redis', 'provider' => 'redis://user:password@example.com'],
533-
],
534-
],
535-
],
536-
],
537-
]);
520+
use Symfony\Config\FrameworkConfig;
521+
522+
return static function (FrameworkConfig $framework) {
523+
$framework->cache()
524+
->pool('my_cache_pool')
525+
->defaultLifetime(31536000) // One year
526+
->adapters([
527+
'cache.adapter.array',
528+
'cache.adapter.apcu',
529+
['name' => 'cache.adapter.redis', 'provider' => 'redis://user:password@example.com'],
530+
])
531+
;
532+
};
538533
539534
Using Cache Tags
540535
----------------
@@ -613,16 +608,15 @@ to enable this feature. This could be added by using the following configuration
613608
..code-block::php
614609
615610
// config/packages/cache.php
616-
$container->loadFromExtension('framework', [
617-
'cache' => [
618-
'pools' => [
619-
'my_cache_pool' => [
620-
'adapter' => 'cache.adapter.redis',
621-
'tags' => true,
622-
],
623-
],
624-
],
625-
]);
611+
use Symfony\Config\FrameworkConfig;
612+
613+
return static function (FrameworkConfig $framework) {
614+
$framework->cache()
615+
->pool('my_cache_pool')
616+
->tags(true)
617+
->adapters(['cache.adapter.redis'])
618+
;
619+
};
626620
627621
Tags are stored in the same pool by default. This is good in most scenarios. But
628622
sometimes it might be better to store the tags in a different pool. That could be
@@ -663,19 +657,20 @@ achieved by specifying the adapter.
663657
..code-block::php
664658
665659
// config/packages/cache.php
666-
$container->loadFromExtension('framework', [
667-
'cache' => [
668-
'pools' => [
669-
'my_cache_pool' => [
670-
'adapter' => 'cache.adapter.redis',
671-
'tags' => 'tag_pool',
672-
],
673-
'tag_pool' => [
674-
'adapter' => 'cache.adapter.apcu',
675-
],
676-
],
677-
],
678-
]);
660+
use Symfony\Config\FrameworkConfig;
661+
662+
return static function (FrameworkConfig $framework) {
663+
$framework->cache()
664+
->pool('my_cache_pool')
665+
->tags('tag_pool')
666+
->adapters(['cache.adapter.redis'])
667+
;
668+
669+
$framework->cache()
670+
->pool('tag_pool')
671+
->adapters(['cache.adapter.apcu'])
672+
;
673+
};
679674
680675
..note::
681676

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp