1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Core\Concern; |
4: | |
5: | use Salient\Contract\Core\Normalisable; |
6: | use Salient\Contract\Core\NormaliserFactory; |
7: | use Salient\Utility\Str; |
8: | use Closure; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | trait HasNormaliser |
20: | { |
21: | |
22: | private static $Normaliser = []; |
23: | |
24: | |
25: | |
26: | |
27: | public static function getNormaliser(): Closure |
28: | { |
29: | return fn(string $name): string => |
30: | Str::snake($name); |
31: | } |
32: | |
33: | |
34: | |
35: | |
36: | final public static function normalise( |
37: | string $name, |
38: | bool $greedy = true, |
39: | string ...$hints |
40: | ): string { |
41: | $normaliser = self::$Normaliser[static::class] |
42: | ??= static::getNormaliser(); |
43: | |
44: | return $normaliser($name, $greedy, ...$hints); |
45: | } |
46: | } |
47: | |