1 | <?php namespace Tamtamchik\NameCase; |
||
6 | class Formatter |
||
7 | { |
||
8 | // Default options. |
||
9 | private static $options = [ |
||
10 | 'lazy' => true, |
||
11 | 'irish' => true, |
||
12 | 'spanish' => true, |
||
13 | ]; |
||
14 | |||
15 | // Irish exceptions. |
||
16 | private static $exceptions = [ |
||
17 | '\bMacEdo' => 'Macedo', |
||
18 | '\bMacEvicius' => 'Macevicius', |
||
19 | '\bMacHado' => 'Machado', |
||
20 | '\bMacHar' => 'Machar', |
||
21 | '\bMacHin' => 'Machin', |
||
22 | '\bMacHlin' => 'Machlin', |
||
23 | '\bMacIas' => 'Macias', |
||
24 | '\bMacIulis' => 'Maciulis', |
||
25 | '\bMacKie' => 'Mackie', |
||
26 | '\bMacKle' => 'Mackle', |
||
27 | '\bMacKlin' => 'Macklin', |
||
28 | '\bMacKmin' => 'Mackmin', |
||
29 | '\bMacQuarie' => 'Macquarie', |
||
30 | ]; |
||
31 | |||
32 | // General replacements. |
||
33 | private static $replacements = [ |
||
34 | '\bAl(?=\s+\w)' => 'al', // al Arabic or forename Al. |
||
35 | '\b(Bin|Binti|Binte)\b' => 'bin', // bin, binti, binte Arabic |
||
36 | '\bAp\b' => 'ap', // ap Welsh. |
||
37 | '\bBen(?=\s+\w)' => 'ben', // ben Hebrew or forename Ben. |
||
38 | '\bDell([ae])\b' => 'dell\1', // della and delle Italian. |
||
39 | '\bD([aeiou])\b' => 'd\1', // da, de, di Italian; du French; do Brasil |
||
40 | '\bD([ao]s)\b' => 'd\1', // das, dos Brasileiros |
||
41 | '\bDe([lr])\b' => 'de\1', // del Italian; der Dutch/Flemish. |
||
42 | '\bEl\b' => 'el', // el Greek or El Spanish. |
||
43 | '\bLa\b' => 'la', // la French or La Spanish. |
||
44 | '\bL([eo])\b' => 'l\1', // lo Italian; le French. |
||
45 | '\bVan(?=\s+\w)' => 'van', // van German or forename Van. |
||
46 | '\bVon\b' => 'von', // von Dutch/Flemish |
||
47 | ]; |
||
48 | |||
49 | // Spanish conjunctions. |
||
50 | private static $conjunctions = ["Y", "E", "I"]; |
||
51 | |||
52 | // Roman letters regexp. |
||
53 | private static $romanRegex = '\b((?:[Xx]{1,3}|[Xx][Ll]|[Ll][Xx]{0,3})?(?:[Ii]{1,3}|[Ii][VvXx]|[Vv][Ii]{0,3})?)\b'; |
||
54 | |||
55 | 3 | public function __construct(array $options = []) |
|
59 | |||
60 | /** |
||
61 | * Main function for NameCase. |
||
62 | * |
||
63 | * @param string $string |
||
64 | * @param array $options |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | 12 | public static function nameCase($string = '', array $options = []) |
|
89 | |||
90 | /** |
||
91 | * Capitalize first letters. |
||
92 | * |
||
93 | * @param string $string |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 12 | private static function capitalize($string) |
|
112 | |||
113 | /** |
||
114 | * Skip if string is mixed case. |
||
115 | * |
||
116 | * @param string $string |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | 12 | private static function skipMixed($string) |
|
127 | |||
128 | /** |
||
129 | * Update for Irish names. |
||
130 | * |
||
131 | * @param string $string |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | 12 | private static function updateIrish($string) |
|
145 | |||
146 | /** |
||
147 | * Fix Spanish conjunctions. |
||
148 | * |
||
149 | * @param string $string |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | 12 | private static function fixConjunction($string) |
|
163 | |||
164 | /** |
||
165 | * Fix roman numeral names. |
||
166 | * |
||
167 | * @param string $string |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | 12 | private static function updateRoman($string) |
|
177 | |||
178 | /** |
||
179 | * Updates irish Mac & Mc. |
||
180 | * |
||
181 | * @param string $string |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | private static function updateMac($string) |
||
198 | } |
||
199 |