Skip to content

Commit cd1739d

Browse files
ENGCOM-7955: #1713: Extract image extension from constant of SaveImageInformation to DI configuration #29399
- Merge Pull Request #29399 from jmonteros422/magento2-1:1713-extract-image-extension-from-constant-of-saveImageInformation-to-dI-configuration - Merged commits: 1. 9224699
2 parents 00f8a8c + 9224699 commit cd1739d

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

app/code/Magento/MediaGalleryIntegration/Plugin/SaveImageInformation.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
*/
2222
class SaveImageInformation
2323
{
24-
private const IMAGE_FILE_NAME_PATTERN = '#\.(jpg|jpeg|gif|png)$# i';
25-
2624
/**
2725
* @var IsPathExcludedInterface
2826
*/
@@ -48,25 +46,33 @@ class SaveImageInformation
4846
*/
4947
private $synchronizeFiles;
5048

49+
/**
50+
* @var string[]
51+
*/
52+
private $imageExtensions;
53+
5154
/**
5255
* @param Filesystem $filesystem
5356
* @param LoggerInterface $log
5457
* @param IsPathExcludedInterface $isPathExcluded
5558
* @param SynchronizeFilesInterface $synchronizeFiles
5659
* @param ConfigInterface $config
60+
* @param array $imageExtensions
5761
*/
5862
public function __construct(
5963
Filesystem $filesystem,
6064
LoggerInterface $log,
6165
IsPathExcludedInterface $isPathExcluded,
6266
SynchronizeFilesInterface $synchronizeFiles,
63-
ConfigInterface $config
67+
ConfigInterface $config,
68+
array $imageExtensions
6469
) {
6570
$this->log = $log;
6671
$this->isPathExcluded = $isPathExcluded;
6772
$this->filesystem = $filesystem;
6873
$this->synchronizeFiles = $synchronizeFiles;
6974
$this->config = $config;
75+
$this->imageExtensions = $imageExtensions;
7076
}
7177

7278
/**
@@ -75,6 +81,7 @@ public function __construct(
7581
* @param Uploader $subject
7682
* @param array $result
7783
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
84+
* @return array
7885
*/
7986
public function afterSave(Uploader $subject, array $result): array
8087
{
@@ -103,7 +110,7 @@ private function isApplicable(string $path): bool
103110
try {
104111
return $path
105112
&& !$this->isPathExcluded->execute($path)
106-
&& preg_match(self::IMAGE_FILE_NAME_PATTERN, $path);
113+
&& preg_match('#\.(' . implode("|", $this->imageExtensions) . ')$# i', $path);
107114
} catch (\Exception $exception) {
108115
$this->log->critical($exception);
109116
return false;

app/code/Magento/MediaGalleryIntegration/etc/adminhtml/di.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,14 @@
1414
<type name="Magento\Framework\File\Uploader">
1515
<plugin name="save_asset_image" type="Magento\MediaGalleryIntegration\Plugin\SaveImageInformation"/>
1616
</type>
17+
<type name="Magento\MediaGalleryIntegration\Plugin\SaveImageInformation">
18+
<arguments>
19+
<argument name="imageExtensions" xsi:type="array">
20+
<item name="jpg" xsi:type="string">jpg</item>
21+
<item name="jpeg" xsi:type="string">jpeg</item>
22+
<item name="gif" xsi:type="string">gif</item>
23+
<item name="png" xsi:type="string">png</item>
24+
</argument>
25+
</arguments>
26+
</type>
1727
</config>

0 commit comments

Comments
 (0)