Skip to content

Commit ca351b6

Browse files
committed
MC-41843: Passing config from DI
1 parent 2594b8e commit ca351b6

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

AdobeStockImage/Model/Storage/Save.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
use Magento\Framework\Filesystem\Driver\Https;
1717
use Magento\Framework\Filesystem\DriverInterface;
1818
use Magento\MediaGalleryApi\Api\IsPathExcludedInterface;
19+
use Magento\Framework\Exception\InputException;
1920

2021
/**
2122
* Save images to the file system
2223
*/
2324
class Save
2425
{
25-
private const MAX_LENGTH = 255;
2626
private const IMAGE_FILE_NAME_PATTERN = '#\.(jpg|jpeg|gif|png)$# i';
2727

2828
/**
@@ -40,16 +40,21 @@ class Save
4040
*/
4141
private $isPathExcluded;
4242

43+
private $maxFileLength;
44+
4345
/**
4446
* @param Filesystem $filesystem
4547
* @param Https $driver
4648
* @param IsPathExcludedInterface $isPathExcluded
49+
* @param $maxFileLength
4750
*/
4851
public function __construct(
4952
Filesystem $filesystem,
5053
Https $driver,
51-
IsPathExcludedInterface $isPathExcluded
54+
IsPathExcludedInterface $isPathExcluded,
55+
$maxFileLength
5256
) {
57+
$this->maxFileLength = $maxFileLength;
5358
$this->filesystem = $filesystem;
5459
$this->driver = $driver;
5560
$this->isPathExcluded = $isPathExcluded;
@@ -64,13 +69,13 @@ public function __construct(
6469
* @throws AlreadyExistsException
6570
* @throws FileSystemException
6671
* @throws LocalizedException
72+
* @throws InputException
6773
*/
6874
public function execute(string $imageUrl, string $destinationPath, bool $allowOverwrite = false): void
6975
{
70-
$maxFilenameLength = self::MAX_LENGTH;
71-
if (strlen($destinationPath) > $maxFilenameLength) {
72-
throw new LocalizedException(
73-
__('Destination path is too long; must be %1 characters or less', $maxFilenameLength)
76+
if (strlen($destinationPath) > $this->maxFileLength) {
77+
throw new InputException(
78+
__('Destination path is too long; must be %1 characters or less', $this->maxFileLength)
7479
);
7580
}
7681

AdobeStockImage/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<type name="Magento\AdobeStockImage\Model\Storage\Save">
3737
<arguments>
3838
<argument name="driver" xsi:type="object">Magento\Framework\Filesystem\Driver\Https</argument>
39+
<argument name="maxFileLength" xsi:type="number">255</argument>
3940
</arguments>
4041
</type>
4142
<type name="Magento\AdobeStockImage\Model\GetRelatedImages">

0 commit comments

Comments
 (0)