27 lines
688 B
PHP
27 lines
688 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\FileManager\Model\Config\Backend;
|
|
|
|
use Magento\Framework\App\Config\Value;
|
|
use Magento\Framework\Exception\LocalizedException;
|
|
|
|
class UploadPath extends Value
|
|
{
|
|
/**
|
|
* @throws LocalizedException
|
|
*/
|
|
public function beforeSave(): self
|
|
{
|
|
$path = trim(str_replace('\\', '/', (string) $this->getValue()), '/');
|
|
if (!preg_match('#^uploads(?:/[a-zA-Z0-9_-]+)*$#', $path)) {
|
|
throw new LocalizedException(
|
|
__('Upload Path must be "uploads" or a safe child directory of "uploads".')
|
|
);
|
|
}
|
|
$this->setValue($path);
|
|
|
|
return parent::beforeSave();
|
|
}
|
|
}
|