/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/AssetMapper/Path/LocalPublicAssetsFilesystem.php
65 строк
2 KB
Christian Flothmann
skip test if not supported compressors are available
09 янв 2025, 15:07
09 янв 2025, 15:07
8208c75
Код
Авторство
О чём код?
<?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\Path; use Symfony\Component\AssetMapper\Compressor\CompressorInterface; use Symfony\Component\Filesystem\Filesystem; class LocalPublicAssetsFilesystem implements PublicAssetsFilesystemInterface { private Filesystem $filesystem; /** * @param string[] $extensionsToCompress */ public function __construct( private readonly string $publicDir, private readonly ?CompressorInterface $compressor = null, private readonly array $extensionsToCompress = [], ) { $this->filesystem = new Filesystem(); } public function write(string $path, string $contents): void { $targetPath = $this->publicDir.'/'.ltrim($path, '/'); $this->filesystem->dumpFile($targetPath, $contents); $this->compress($targetPath); } public function copy(string $originPath, string $path): void { $targetPath = $this->publicDir.'/'.ltrim($path, '/'); $this->filesystem->copy($originPath, $targetPath, true); $this->compress($targetPath); } public function getDestinationPath(): string { return $this->publicDir; } private function compress(string $targetPath): void { foreach ($this->extensionsToCompress as $ext) { if (!str_ends_with($targetPath, ".$ext")) { continue; } $this->compressor?->compress($targetPath); return; } } }