@@ -173,11 +173,13 @@ class Uploader
173
173
*
174
174
* @param string|array $fileId
175
175
* @param \Magento\Framework\File\Mime|null $fileMime
176
+ * @param DirectoryList|null $directoryList
176
177
* @throws \DomainException
177
178
*/
178
179
public function __construct (
179
180
$ fileId ,
180
- Mime $ fileMime = null
181
+ Mime $ fileMime = null ,
182
+ DirectoryList $ directoryList = null
181
183
) {
182
184
$ this ->_setUploadFileId ($ fileId );
183
185
if (!file_exists ($ this ->_file ['tmp_name ' ])) {
@@ -187,6 +189,8 @@ public function __construct(
187
189
$ this ->_fileExists = true ;
188
190
}
189
191
$ this ->fileMime = $ fileMime ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (Mime::class);
192
+ $ this ->directoryList = $ directoryList ?: \Magento \Framework \App \ObjectManager::getInstance ()
193
+ ->get (DirectoryList::class);
190
194
}
191
195
192
196
/**
@@ -610,14 +614,14 @@ private function validateFileId(array $fileId)
610
614
if (preg_match ('/\.\.( \\\|\/)/ ' , $ tmpName ) !== 1 ) {
611
615
$ allowedFolders = [
612
616
sys_get_temp_dir (),
613
- $ this ->getDirectoryList () ->getPath (DirectoryList::MEDIA ),
614
- $ this ->getDirectoryList () ->getPath (DirectoryList::VAR_DIR ),
615
- $ this ->getDirectoryList () ->getPath (DirectoryList::TMP ),
616
- $ this ->getDirectoryList () ->getPath (DirectoryList::UPLOAD ),
617
+ $ this ->directoryList ->getPath (DirectoryList::MEDIA ),
618
+ $ this ->directoryList ->getPath (DirectoryList::VAR_DIR ),
619
+ $ this ->directoryList ->getPath (DirectoryList::TMP ),
620
+ $ this ->directoryList ->getPath (DirectoryList::UPLOAD ),
617
621
];
618
622
619
623
$ disallowedFolders = [
620
- $ this ->getDirectoryList () ->getPath (DirectoryList::LOG ),
624
+ $ this ->directoryList ->getPath (DirectoryList::LOG ),
621
625
];
622
626
623
627
foreach ($ allowedFolders as $ allowedFolder ) {
@@ -643,19 +647,6 @@ private function validateFileId(array $fileId)
643
647
}
644
648
}
645
649
646
- /**
647
- * @return DirectoryList
648
- */
649
- private function getDirectoryList (): DirectoryList
650
- {
651
- if ($ this ->directoryList === null ) {
652
- $ this ->directoryList = \Magento \Framework \App \ObjectManager::getInstance ()
653
- ->get (DirectoryList::class);
654
- }
655
-
656
- return $ this ->directoryList ;
657
- }
658
-
659
650
/**
660
651
* Create destination folder
661
652
*
0 commit comments