Core\Files: Optimize the filterName() method
This commit is contained in:
parent
2ddd7796b0
commit
5a3ad9d33e
1 changed files with 13 additions and 4 deletions
|
@ -15,6 +15,7 @@ use ForkBB\Core\File;
|
|||
use ForkBB\Core\Image;
|
||||
use ForkBB\Core\Image\DefaultDriver;
|
||||
use ForkBB\Core\Exceptions\FileException;
|
||||
use Transliterator;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
|
||||
|
@ -55,6 +56,11 @@ class Files
|
|||
*/
|
||||
protected array $tmpFiles = [];
|
||||
|
||||
/**
|
||||
* Для кэширования транслитератора
|
||||
*/
|
||||
protected Transliterator|false|null $transl = null;
|
||||
|
||||
/**
|
||||
* Список mime типов считающихся картинками
|
||||
*/
|
||||
|
@ -971,10 +977,13 @@ class Files
|
|||
*/
|
||||
public function filterName(string $name): string
|
||||
{
|
||||
$name = \transliterator_transliterate(
|
||||
'Any-Latin; Latin-ASCII; Lower()', // "Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; Lower();",
|
||||
$name
|
||||
);
|
||||
if (null === $this->transl) {
|
||||
$this->transl = Transliterator::create('Any-Latin;Latin-ASCII;Lower();') ?? false;
|
||||
}
|
||||
|
||||
if ($this->transl instanceof Transliterator) {
|
||||
$name = $this->transl->transliterate($name);
|
||||
}
|
||||
|
||||
$name = \trim(\preg_replace(['%[^\w]+%', '%_+%'], ['-', '_'], $name), '-_');
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue