@@ -209,7 +209,6 @@ class Uploader
209
209
* @param DriverPool|null $driverPool
210
210
* @param TargetDirectory|null $targetDirectory
211
211
* @param Filesystem|null $filesystem
212
- * @param LoggerInterface|null $logger
213
212
* @throws \DomainException
214
213
*/
215
214
public function __construct (
@@ -218,8 +217,7 @@ public function __construct(
218
217
DirectoryList $ directoryList = null ,
219
218
DriverPool $ driverPool = null ,
220
219
TargetDirectory $ targetDirectory = null ,
221
- Filesystem $ filesystem = null ,
222
- LoggerInterface $ logger = null
220
+ Filesystem $ filesystem = null
223
221
) {
224
222
$ this ->directoryList = $ directoryList ?: ObjectManager::getInstance ()->get (DirectoryList::class);
225
223
$ this ->targetDirectory = $ targetDirectory ?: ObjectManager::getInstance ()->get (TargetDirectory::class);
@@ -234,7 +232,6 @@ public function __construct(
234
232
}
235
233
$ this ->fileMime = $ fileMime ?: ObjectManager::getInstance ()->get (Mime::class);
236
234
$ this ->driverPool = $ driverPool ?: ObjectManager::getInstance ()->get (DriverPool::class);
237
- $ this ->logger = $ logger ?: ObjectManager::getInstance ()->get (LoggerInterface::class);
238
235
}
239
236
240
237
/**
@@ -326,7 +323,7 @@ private function validateDestination(string $destinationFolder): void
326
323
}
327
324
if ($ this ->_allowCreateFolders ) {
328
325
$ this ->createDestinationFolder ($ destinationFolder );
329
- } elseif (!$ this ->targetDirectory
326
+ } elseif (!$ this ->getTargetDirectory ()
330
327
->getDirectoryWrite (DirectoryList::ROOT )
331
328
->isWritable ($ destinationFolder )
332
329
) {
@@ -359,24 +356,66 @@ protected function _moveFile($tmpPath, $destPath)
359
356
$ rootCode = DirectoryList::PUB ;
360
357
361
358
try {
362
- if (strpos ($ destPath , $ this ->directoryList ->getPath ($ rootCode )) !== 0 ) {
359
+ if (strpos ($ destPath , $ this ->getDirectoryList () ->getPath ($ rootCode )) !== 0 ) {
363
360
$ rootCode = DirectoryList::ROOT ;
364
361
}
365
362
366
- $ destPath = str_replace ($ this ->directoryList ->getPath ($ rootCode ), '' , $ destPath );
367
- $ directory = $ this ->targetDirectory ->getDirectoryWrite ($ rootCode );
363
+ $ destPath = str_replace ($ this ->getDirectoryList () ->getPath ($ rootCode ), '' , $ destPath );
364
+ $ directory = $ this ->getTargetDirectory () ->getDirectoryWrite ($ rootCode );
368
365
369
366
return $ this ->getFileDriver ()->rename (
370
367
$ tmpPath ,
371
368
$ directory ->getAbsolutePath ($ destPath ),
372
369
$ directory ->getDriver ()
373
370
);
374
371
} catch (FileSystemException $ exception ) {
375
- $ this ->logger ->critical ($ exception ->getMessage ());
372
+ $ this ->getLogger () ->critical ($ exception ->getMessage ());
376
373
return false ;
377
374
}
378
375
}
379
376
377
+ /**
378
+ * Get logger instance.
379
+ *
380
+ * @deprecated
381
+ * @return LoggerInterface
382
+ */
383
+ private function getLogger (): LoggerInterface
384
+ {
385
+ if (!$ this ->logger ) {
386
+ $ this ->logger = ObjectManager::getInstance ()->get (LoggerInterface::class);
387
+ }
388
+ return $ this ->logger ;
389
+ }
390
+
391
+ /**
392
+ * Retrieves target directory.
393
+ *
394
+ * @return TargetDirectory
395
+ */
396
+ private function getTargetDirectory (): TargetDirectory
397
+ {
398
+ if (!isset ($ this ->targetDirectory )) {
399
+ $ this ->targetDirectory = ObjectManager::getInstance ()->get (TargetDirectory::class);
400
+ }
401
+
402
+ return $ this ->targetDirectory ;
403
+ }
404
+
405
+ /**
406
+ * Retrieves directory list.
407
+ *
408
+ * @return DirectoryList
409
+ */
410
+ private function getDirectoryList (): DirectoryList
411
+ {
412
+ if (!isset ($ this ->directoryList )) {
413
+ $ this ->directoryList = ObjectManager::getInstance ()->get (DirectoryList::class);
414
+ }
415
+
416
+ return $ this ->directoryList ;
417
+ }
418
+
380
419
/**
381
420
* Validate file before save
382
421
*
@@ -740,7 +779,7 @@ private function createDestinationFolder(string $destinationFolder)
740
779
$ destinationFolder = substr ($ destinationFolder , 0 , -1 );
741
780
}
742
781
743
- $ rootDirectory = $ this ->targetDirectory ->getDirectoryWrite (DirectoryList::ROOT );
782
+ $ rootDirectory = $ this ->getTargetDirectory () ->getDirectoryWrite (DirectoryList::ROOT );
744
783
745
784
if (!$ rootDirectory ->isDirectory ($ destinationFolder )) {
746
785
$ result = $ rootDirectory ->getDriver ()->createDirectory ($ destinationFolder );
@@ -809,8 +848,8 @@ public static function getDispersionPath($fileName)
809
848
$ dispersionPath = '/ ' . ('. ' == $ fileName [$ char ] ? '_ ' : $ fileName [$ char ]);
810
849
} else {
811
850
$ dispersionPath = self ::_addDirSeparator (
812
- $ dispersionPath
813
- ) . ('. ' == $ fileName [$ char ] ? '_ ' : $ fileName [$ char ]);
851
+ $ dispersionPath
852
+ ) . ('. ' == $ fileName [$ char ] ? '_ ' : $ fileName [$ char ]);
814
853
}
815
854
$ char ++;
816
855
}
0 commit comments