Files
esun3d/app/code/Esun/FileManager/Model/Config.php
T
2026-09-15 10:35:56 +08:00

52 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\FileManager\Model;
use Esun\FileManager\Model\Security\FilePolicy;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
class Config
{
private const XML_PATH_ENABLED = 'filemanager/general/enabled';
private const XML_PATH_ALLOWED_EXTENSIONS = 'filemanager/general/allowed_extensions';
private const XML_PATH_MAX_FILE_SIZE = 'filemanager/general/max_file_size';
private const XML_PATH_UPLOAD_PATH = 'filemanager/general/upload_path';
public function __construct(private readonly ScopeConfigInterface $scopeConfig)
{
}
public function isEnabled(): bool
{
return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED, ScopeInterface::SCOPE_STORE);
}
/**
* @return string[]
*/
public function getAllowedExtensions(): array
{
$value = strtolower((string) $this->scopeConfig->getValue(self::XML_PATH_ALLOWED_EXTENSIONS));
$extensions = preg_split('/[\s,]+/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: [];
return array_values(array_intersect(
array_unique($extensions),
FilePolicy::getSupportedExtensions()
));
}
public function getMaximumFileSizeBytes(): int
{
$megabytes = (float) $this->scopeConfig->getValue(self::XML_PATH_MAX_FILE_SIZE);
return (int) round($megabytes * 1024 * 1024);
}
public function getUploadPath(): string
{
return trim((string) $this->scopeConfig->getValue(self::XML_PATH_UPLOAD_PATH), '/');
}
}