Skip to content

Commit 2b7fe41

Browse files
committed
Merge remote-tracking branch 'origin/MC-40689' into 2.4.3-develop-pr124
2 parents f614e0c + be2b22c commit 2b7fe41

File tree

1 file changed

+13
-25
lines changed
  • app/code/Magento/Customer/Model/Metadata/Form

1 file changed

+13
-25
lines changed

app/code/Magento/Customer/Model/Metadata/Form/File.php

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Exception\LocalizedException;
1515
use Magento\Framework\File\UploaderFactory;
1616
use Magento\Framework\Filesystem;
17+
use Magento\Framework\Filesystem\Io\File as IoFile;
1718

1819
/**
1920
* Processes files that are save for customer.
@@ -62,6 +63,11 @@ class File extends AbstractData
6263
*/
6364
protected $fileProcessorFactory;
6465

66+
/**
67+
* @var IoFile|null
68+
*/
69+
private $ioFile;
70+
6571
/**
6672
* Constructor
6773
*
@@ -77,6 +83,7 @@ class File extends AbstractData
7783
* @param Filesystem $fileSystem
7884
* @param UploaderFactory $uploaderFactory
7985
* @param \Magento\Customer\Model\FileProcessorFactory|null $fileProcessorFactory
86+
* @param IoFile|null $ioFile
8087
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8188
*/
8289
public function __construct(
@@ -91,7 +98,8 @@ public function __construct(
9198
\Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $fileValidator,
9299
Filesystem $fileSystem,
93100
UploaderFactory $uploaderFactory,
94-
\Magento\Customer\Model\FileProcessorFactory $fileProcessorFactory = null
101+
\Magento\Customer\Model\FileProcessorFactory $fileProcessorFactory = null,
102+
IoFile $ioFile = null
95103
) {
96104
$value = $this->prepareFileValue($value);
97105
parent::__construct($localeDate, $logger, $attribute, $localeResolver, $value, $entityTypeCode, $isAjax);
@@ -102,6 +110,8 @@ public function __construct(
102110
$this->fileProcessorFactory = $fileProcessorFactory ?: ObjectManager::getInstance()
103111
->get(FileProcessorFactory::class);
104112
$this->fileProcessor = $this->fileProcessorFactory->create(['entityTypeCode' => $this->_entityTypeCode]);
113+
$this->ioFile = $ioFile ?: ObjectManager::getInstance()
114+
->get(IoFile::class);
105115
}
106116

107117
/**
@@ -183,7 +193,7 @@ protected function _validateByRules($value)
183193
{
184194
$label = $value['name'];
185195
$rules = $this->getAttribute()->getValidationRules();
186-
$extension = $this->getFileExtension($value['name']);
196+
$extension = $this->ioFile->getPathInfo($value['name'])['extension'];
187197
$fileExtensions = ArrayObjectSearch::getArrayElementByName(
188198
$rules,
189199
'file_extensions'
@@ -221,28 +231,6 @@ protected function _validateByRules($value)
221231
return [];
222232
}
223233

224-
/**
225-
* Get file extension from the file if it exists, otherwise, get from filename.
226-
*
227-
* @param string $fileName
228-
* @return string
229-
*/
230-
private function getFileExtension(string $fileName): string
231-
{
232-
return pathinfo($fileName, PATHINFO_EXTENSION);
233-
}
234-
235-
/**
236-
* Get file basename from the file if it exists, otherwise, get from filename.
237-
*
238-
* @param string $fileName
239-
* @return string
240-
*/
241-
private function getFileBasename(string $fileName): string
242-
{
243-
return pathinfo($fileName, PATHINFO_BASENAME);
244-
}
245-
246234
/**
247235
* Helper function that checks if the file was uploaded.
248236
*
@@ -259,7 +247,7 @@ protected function _isUploadedFile($filename)
259247
}
260248

261249
// This case is required for file uploader UI component
262-
$temporaryFile = FileProcessor::TMP_DIR . '/' . $this->getFileBasename($filename);
250+
$temporaryFile = FileProcessor::TMP_DIR . '/' . $this->ioFile->getPathInfo($filename)['basename'];
263251
if ($this->fileProcessor->isExist($temporaryFile)) {
264252
return true;
265253
}

0 commit comments

Comments
 (0)