21
21
*/
22
22
class SaveImageInformation
23
23
{
24
- private const IMAGE_FILE_NAME_PATTERN = '#\.(jpg|jpeg|gif|png)$# i ' ;
25
-
26
24
/**
27
25
* @var IsPathExcludedInterface
28
26
*/
@@ -48,25 +46,33 @@ class SaveImageInformation
48
46
*/
49
47
private $ synchronizeFiles ;
50
48
49
+ /**
50
+ * @var string[]
51
+ */
52
+ private $ imageExtensions ;
53
+
51
54
/**
52
55
* @param Filesystem $filesystem
53
56
* @param LoggerInterface $log
54
57
* @param IsPathExcludedInterface $isPathExcluded
55
58
* @param SynchronizeFilesInterface $synchronizeFiles
56
59
* @param ConfigInterface $config
60
+ * @param array $imageExtensions
57
61
*/
58
62
public function __construct (
59
63
Filesystem $ filesystem ,
60
64
LoggerInterface $ log ,
61
65
IsPathExcludedInterface $ isPathExcluded ,
62
66
SynchronizeFilesInterface $ synchronizeFiles ,
63
- ConfigInterface $ config
67
+ ConfigInterface $ config ,
68
+ array $ imageExtensions
64
69
) {
65
70
$ this ->log = $ log ;
66
71
$ this ->isPathExcluded = $ isPathExcluded ;
67
72
$ this ->filesystem = $ filesystem ;
68
73
$ this ->synchronizeFiles = $ synchronizeFiles ;
69
74
$ this ->config = $ config ;
75
+ $ this ->imageExtensions = $ imageExtensions ;
70
76
}
71
77
72
78
/**
@@ -75,6 +81,7 @@ public function __construct(
75
81
* @param Uploader $subject
76
82
* @param array $result
77
83
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
84
+ * @return array
78
85
*/
79
86
public function afterSave (Uploader $ subject , array $ result ): array
80
87
{
@@ -103,7 +110,7 @@ private function isApplicable(string $path): bool
103
110
try {
104
111
return $ path
105
112
&& !$ this ->isPathExcluded ->execute ($ path )
106
- && preg_match (self :: IMAGE_FILE_NAME_PATTERN , $ path );
113
+ && preg_match (' #\.( ' . implode ( " | " , $ this -> imageExtensions ) . ' )$# i ' , $ path );
107
114
} catch (\Exception $ exception ) {
108
115
$ this ->log ->critical ($ exception );
109
116
return false ;
0 commit comments