1616use Magento \Framework \Filesystem \Driver \Https ;
1717use Magento \Framework \Filesystem \DriverInterface ;
1818use Magento \MediaGalleryApi \Api \IsPathExcludedInterface ;
19+ use Magento \Framework \Exception \InputException ;
1920
2021/**
2122 * Save images to the file system
2223 */
2324class 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
0 commit comments