/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/AssetMapper/Compressor/ChainCompressor.php
50 строк
1 KB
Kévin Dunglas
[AssetMapper] add support for assets pre-compression
06 дек 2024, 16:38
06 дек 2024, 16:38
5fa3e92
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\AssetMapper\Compressor; use Psr\Log\LoggerInterface; /** * Calls multiple compressors in a chain. * * @author Kévin Dunglas <kevin@dunglas.dev> */ final class ChainCompressor implements CompressorInterface { /** * @param CompressorInterface[] $compressors */ public function __construct( private ?array $compressors = null, private readonly ?LoggerInterface $logger = null, ) { } public function compress(string $path): void { if (null === $this->compressors) { $this->compressors = []; foreach ([new BrotliCompressor(), new ZstandardCompressor(), new GzipCompressor()] as $compressor) { $unsupportedReason = $compressor->getUnsupportedReason(); if (null === $unsupportedReason) { $this->compressors[] = $compressor; } else { $this->logger?->warning($unsupportedReason); } } } foreach ($this->compressors as $compressor) { $compressor->compress($path); } } }