SlugHelper
in package
Fast replacement of {@see Strings::webalize()} for hot paths (router translators).
Nette Strings::toAscii() creates \Transliterator::create() on every call, which is
costly for long category lists. This copy of the algorithm keeps one static Transliterator
per process and memoizes the result by the exact input, because the same href is converted
repeatedly within a request.
IMPORTANT: the output must stay bit-identical to Strings::webalize() because public URLs
are built from it. tests/Unit/Utils/Helpers/SlugHelperTest.php guards this; run it after
every nette/utils update. When the vendor algorithm changes, fix the copy here, not the test.
Table of Contents
Constants
- MEMO_LIMIT : mixed = 20000
- Memoization cap; protects long-running processes (cron, sitemap).
Properties
- $memo : array<string, string>
- $transliterator : Transliterator|null
Methods
- reset() : void
- Clears the memo and the shared `Transliterator`; for tests and long-running processes.
- toAscii() : string
- Copy of {@see Strings::toAscii()} with a shared `Transliterator`.
- webalize() : string
- pcreReplace() : string
- Behaves like Nette `Strings::pcre()`: a regex error throws instead of returning a silent null.
Constants
MEMO_LIMIT
Memoization cap; protects long-running processes (cron, sitemap).
private
mixed
MEMO_LIMIT
= 20000
Properties
$memo
private
static array<string, string>
$memo
= []
$transliterator
private
static Transliterator|null
$transliterator
= null
Methods
reset()
Clears the memo and the shared `Transliterator`; for tests and long-running processes.
public
static reset() : void
toAscii()
Copy of {@see Strings::toAscii()} with a shared `Transliterator`.
public
static toAscii(string $s) : string
Parameters
- $s : string
Return values
stringwebalize()
public
static webalize(string $s[, string|null $charlist = null ][, bool $lower = true ]) : string
Parameters
- $s : string
- $charlist : string|null = null
- $lower : bool = true
Return values
stringpcreReplace()
Behaves like Nette `Strings::pcre()`: a regex error throws instead of returning a silent null.
private
static pcreReplace(string $pattern, string $replacement, string $subject) : string
Parameters
- $pattern : string
- $replacement : string
- $subject : string