Skip to content

Commit 62522ce

Browse files
author
Maxime Leclercq
committed
refactor(filter): use param to exclude file extensions
1 parent 1a1416e commit 62522ce

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Resources/config/services.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ parameters:
77
pdf: '%env(default:monsieurbiz_sylius_media_manager.default_max_file:resolve:MONSIEURBIZ_SYLIUS_MEDIA_MANAGER_MAX_FILE_SIZE_PDF)%'
88
favicon: '%env(default:monsieurbiz_sylius_media_manager.default_max_file:resolve:MONSIEURBIZ_SYLIUS_MEDIA_MANAGER_MAX_FILE_SIZE_FAVICON)%'
99
file: '%env(default:monsieurbiz_sylius_media_manager.default_max_file:resolve:MONSIEURBIZ_SYLIUS_MEDIA_MANAGER_MAX_FILE_SIZE_FILE)%'
10+
monsieurbiz_sylius_media_manager.liip_imagine.exclude_extensions:
11+
- 'svg'
12+
- 'ico'
1013

1114
services:
1215
_defaults:
@@ -48,3 +51,4 @@ services:
4851
arguments:
4952
$loaders: '%liip_imagine.loaders%'
5053
$publicDir: '%sylius_core.public_dir%'
54+
$excludeExtensions: '%monsieurbiz_sylius_media_manager.liip_imagine.exclude_extensions%'

src/Twig/Extension/FilterExtensionDecorator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class FilterExtensionDecorator extends BaseFilterExtension
2626
public function __construct(
2727
CacheManager $cache,
2828
array $loaders,
29-
string $publicDir
29+
string $publicDir,
30+
private array $excludeExtensions = ['svg', 'ico'],
3031
) {
3132
parent::__construct($cache);
3233
$this->loaders = $loaders;
@@ -62,6 +63,9 @@ public function filter(
6263

6364
private function canImageBeFiltered(string $path): bool
6465
{
65-
return !str_ends_with($path, '.svg') && !str_ends_with($path, '.ico');
66+
/** @var string $pathExtension */
67+
$pathExtension = pathinfo($path, \PATHINFO_EXTENSION);
68+
69+
return !\in_array($pathExtension, $this->excludeExtensions, true);
6670
}
6771
}

0 commit comments

Comments
 (0)