Skip to content

Commit 87c3d5c

Browse files
committed
warm icons in asset-mapper's PreAssetsCompileEvent
1 parent bfe8eec commit 87c3d5c

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

src/Icons/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"symfony/twig-bundle": "^6.4|^7.0"
3333
},
3434
"require-dev": {
35+
"symfony/asset-mapper": "^6.4|^7.0",
3536
"symfony/console": "^6.4|^7.0",
3637
"symfony/http-client": "6.4|^7.0",
3738
"symfony/phpunit-bridge": "^6.3|^7.0",

src/Icons/config/asset_mapper.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent;
15+
use Symfony\UX\Icons\EventListener\WarmIconCacheOnAssetCompileListener;
16+
17+
return static function (ContainerConfigurator $container): void {
18+
$container->services()
19+
->set('.ux_icons.event_listener.warm_icon_cache_on_asset_compile', WarmIconCacheOnAssetCompileListener::class)
20+
->args([
21+
service('.ux_icons.cache_warmer'),
22+
])
23+
->tag('kernel.event_listener', [
24+
'event' => PreAssetsCompileEvent::class,
25+
'method' => '__invoke',
26+
])
27+
;
28+
};

src/Icons/src/DependencyInjection/UXIconsExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\UX\Icons\DependencyInjection;
1313

14+
use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent;
1415
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1516
use Symfony\Component\Config\Definition\ConfigurationInterface;
1617
use Symfony\Component\Config\FileLocator;
@@ -72,6 +73,10 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
7273
$loader->load('twig_component.php');
7374
}
7475

76+
if (class_exists(PreAssetsCompileEvent::class)) {
77+
$loader->load('asset_mapper.php');
78+
}
79+
7580
$container->getDefinition('.ux_icons.local_svg_icon_registry')
7681
->setArguments([
7782
$mergedConfig['icon_dir'],
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\Icons\EventListener;
13+
14+
use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent;
15+
use Symfony\UX\Icons\IconCacheWarmer;
16+
17+
/**
18+
* @author Kevin Bond <[email protected]>
19+
*
20+
* @internal
21+
*/
22+
final class WarmIconCacheOnAssetCompileListener
23+
{
24+
public function __construct(private IconCacheWarmer $warmer)
25+
{
26+
}
27+
28+
public function __invoke(PreAssetsCompileEvent $event): void
29+
{
30+
$event->getOutput()->writeln('Warming the icon cache...');
31+
32+
$this->warmer->warm();
33+
34+
$event->getOutput()->writeln('Icon cache warmed.');
35+
}
36+
}

0 commit comments

Comments
 (0)