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

Commitacdf609

Browse files
committed
[ConfigBuilder] Replace all framework config
1 parentac05b01 commitacdf609

34 files changed

+1198
-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

‎configuration/env_var_processors.rst‎

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ processor to turn the value of the ``HTTP_PORT`` env var into an integer:
4444
..code-block::php
4545
4646
// config/packages/framework.php
47-
$container->loadFromExtension('framework', [
48-
'router' => [
49-
'http_port' => '%env(int:HTTP_PORT)%',
50-
],
51-
]);
47+
use Symfony\Config\FrameworkConfig;
48+
49+
return static function (FrameworkConfig $framework) {
50+
$framework->router()
51+
->httpPort('%env(int:HTTP_PORT)%')
52+
;
53+
};
5254
5355
Built-In Environment Variable Processors
5456
----------------------------------------
@@ -90,10 +92,13 @@ Symfony provides the following env var processors:
9092
..code-block::php
9193
9294
// config/packages/framework.php
93-
$container->setParameter('env(SECRET)', 'some_secret');
94-
$container->loadFromExtension('framework', [
95-
'secret' => '%env(string:SECRET)%',
96-
]);
95+
use Symfony\Component\DependencyInjection\ContainerBuilder;
96+
use Symfony\Config\FrameworkConfig;
97+
98+
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
99+
$container->setParameter('env(SECRET)', 'some_secret');
100+
$framework->secret('%env(string:SECRET)%');
101+
};
97102
98103
``env(bool:FOO)``
99104
Casts ``FOO`` to a bool (``true`` values are ``'true'``, ``'on'``, ``'yes'``
@@ -131,10 +136,13 @@ Symfony provides the following env var processors:
131136
..code-block::php
132137
133138
// config/packages/framework.php
134-
$container->setParameter('env(HTTP_METHOD_OVERRIDE)', 'true');
135-
$container->loadFromExtension('framework', [
136-
'http_method_override' => '%env(bool:HTTP_METHOD_OVERRIDE)%',
137-
]);
139+
use Symfony\Component\DependencyInjection\ContainerBuilder;
140+
use Symfony\Config\FrameworkConfig;
141+
142+
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
143+
$container->setParameter('env(HTTP_METHOD_OVERRIDE)', 'true');
144+
$framework->httpMethodOverride('%env(bool:HTTP_METHOD_OVERRIDE)%');
145+
};
138146
139147
``env(not:FOO)``
140148

@@ -269,10 +277,13 @@ Symfony provides the following env var processors:
269277
..code-block::php
270278
271279
// config/packages/framework.php
272-
$container->setParameter('env(TRUSTED_HOSTS)', '["10.0.0.1", "10.0.0.2"]');
273-
$container->loadFromExtension('framework', [
274-
'trusted_hosts' => '%env(json:TRUSTED_HOSTS)%',
275-
]);
280+
use Symfony\Component\DependencyInjection\ContainerBuilder;
281+
use Symfony\Config\FrameworkConfig;
282+
283+
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
284+
$container->setParameter('env(TRUSTED_HOSTS)', '["10.0.0.1", "10.0.0.2"]');
285+
$framework->trustedHosts('%env(json:TRUSTED_HOSTS)%');
286+
};
276287
277288
``env(resolve:FOO)``
278289
If the content of ``FOO`` includes container parameters (with the syntax
@@ -353,10 +364,13 @@ Symfony provides the following env var processors:
353364
..code-block::php
354365
355366
// config/packages/framework.php
356-
$container->setParameter('env(TRUSTED_HOSTS)', '10.0.0.1,10.0.0.2');
357-
$container->loadFromExtension('framework', [
358-
'trusted_hosts' => '%env(csv:TRUSTED_HOSTS)%',
359-
]);
367+
use Symfony\Component\DependencyInjection\ContainerBuilder;
368+
use Symfony\Config\FrameworkConfig;
369+
370+
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
371+
$container->setParameter('env(TRUSTED_HOSTS)', '10.0.0.1,10.0.0.2');
372+
$framework->trustedHosts('%env(csv:TRUSTED_HOSTS)%');
373+
};
360374
361375
``env(file:FOO)``
362376
Returns the contents of a file whose path is the value of the ``FOO`` env var:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp