Skip to content

Commit

Permalink
[FrameworkBundle] Use WarmableAggregate to warm read-only artifacts…
Browse files Browse the repository at this point in the history
… in `build_dir`
  • Loading branch information
Okhoshi committed May 22, 2023
1 parent 9307f91 commit a575a7e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
6.3
---

* Use `WarmableAggregate` to warm read-only artifacts in `build_dir`
* Add `extra` option for `http_client.default_options` and `http_client.scoped_client`
* Add `DomCrawlerAssertionsTrait::assertSelectorCount(int $count, string $selector)`
* Allow to avoid `limit` definition in a RateLimiter configuration when using the `no_limit` policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* Generate all config builders.
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class ConfigBuilderCacheWarmer implements CacheWarmerInterface
class ConfigBuilderCacheWarmer implements WarmableInterface
{
private KernelInterface $kernel;
private ?LoggerInterface $logger;
Expand Down Expand Up @@ -76,9 +76,4 @@ private function dumpExtension(ExtensionInterface $extension, ConfigBuilderGener

$generator->build($configuration);
}

public function isOptional(): bool
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class UnusedTagsPass implements CompilerPassInterface
{
private const KNOWN_TAGS = [
'annotations.cached_reader',
'assets.package',
'asset_mapper.compiler',
'assets.package',
'auto_alias',
'cache.pool',
'cache.pool.clearer',
Expand Down Expand Up @@ -55,6 +55,7 @@ class UnusedTagsPass implements CompilerPassInterface
'form.type_guesser',
'html_sanitizer',
'http_client.client',
'kernel.build_warmer',
'kernel.cache_clearer',
'kernel.cache_warmer',
'kernel.event_listener',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Attribute\AsTargetedValueResolver;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\BuildWarmerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\BackedEnumValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\UidValueResolver;
Expand Down Expand Up @@ -610,6 +611,8 @@ public function load(array $configs, ContainerBuilder $container)
->addTag('form.type_extension');
$container->registerForAutoconfiguration(CacheClearerInterface::class)
->addTag('kernel.cache_clearer');
$container->registerForAutoconfiguration(BuildWarmerInterface::class)
->addTag('kernel.build_warmer');
$container->registerForAutoconfiguration(CacheWarmerInterface::class)
->addTag('kernel.cache_warmer');
$container->registerForAutoconfiguration(EventDispatcherInterface::class)
Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Symfony\Component\HttpFoundation\UrlHelper;
use Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableAggregate;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
use Symfony\Component\HttpKernel\EventListener\LocaleAwareListener;
Expand Down Expand Up @@ -124,6 +125,15 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
])
->alias(UrlHelper::class, 'url_helper')

->set('build_warmer', WarmableAggregate::class)
->public()
->args([
tagged_iterator('kernel.build_warmer'),
param('kernel.debug'),
sprintf('%s/%sDeprecations.log', param('kernel.build_dir'), param('kernel.container_class')),
])
->tag('container.no_preload')

->set('cache_warmer', CacheWarmerAggregate::class)
->public()
->args([
Expand Down Expand Up @@ -227,7 +237,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
])
->set('config_builder.warmer', ConfigBuilderCacheWarmer::class)
->args([service(KernelInterface::class), service('logger')->nullOnInvalid()])
->tag('kernel.cache_warmer')
->tag('kernel.build_warmer')

->set('clock', Clock::class)
->alias(ClockInterface::class, 'clock')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ public function testTagsPartialSearch()
$this->assertStringContainsString('Select one of the following tags to display its information', $tester->getDisplay());
$this->assertStringContainsString('[0] kernel.event_subscriber', $tester->getDisplay());
$this->assertStringContainsString('[1] kernel.locale_aware', $tester->getDisplay());
$this->assertStringContainsString('[2] kernel.cache_warmer', $tester->getDisplay());
$this->assertStringContainsString('[2] kernel.build_warmer', $tester->getDisplay());
$this->assertStringContainsString('[3] kernel.fragment_renderer', $tester->getDisplay());
$this->assertStringContainsString('[4] kernel.reset', $tester->getDisplay());
$this->assertStringContainsString('[5] kernel.cache_clearer', $tester->getDisplay());
$this->assertStringContainsString('[6] kernel.cache_warmer', $tester->getDisplay());
$this->assertStringContainsString('Symfony Container Services Tagged with "kernel.event_subscriber" Tag', $tester->getDisplay());
}

Expand Down

0 comments on commit a575a7e

Please sign in to comment.