@@ -145,29 +145,31 @@ class Uploader
145
145
*/
146
146
private $ filesystem ;
147
147
148
- /**
148
+ /**#@+
149
149
* File upload type (multiple or single)
150
150
*/
151
- public const SINGLE_STYLE = 0 ;
151
+ const SINGLE_STYLE = 0 ;
152
+
153
+ const MULTIPLE_STYLE = 1 ;
152
154
153
- public const MULTIPLE_STYLE = 1 ;
155
+ /**#@-*/
154
156
155
157
/**
156
158
* Temp file name empty code
157
159
*/
158
- public const TMP_NAME_EMPTY = 666 ;
160
+ const TMP_NAME_EMPTY = 666 ;
159
161
160
162
/**
161
163
* Maximum Image Width resolution in pixels. For image resizing on client side
162
164
* @deprecated @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxWidth()
163
165
*/
164
- public const MAX_IMAGE_WIDTH = 1920 ;
166
+ const MAX_IMAGE_WIDTH = 1920 ;
165
167
166
168
/**
167
169
* Maximum Image Height resolution in pixels. For image resizing on client side
168
170
* @deprecated @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxHeight()
169
171
*/
170
- public const MAX_IMAGE_HEIGHT = 1200 ;
172
+ const MAX_IMAGE_HEIGHT = 1200 ;
171
173
172
174
/**
173
175
* Resulting of uploaded file
@@ -206,7 +208,6 @@ class Uploader
206
208
* @param DriverPool|null $driverPool
207
209
* @param TargetDirectory|null $targetDirectory
208
210
* @param Filesystem|null $filesystem
209
- * @param LoggerInterface|null $logger
210
211
* @throws \DomainException
211
212
*/
212
213
public function __construct (
@@ -215,14 +216,12 @@ public function __construct(
215
216
DirectoryList $ directoryList = null ,
216
217
DriverPool $ driverPool = null ,
217
218
TargetDirectory $ targetDirectory = null ,
218
- Filesystem $ filesystem = null ,
219
- LoggerInterface $ logger = null
219
+ Filesystem $ filesystem = null
220
220
) {
221
221
$ this ->directoryList = $ directoryList ?: ObjectManager::getInstance ()->get (DirectoryList::class);
222
222
$ this ->targetDirectory = $ targetDirectory ?: ObjectManager::getInstance ()->get (TargetDirectory::class);
223
223
224
224
$ this ->filesystem = $ filesystem ?: ObjectManager::getInstance ()->get (FileSystem::class);
225
- $ this ->logger = $ logger ?: ObjectManager::getInstance ()->get (LoggerInterface::class);
226
225
$ this ->_setUploadFileId ($ fileId );
227
226
if (!file_exists ($ this ->_file ['tmp_name ' ])) {
228
227
$ code = empty ($ this ->_file ['tmp_name ' ]) ? self ::TMP_NAME_EMPTY : 0 ;
@@ -251,7 +250,7 @@ protected function _afterSave($result)
251
250
*
252
251
* @param string $destinationFolder
253
252
* @param string $newFileName
254
- * @return array|false
253
+ * @return array
255
254
* @throws \Exception
256
255
* @SuppressWarnings(PHPMD.NPathComplexity)
257
256
*/
@@ -323,7 +322,7 @@ private function validateDestination(string $destinationFolder): void
323
322
}
324
323
if ($ this ->_allowCreateFolders ) {
325
324
$ this ->createDestinationFolder ($ destinationFolder );
326
- } elseif (!$ this ->targetDirectory
325
+ } elseif (!$ this ->getTargetDirectory ()
327
326
->getDirectoryWrite (DirectoryList::ROOT )
328
327
->isWritable ($ destinationFolder )
329
328
) {
@@ -356,24 +355,66 @@ protected function _moveFile($tmpPath, $destPath)
356
355
$ rootCode = DirectoryList::PUB ;
357
356
358
357
try {
359
- if (strpos ($ destPath , $ this ->directoryList ->getPath ($ rootCode )) !== 0 ) {
358
+ if (strpos ($ destPath , $ this ->getDirectoryList () ->getPath ($ rootCode )) !== 0 ) {
360
359
$ rootCode = DirectoryList::ROOT ;
361
360
}
362
361
363
- $ destPath = str_replace ($ this ->directoryList ->getPath ($ rootCode ), '' , $ destPath );
364
- $ directory = $ this ->targetDirectory ->getDirectoryWrite ($ rootCode );
362
+ $ destPath = str_replace ($ this ->getDirectoryList () ->getPath ($ rootCode ), '' , $ destPath );
363
+ $ directory = $ this ->getTargetDirectory () ->getDirectoryWrite ($ rootCode );
365
364
366
365
return $ this ->getFileDriver ()->rename (
367
366
$ tmpPath ,
368
367
$ directory ->getAbsolutePath ($ destPath ),
369
368
$ directory ->getDriver ()
370
369
);
371
370
} catch (FileSystemException $ exception ) {
372
- $ this ->logger ->critical ($ exception ->getMessage ());
371
+ $ this ->getLogger () ->critical ($ exception ->getMessage ());
373
372
return false ;
374
373
}
375
374
}
376
375
376
+ /**
377
+ * Get logger instance.
378
+ *
379
+ * @deprecated
380
+ * @return LoggerInterface
381
+ */
382
+ private function getLogger (): LoggerInterface
383
+ {
384
+ if (!$ this ->logger ) {
385
+ $ this ->logger = ObjectManager::getInstance ()->get (LoggerInterface::class);
386
+ }
387
+ return $ this ->logger ;
388
+ }
389
+
390
+ /**
391
+ * Retrieves target directory.
392
+ *
393
+ * @return TargetDirectory
394
+ */
395
+ private function getTargetDirectory (): TargetDirectory
396
+ {
397
+ if (!isset ($ this ->targetDirectory )) {
398
+ $ this ->targetDirectory = ObjectManager::getInstance ()->get (TargetDirectory::class);
399
+ }
400
+
401
+ return $ this ->targetDirectory ;
402
+ }
403
+
404
+ /**
405
+ * Retrieves directory list.
406
+ *
407
+ * @return DirectoryList
408
+ */
409
+ private function getDirectoryList (): DirectoryList
410
+ {
411
+ if (!isset ($ this ->directoryList )) {
412
+ $ this ->directoryList = ObjectManager::getInstance ()->get (DirectoryList::class);
413
+ }
414
+
415
+ return $ this ->directoryList ;
416
+ }
417
+
377
418
/**
378
419
* Validate file before save
379
420
*
@@ -732,7 +773,7 @@ private function createDestinationFolder(string $destinationFolder)
732
773
$ destinationFolder = substr ($ destinationFolder , 0 , -1 );
733
774
}
734
775
735
- $ rootDirectory = $ this ->targetDirectory ->getDirectoryWrite (DirectoryList::ROOT );
776
+ $ rootDirectory = $ this ->getTargetDirectory () ->getDirectoryWrite (DirectoryList::ROOT );
736
777
737
778
if (!$ rootDirectory ->isDirectory ($ destinationFolder )) {
738
779
$ result = $ rootDirectory ->getDriver ()->createDirectory ($ destinationFolder );
@@ -753,11 +794,9 @@ private function createDestinationFolder(string $destinationFolder)
753
794
public static function getNewFileName ($ destinationFile )
754
795
{
755
796
/** @var Filesystem $fileSystem */
756
- // phpcs:ignore Magento2.PHP.AutogeneratedClassNotInConstructor
757
797
$ fileSystem = ObjectManager::getInstance ()->get (Filesystem::class);
758
798
$ local = $ fileSystem ->getDirectoryRead (DirectoryList::ROOT );
759
799
/** @var TargetDirectory $targetDirectory */
760
- // phpcs:ignore Magento2.PHP.AutogeneratedClassNotInConstructor
761
800
$ targetDirectory = ObjectManager::getInstance ()->get (TargetDirectory::class);
762
801
$ remote = $ targetDirectory ->getDirectoryRead (DirectoryList::ROOT );
763
802
0 commit comments