@@ -36,75 +36,75 @@ |
||
36 | 36 | class Slugger implements SluggerInterface |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * Default Basic ID |
|
41 | - * |
|
42 | - * @var string |
|
43 | - * |
|
44 | - * @link http://userguide.icu-project.org/transforms/general#TOC-Basic-IDs |
|
45 | - */ |
|
46 | - protected const DEFAULT_BASIC_ID = 'Russian-Latin/BGN'; |
|
39 | + /** |
|
40 | + * Default Basic ID |
|
41 | + * |
|
42 | + * @var string |
|
43 | + * |
|
44 | + * @link http://userguide.icu-project.org/transforms/general#TOC-Basic-IDs |
|
45 | + */ |
|
46 | + protected const DEFAULT_BASIC_ID = 'Russian-Latin/BGN'; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Transliterator |
|
50 | - * |
|
51 | - * @var Transliterator |
|
52 | - */ |
|
53 | - protected $transliterator; |
|
48 | + /** |
|
49 | + * Transliterator |
|
50 | + * |
|
51 | + * @var Transliterator |
|
52 | + */ |
|
53 | + protected $transliterator; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Replacements |
|
57 | - * |
|
58 | - * @var array<string, string> |
|
59 | - */ |
|
60 | - protected $replacements = []; |
|
55 | + /** |
|
56 | + * Replacements |
|
57 | + * |
|
58 | + * @var array<string, string> |
|
59 | + */ |
|
60 | + protected $replacements = []; |
|
61 | 61 | |
62 | - /** |
|
63 | - * Constructor of the class |
|
64 | - * |
|
65 | - * @param string|null $basicId |
|
66 | - * @param array<string, string> $replacements |
|
67 | - * |
|
68 | - * @throws InvalidArgumentException |
|
69 | - * @throws UnableToCreateTransliteratorException |
|
70 | - */ |
|
71 | - public function __construct(?string $basicId = null, array $replacements = []) |
|
72 | - { |
|
73 | - // http://userguide.icu-project.org/transforms/general#TOC-Basic-IDs |
|
74 | - /** @var string */ |
|
75 | - $basicId = $basicId ?? static::DEFAULT_BASIC_ID; |
|
76 | - if (!in_array($basicId, Transliterator::listIDs(), true)) { |
|
77 | - throw new InvalidArgumentException('Unknown Basic ID'); |
|
78 | - } |
|
62 | + /** |
|
63 | + * Constructor of the class |
|
64 | + * |
|
65 | + * @param string|null $basicId |
|
66 | + * @param array<string, string> $replacements |
|
67 | + * |
|
68 | + * @throws InvalidArgumentException |
|
69 | + * @throws UnableToCreateTransliteratorException |
|
70 | + */ |
|
71 | + public function __construct(?string $basicId = null, array $replacements = []) |
|
72 | + { |
|
73 | + // http://userguide.icu-project.org/transforms/general#TOC-Basic-IDs |
|
74 | + /** @var string */ |
|
75 | + $basicId = $basicId ?? static::DEFAULT_BASIC_ID; |
|
76 | + if (!in_array($basicId, Transliterator::listIDs(), true)) { |
|
77 | + throw new InvalidArgumentException('Unknown Basic ID'); |
|
78 | + } |
|
79 | 79 | |
80 | - // http://userguide.icu-project.org/transforms/general#TOC-Compound-IDs |
|
81 | - $compoundIds = $basicId . '; Any-Latin; Latin-ASCII; Lower()'; |
|
82 | - $transliterator = Transliterator::create($compoundIds); |
|
83 | - if ($transliterator === null) { |
|
84 | - throw new UnableToCreateTransliteratorException('Unable to create transliterator'); |
|
85 | - } |
|
80 | + // http://userguide.icu-project.org/transforms/general#TOC-Compound-IDs |
|
81 | + $compoundIds = $basicId . '; Any-Latin; Latin-ASCII; Lower()'; |
|
82 | + $transliterator = Transliterator::create($compoundIds); |
|
83 | + if ($transliterator === null) { |
|
84 | + throw new UnableToCreateTransliteratorException('Unable to create transliterator'); |
|
85 | + } |
|
86 | 86 | |
87 | - $this->transliterator = $transliterator; |
|
88 | - $this->replacements = $replacements; |
|
89 | - } |
|
87 | + $this->transliterator = $transliterator; |
|
88 | + $this->replacements = $replacements; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * {@inheritdoc} |
|
93 | - * |
|
94 | - * @throws UnableToTransliterateException |
|
95 | - */ |
|
96 | - public function slugify(string $string, string $separator = '-') : string |
|
97 | - { |
|
98 | - $result = $this->transliterator->transliterate($string); |
|
99 | - if ($result === false) { |
|
100 | - throw new UnableToTransliterateException('Unable to transliterate'); |
|
101 | - } |
|
91 | + /** |
|
92 | + * {@inheritdoc} |
|
93 | + * |
|
94 | + * @throws UnableToTransliterateException |
|
95 | + */ |
|
96 | + public function slugify(string $string, string $separator = '-') : string |
|
97 | + { |
|
98 | + $result = $this->transliterator->transliterate($string); |
|
99 | + if ($result === false) { |
|
100 | + throw new UnableToTransliterateException('Unable to transliterate'); |
|
101 | + } |
|
102 | 102 | |
103 | - $result = strtr($result, $this->replacements); |
|
104 | - $result = str_replace(['"', "'"], '', $result); |
|
105 | - $result = preg_replace('/[^0-9A-Za-z]++/', $separator, $result); |
|
106 | - $result = trim($result, $separator); |
|
103 | + $result = strtr($result, $this->replacements); |
|
104 | + $result = str_replace(['"', "'"], '', $result); |
|
105 | + $result = preg_replace('/[^0-9A-Za-z]++/', $separator, $result); |
|
106 | + $result = trim($result, $separator); |
|
107 | 107 | |
108 | - return $result; |
|
109 | - } |
|
108 | + return $result; |
|
109 | + } |
|
110 | 110 | } |
@@ -19,13 +19,13 @@ |
||
19 | 19 | interface SluggerInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Slugifies the given string |
|
24 | - * |
|
25 | - * @param string $string |
|
26 | - * @param string $separator |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function slugify(string $string, string $separator) : string; |
|
22 | + /** |
|
23 | + * Slugifies the given string |
|
24 | + * |
|
25 | + * @param string $string |
|
26 | + * @param string $separator |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function slugify(string $string, string $separator) : string; |
|
31 | 31 | } |