|
@@ -1,575 +0,0 @@
|
1
|
|
-<?php
|
2
|
|
-/**
|
3
|
|
- * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
4
|
|
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
5
|
|
- *
|
6
|
|
- * Licensed under The MIT License
|
7
|
|
- * For full copyright and license information, please see the LICENSE.txt
|
8
|
|
- * Redistributions of files must retain the above copyright notice.
|
9
|
|
- *
|
10
|
|
- * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
11
|
|
- * @link http://cakephp.org CakePHP(tm) Project
|
12
|
|
- * @package Cake.Utility
|
13
|
|
- * @since CakePHP(tm) v 0.2.9
|
14
|
|
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
|
15
|
|
- */
|
16
|
|
-
|
17
|
|
-/**
|
18
|
|
- * Pluralize and singularize English words.
|
19
|
|
- *
|
20
|
|
- * Inflector pluralizes and singularizes English nouns.
|
21
|
|
- * Used by CakePHP's naming conventions throughout the framework.
|
22
|
|
- *
|
23
|
|
- * @package Cake.Utility
|
24
|
|
- * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html
|
25
|
|
- */
|
26
|
|
-class Inflector {
|
27
|
|
-
|
28
|
|
-/**
|
29
|
|
- * Plural inflector rules
|
30
|
|
- *
|
31
|
|
- * @var array
|
32
|
|
- */
|
33
|
|
- protected static $_plural = array(
|
34
|
|
- 'rules' => array(
|
35
|
|
- '/(s)tatus$/i' => '\1tatuses',
|
36
|
|
- '/(quiz)$/i' => '\1zes',
|
37
|
|
- '/^(ox)$/i' => '\1\2en',
|
38
|
|
- '/([m|l])ouse$/i' => '\1ice',
|
39
|
|
- '/(matr|vert|ind)(ix|ex)$/i' => '\1ices',
|
40
|
|
- '/(x|ch|ss|sh)$/i' => '\1es',
|
41
|
|
- '/([^aeiouy]|qu)y$/i' => '\1ies',
|
42
|
|
- '/(hive)$/i' => '\1s',
|
43
|
|
- '/(?:([^f])fe|([lre])f)$/i' => '\1\2ves',
|
44
|
|
- '/sis$/i' => 'ses',
|
45
|
|
- '/([ti])um$/i' => '\1a',
|
46
|
|
- '/(p)erson$/i' => '\1eople',
|
47
|
|
- '/(?<!u)(m)an$/i' => '\1en',
|
48
|
|
- '/(c)hild$/i' => '\1hildren',
|
49
|
|
- '/(buffal|tomat)o$/i' => '\1\2oes',
|
50
|
|
- '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i',
|
51
|
|
- '/us$/i' => 'uses',
|
52
|
|
- '/(alias)$/i' => '\1es',
|
53
|
|
- '/(ax|cris|test)is$/i' => '\1es',
|
54
|
|
- '/s$/' => 's',
|
55
|
|
- '/^$/' => '',
|
56
|
|
- '/$/' => 's',
|
57
|
|
- ),
|
58
|
|
- 'uninflected' => array(
|
59
|
|
- '.*[nrlm]ese',
|
60
|
|
- '.*data',
|
61
|
|
- '.*deer',
|
62
|
|
- '.*fish',
|
63
|
|
- '.*measles',
|
64
|
|
- '.*ois',
|
65
|
|
- '.*pox',
|
66
|
|
- '.*sheep',
|
67
|
|
- 'people',
|
68
|
|
- 'feedback',
|
69
|
|
- 'stadia'
|
70
|
|
- ),
|
71
|
|
- 'irregular' => array(
|
72
|
|
- 'atlas' => 'atlases',
|
73
|
|
- 'beef' => 'beefs',
|
74
|
|
- 'brief' => 'briefs',
|
75
|
|
- 'brother' => 'brothers',
|
76
|
|
- 'cafe' => 'cafes',
|
77
|
|
- 'child' => 'children',
|
78
|
|
- 'cookie' => 'cookies',
|
79
|
|
- 'corpus' => 'corpuses',
|
80
|
|
- 'cow' => 'cows',
|
81
|
|
- 'criterion' => 'criteria',
|
82
|
|
- 'ganglion' => 'ganglions',
|
83
|
|
- 'genie' => 'genies',
|
84
|
|
- 'genus' => 'genera',
|
85
|
|
- 'graffito' => 'graffiti',
|
86
|
|
- 'hoof' => 'hoofs',
|
87
|
|
- 'loaf' => 'loaves',
|
88
|
|
- 'man' => 'men',
|
89
|
|
- 'money' => 'monies',
|
90
|
|
- 'mongoose' => 'mongooses',
|
91
|
|
- 'move' => 'moves',
|
92
|
|
- 'mythos' => 'mythoi',
|
93
|
|
- 'niche' => 'niches',
|
94
|
|
- 'numen' => 'numina',
|
95
|
|
- 'occiput' => 'occiputs',
|
96
|
|
- 'octopus' => 'octopuses',
|
97
|
|
- 'opus' => 'opuses',
|
98
|
|
- 'ox' => 'oxen',
|
99
|
|
- 'penis' => 'penises',
|
100
|
|
- 'person' => 'people',
|
101
|
|
- 'sex' => 'sexes',
|
102
|
|
- 'soliloquy' => 'soliloquies',
|
103
|
|
- 'testis' => 'testes',
|
104
|
|
- 'trilby' => 'trilbys',
|
105
|
|
- 'turf' => 'turfs',
|
106
|
|
- 'potato' => 'potatoes',
|
107
|
|
- 'hero' => 'heroes',
|
108
|
|
- 'tooth' => 'teeth',
|
109
|
|
- 'goose' => 'geese',
|
110
|
|
- 'foot' => 'feet'
|
111
|
|
- )
|
112
|
|
- );
|
113
|
|
-
|
114
|
|
-/**
|
115
|
|
- * Singular inflector rules
|
116
|
|
- *
|
117
|
|
- * @var array
|
118
|
|
- */
|
119
|
|
- protected static $_singular = array(
|
120
|
|
- 'rules' => array(
|
121
|
|
- '/(s)tatuses$/i' => '\1\2tatus',
|
122
|
|
- '/^(.*)(menu)s$/i' => '\1\2',
|
123
|
|
- '/(quiz)zes$/i' => '\\1',
|
124
|
|
- '/(matr)ices$/i' => '\1ix',
|
125
|
|
- '/(vert|ind)ices$/i' => '\1ex',
|
126
|
|
- '/^(ox)en/i' => '\1',
|
127
|
|
- '/(alias)(es)*$/i' => '\1',
|
128
|
|
- '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us',
|
129
|
|
- '/([ftw]ax)es/i' => '\1',
|
130
|
|
- '/(cris|ax|test)es$/i' => '\1is',
|
131
|
|
- '/(shoe)s$/i' => '\1',
|
132
|
|
- '/(o)es$/i' => '\1',
|
133
|
|
- '/ouses$/' => 'ouse',
|
134
|
|
- '/([^a])uses$/' => '\1us',
|
135
|
|
- '/([m|l])ice$/i' => '\1ouse',
|
136
|
|
- '/(x|ch|ss|sh)es$/i' => '\1',
|
137
|
|
- '/(m)ovies$/i' => '\1\2ovie',
|
138
|
|
- '/(s)eries$/i' => '\1\2eries',
|
139
|
|
- '/([^aeiouy]|qu)ies$/i' => '\1y',
|
140
|
|
- '/(tive)s$/i' => '\1',
|
141
|
|
- '/(hive)s$/i' => '\1',
|
142
|
|
- '/(drive)s$/i' => '\1',
|
143
|
|
- '/([le])ves$/i' => '\1f',
|
144
|
|
- '/([^rfoa])ves$/i' => '\1fe',
|
145
|
|
- '/(^analy)ses$/i' => '\1sis',
|
146
|
|
- '/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
|
147
|
|
- '/([ti])a$/i' => '\1um',
|
148
|
|
- '/(p)eople$/i' => '\1\2erson',
|
149
|
|
- '/(m)en$/i' => '\1an',
|
150
|
|
- '/(c)hildren$/i' => '\1\2hild',
|
151
|
|
- '/(n)ews$/i' => '\1\2ews',
|
152
|
|
- '/eaus$/' => 'eau',
|
153
|
|
- '/^(.*us)$/' => '\\1',
|
154
|
|
- '/s$/i' => ''
|
155
|
|
- ),
|
156
|
|
- 'uninflected' => array(
|
157
|
|
- '.*data',
|
158
|
|
- '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', '.*ss', 'feedback'
|
159
|
|
- ),
|
160
|
|
- 'irregular' => array(
|
161
|
|
- 'foes' => 'foe',
|
162
|
|
- )
|
163
|
|
- );
|
164
|
|
-
|
165
|
|
-/**
|
166
|
|
- * Words that should not be inflected
|
167
|
|
- *
|
168
|
|
- * @var array
|
169
|
|
- */
|
170
|
|
- protected static $_uninflected = array(
|
171
|
|
- 'Amoyese', 'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus',
|
172
|
|
- 'carp', 'chassis', 'clippers', 'cod', 'coitus', 'Congoese', 'contretemps', 'corps',
|
173
|
|
- 'debris', 'diabetes', 'djinn', 'eland', 'elk', 'equipment', 'Faroese', 'flounder',
|
174
|
|
- 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti',
|
175
|
|
- 'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings',
|
176
|
|
- 'jackanapes', 'Kiplingese', 'Kongoese', 'Lucchese', 'mackerel', 'Maltese', '.*?media',
|
177
|
|
- 'mews', 'moose', 'mumps', 'Nankingese', 'news', 'nexus', 'Niasese',
|
178
|
|
- 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese',
|
179
|
|
- 'proceedings', 'rabies', 'research', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors',
|
180
|
|
- 'sea[- ]bass', 'series', 'Shavese', 'shears', 'siemens', 'species', 'swine', 'testes',
|
181
|
|
- 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese', 'whiting', 'wildebeest',
|
182
|
|
- 'Yengeese'
|
183
|
|
- );
|
184
|
|
-
|
185
|
|
-/**
|
186
|
|
- * Default map of accented and special characters to ASCII characters
|
187
|
|
- *
|
188
|
|
- * @var array
|
189
|
|
- */
|
190
|
|
- protected static $_transliteration = array(
|
191
|
|
- '/À|Á|Â|Ã|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A',
|
192
|
|
- '/Æ|Ǽ/' => 'AE',
|
193
|
|
- '/Ä/' => 'Ae',
|
194
|
|
- '/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
|
195
|
|
- '/Ð|Ď|Đ/' => 'D',
|
196
|
|
- '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě/' => 'E',
|
197
|
|
- '/Ĝ|Ğ|Ġ|Ģ|Ґ/' => 'G',
|
198
|
|
- '/Ĥ|Ħ/' => 'H',
|
199
|
|
- '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|І/' => 'I',
|
200
|
|
- '/IJ/' => 'IJ',
|
201
|
|
- '/Ĵ/' => 'J',
|
202
|
|
- '/Ķ/' => 'K',
|
203
|
|
- '/Ĺ|Ļ|Ľ|Ŀ|Ł/' => 'L',
|
204
|
|
- '/Ñ|Ń|Ņ|Ň/' => 'N',
|
205
|
|
- '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ/' => 'O',
|
206
|
|
- '/Œ/' => 'OE',
|
207
|
|
- '/Ö/' => 'Oe',
|
208
|
|
- '/Ŕ|Ŗ|Ř/' => 'R',
|
209
|
|
- '/Ś|Ŝ|Ş|Ș|Š/' => 'S',
|
210
|
|
- '/ẞ/' => 'SS',
|
211
|
|
- '/Ţ|Ț|Ť|Ŧ/' => 'T',
|
212
|
|
- '/Þ/' => 'TH',
|
213
|
|
- '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/' => 'U',
|
214
|
|
- '/Ü/' => 'Ue',
|
215
|
|
- '/Ŵ/' => 'W',
|
216
|
|
- '/Ý|Ÿ|Ŷ/' => 'Y',
|
217
|
|
- '/Є/' => 'Ye',
|
218
|
|
- '/Ї/' => 'Yi',
|
219
|
|
- '/Ź|Ż|Ž/' => 'Z',
|
220
|
|
- '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/' => 'a',
|
221
|
|
- '/ä|æ|ǽ/' => 'ae',
|
222
|
|
- '/ç|ć|ĉ|ċ|č/' => 'c',
|
223
|
|
- '/ð|ď|đ/' => 'd',
|
224
|
|
- '/è|é|ê|ë|ē|ĕ|ė|ę|ě/' => 'e',
|
225
|
|
- '/ƒ/' => 'f',
|
226
|
|
- '/ĝ|ğ|ġ|ģ|ґ/' => 'g',
|
227
|
|
- '/ĥ|ħ/' => 'h',
|
228
|
|
- '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|і/' => 'i',
|
229
|
|
- '/ij/' => 'ij',
|
230
|
|
- '/ĵ/' => 'j',
|
231
|
|
- '/ķ/' => 'k',
|
232
|
|
- '/ĺ|ļ|ľ|ŀ|ł/' => 'l',
|
233
|
|
- '/ñ|ń|ņ|ň|ʼn/' => 'n',
|
234
|
|
- '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º/' => 'o',
|
235
|
|
- '/ö|œ/' => 'oe',
|
236
|
|
- '/ŕ|ŗ|ř/' => 'r',
|
237
|
|
- '/ś|ŝ|ş|ș|š|ſ/' => 's',
|
238
|
|
- '/ß/' => 'ss',
|
239
|
|
- '/ţ|ț|ť|ŧ/' => 't',
|
240
|
|
- '/þ/' => 'th',
|
241
|
|
- '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/' => 'u',
|
242
|
|
- '/ü/' => 'ue',
|
243
|
|
- '/ŵ/' => 'w',
|
244
|
|
- '/ý|ÿ|ŷ/' => 'y',
|
245
|
|
- '/є/' => 'ye',
|
246
|
|
- '/ї/' => 'yi',
|
247
|
|
- '/ź|ż|ž/' => 'z',
|
248
|
|
- );
|
249
|
|
-
|
250
|
|
-/**
|
251
|
|
- * Method cache array.
|
252
|
|
- *
|
253
|
|
- * @var array
|
254
|
|
- */
|
255
|
|
- protected static $_cache = array();
|
256
|
|
-
|
257
|
|
-/**
|
258
|
|
- * The initial state of Inflector so reset() works.
|
259
|
|
- *
|
260
|
|
- * @var array
|
261
|
|
- */
|
262
|
|
- protected static $_initialState = array();
|
263
|
|
-
|
264
|
|
-/**
|
265
|
|
- * Cache inflected values, and return if already available
|
266
|
|
- *
|
267
|
|
- * @param string $type Inflection type
|
268
|
|
- * @param string $key Original value
|
269
|
|
- * @param string $value Inflected value
|
270
|
|
- * @return string Inflected value, from cache
|
271
|
|
- */
|
272
|
|
- protected static function _cache($type, $key, $value = false) {
|
273
|
|
- $key = '_' . $key;
|
274
|
|
- $type = '_' . $type;
|
275
|
|
- if ($value !== false) {
|
276
|
|
- self::$_cache[$type][$key] = $value;
|
277
|
|
- return $value;
|
278
|
|
- }
|
279
|
|
- if (!isset(self::$_cache[$type][$key])) {
|
280
|
|
- return false;
|
281
|
|
- }
|
282
|
|
- return self::$_cache[$type][$key];
|
283
|
|
- }
|
284
|
|
-
|
285
|
|
-/**
|
286
|
|
- * Clears Inflectors inflected value caches. And resets the inflection
|
287
|
|
- * rules to the initial values.
|
288
|
|
- *
|
289
|
|
- * @return void
|
290
|
|
- */
|
291
|
|
- public static function reset() {
|
292
|
|
- if (empty(self::$_initialState)) {
|
293
|
|
- self::$_initialState = get_class_vars('Inflector');
|
294
|
|
- return;
|
295
|
|
- }
|
296
|
|
- foreach (self::$_initialState as $key => $val) {
|
297
|
|
- if ($key !== '_initialState') {
|
298
|
|
- self::${$key} = $val;
|
299
|
|
- }
|
300
|
|
- }
|
301
|
|
- }
|
302
|
|
-
|
303
|
|
-/**
|
304
|
|
- * Adds custom inflection $rules, of either 'plural', 'singular' or 'transliteration' $type.
|
305
|
|
- *
|
306
|
|
- * ### Usage:
|
307
|
|
- *
|
308
|
|
- * ```
|
309
|
|
- * Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables'));
|
310
|
|
- * Inflector::rules('plural', array(
|
311
|
|
- * 'rules' => array('/^(inflect)ors$/i' => '\1ables'),
|
312
|
|
- * 'uninflected' => array('dontinflectme'),
|
313
|
|
- * 'irregular' => array('red' => 'redlings')
|
314
|
|
- * ));
|
315
|
|
- * Inflector::rules('transliteration', array('/å/' => 'aa'));
|
316
|
|
- * ```
|
317
|
|
- *
|
318
|
|
- * @param string $type The type of inflection, either 'plural', 'singular' or 'transliteration'
|
319
|
|
- * @param array $rules Array of rules to be added.
|
320
|
|
- * @param bool $reset If true, will unset default inflections for all
|
321
|
|
- * new rules that are being defined in $rules.
|
322
|
|
- * @return void
|
323
|
|
- */
|
324
|
|
- public static function rules($type, $rules, $reset = false) {
|
325
|
|
- $var = '_' . $type;
|
326
|
|
-
|
327
|
|
- switch ($type) {
|
328
|
|
- case 'transliteration':
|
329
|
|
- if ($reset) {
|
330
|
|
- self::$_transliteration = $rules;
|
331
|
|
- } else {
|
332
|
|
- self::$_transliteration = $rules + self::$_transliteration;
|
333
|
|
- }
|
334
|
|
- break;
|
335
|
|
-
|
336
|
|
- default:
|
337
|
|
- foreach ($rules as $rule => $pattern) {
|
338
|
|
- if (is_array($pattern)) {
|
339
|
|
- if ($reset) {
|
340
|
|
- self::${$var}[$rule] = $pattern;
|
341
|
|
- } else {
|
342
|
|
- if ($rule === 'uninflected') {
|
343
|
|
- self::${$var}[$rule] = array_merge($pattern, self::${$var}[$rule]);
|
344
|
|
- } else {
|
345
|
|
- self::${$var}[$rule] = $pattern + self::${$var}[$rule];
|
346
|
|
- }
|
347
|
|
- }
|
348
|
|
- unset($rules[$rule], self::${$var}['cache' . ucfirst($rule)]);
|
349
|
|
- if (isset(self::${$var}['merged'][$rule])) {
|
350
|
|
- unset(self::${$var}['merged'][$rule]);
|
351
|
|
- }
|
352
|
|
- if ($type === 'plural') {
|
353
|
|
- self::$_cache['pluralize'] = self::$_cache['tableize'] = array();
|
354
|
|
- } elseif ($type === 'singular') {
|
355
|
|
- self::$_cache['singularize'] = array();
|
356
|
|
- }
|
357
|
|
- }
|
358
|
|
- }
|
359
|
|
- self::${$var}['rules'] = $rules + self::${$var}['rules'];
|
360
|
|
- }
|
361
|
|
- }
|
362
|
|
-
|
363
|
|
-/**
|
364
|
|
- * Return $word in plural form.
|
365
|
|
- *
|
366
|
|
- * @param string $word Word in singular
|
367
|
|
- * @return string Word in plural
|
368
|
|
- * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::pluralize
|
369
|
|
- */
|
370
|
|
- public static function pluralize($word) {
|
371
|
|
- if (isset(self::$_cache['pluralize'][$word])) {
|
372
|
|
- return self::$_cache['pluralize'][$word];
|
373
|
|
- }
|
374
|
|
-
|
375
|
|
- if (!isset(self::$_plural['merged']['irregular'])) {
|
376
|
|
- self::$_plural['merged']['irregular'] = self::$_plural['irregular'];
|
377
|
|
- }
|
378
|
|
-
|
379
|
|
- if (!isset(self::$_plural['merged']['uninflected'])) {
|
380
|
|
- self::$_plural['merged']['uninflected'] = array_merge(self::$_plural['uninflected'], self::$_uninflected);
|
381
|
|
- }
|
382
|
|
-
|
383
|
|
- if (!isset(self::$_plural['cacheUninflected']) || !isset(self::$_plural['cacheIrregular'])) {
|
384
|
|
- self::$_plural['cacheUninflected'] = '(?:' . implode('|', self::$_plural['merged']['uninflected']) . ')';
|
385
|
|
- self::$_plural['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_plural['merged']['irregular'])) . ')';
|
386
|
|
- }
|
387
|
|
-
|
388
|
|
- if (preg_match('/(.*)\\b(' . self::$_plural['cacheIrregular'] . ')$/i', $word, $regs)) {
|
389
|
|
- self::$_cache['pluralize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$_plural['merged']['irregular'][strtolower($regs[2])], 1);
|
390
|
|
- return self::$_cache['pluralize'][$word];
|
391
|
|
- }
|
392
|
|
-
|
393
|
|
- if (preg_match('/^(' . self::$_plural['cacheUninflected'] . ')$/i', $word, $regs)) {
|
394
|
|
- self::$_cache['pluralize'][$word] = $word;
|
395
|
|
- return $word;
|
396
|
|
- }
|
397
|
|
-
|
398
|
|
- foreach (self::$_plural['rules'] as $rule => $replacement) {
|
399
|
|
- if (preg_match($rule, $word)) {
|
400
|
|
- self::$_cache['pluralize'][$word] = preg_replace($rule, $replacement, $word);
|
401
|
|
- return self::$_cache['pluralize'][$word];
|
402
|
|
- }
|
403
|
|
- }
|
404
|
|
- }
|
405
|
|
-
|
406
|
|
-/**
|
407
|
|
- * Return $word in singular form.
|
408
|
|
- *
|
409
|
|
- * @param string $word Word in plural
|
410
|
|
- * @return string Word in singular
|
411
|
|
- * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::singularize
|
412
|
|
- */
|
413
|
|
- public static function singularize($word) {
|
414
|
|
- if (isset(self::$_cache['singularize'][$word])) {
|
415
|
|
- return self::$_cache['singularize'][$word];
|
416
|
|
- }
|
417
|
|
-
|
418
|
|
- if (!isset(self::$_singular['merged']['uninflected'])) {
|
419
|
|
- self::$_singular['merged']['uninflected'] = array_merge(
|
420
|
|
- self::$_singular['uninflected'],
|
421
|
|
- self::$_uninflected
|
422
|
|
- );
|
423
|
|
- }
|
424
|
|
-
|
425
|
|
- if (!isset(self::$_singular['merged']['irregular'])) {
|
426
|
|
- self::$_singular['merged']['irregular'] = array_merge(
|
427
|
|
- self::$_singular['irregular'],
|
428
|
|
- array_flip(self::$_plural['irregular'])
|
429
|
|
- );
|
430
|
|
- }
|
431
|
|
-
|
432
|
|
- if (!isset(self::$_singular['cacheUninflected']) || !isset(self::$_singular['cacheIrregular'])) {
|
433
|
|
- self::$_singular['cacheUninflected'] = '(?:' . implode('|', self::$_singular['merged']['uninflected']) . ')';
|
434
|
|
- self::$_singular['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_singular['merged']['irregular'])) . ')';
|
435
|
|
- }
|
436
|
|
-
|
437
|
|
- if (preg_match('/(.*)\\b(' . self::$_singular['cacheIrregular'] . ')$/i', $word, $regs)) {
|
438
|
|
- self::$_cache['singularize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$_singular['merged']['irregular'][strtolower($regs[2])], 1);
|
439
|
|
- return self::$_cache['singularize'][$word];
|
440
|
|
- }
|
441
|
|
-
|
442
|
|
- if (preg_match('/^(' . self::$_singular['cacheUninflected'] . ')$/i', $word, $regs)) {
|
443
|
|
- self::$_cache['singularize'][$word] = $word;
|
444
|
|
- return $word;
|
445
|
|
- }
|
446
|
|
-
|
447
|
|
- foreach (self::$_singular['rules'] as $rule => $replacement) {
|
448
|
|
- if (preg_match($rule, $word)) {
|
449
|
|
- self::$_cache['singularize'][$word] = preg_replace($rule, $replacement, $word);
|
450
|
|
- return self::$_cache['singularize'][$word];
|
451
|
|
- }
|
452
|
|
- }
|
453
|
|
- self::$_cache['singularize'][$word] = $word;
|
454
|
|
- return $word;
|
455
|
|
- }
|
456
|
|
-
|
457
|
|
-/**
|
458
|
|
- * Returns the given lower_case_and_underscored_word as a CamelCased word.
|
459
|
|
- *
|
460
|
|
- * @param string $lowerCaseAndUnderscoredWord Word to camelize
|
461
|
|
- * @return string Camelized word. LikeThis.
|
462
|
|
- * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::camelize
|
463
|
|
- */
|
464
|
|
- public static function camelize($lowerCaseAndUnderscoredWord) {
|
465
|
|
- if (!($result = self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
|
466
|
|
- $result = str_replace(' ', '', Inflector::humanize($lowerCaseAndUnderscoredWord));
|
467
|
|
- self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
|
468
|
|
- }
|
469
|
|
- return $result;
|
470
|
|
- }
|
471
|
|
-
|
472
|
|
-/**
|
473
|
|
- * Returns the given camelCasedWord as an underscored_word.
|
474
|
|
- *
|
475
|
|
- * @param string $camelCasedWord Camel-cased word to be "underscorized"
|
476
|
|
- * @return string Underscore-syntaxed version of the $camelCasedWord
|
477
|
|
- * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::underscore
|
478
|
|
- */
|
479
|
|
- public static function underscore($camelCasedWord) {
|
480
|
|
- if (!($result = self::_cache(__FUNCTION__, $camelCasedWord))) {
|
481
|
|
- $result = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
|
482
|
|
- self::_cache(__FUNCTION__, $camelCasedWord, $result);
|
483
|
|
- }
|
484
|
|
- return $result;
|
485
|
|
- }
|
486
|
|
-
|
487
|
|
-/**
|
488
|
|
- * Returns the given underscored_word_group as a Human Readable Word Group.
|
489
|
|
- * (Underscores are replaced by spaces and capitalized following words.)
|
490
|
|
- *
|
491
|
|
- * @param string $lowerCaseAndUnderscoredWord String to be made more readable
|
492
|
|
- * @return string Human-readable string
|
493
|
|
- * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::humanize
|
494
|
|
- */
|
495
|
|
- public static function humanize($lowerCaseAndUnderscoredWord) {
|
496
|
|
- if (!($result = self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
|
497
|
|
- $result = ucwords(str_replace('_', ' ', $lowerCaseAndUnderscoredWord));
|
498
|
|
- self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
|
499
|
|
- }
|
500
|
|
- return $result;
|
501
|
|
- }
|
502
|
|
-
|
503
|
|
-/**
|
504
|
|
- * Returns corresponding table name for given model $className. ("people" for the model class "Person").
|
505
|
|
- *
|
506
|
|
- * @param string $className Name of class to get database table name for
|
507
|
|
- * @return string Name of the database table for given class
|
508
|
|
- * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::tableize
|
509
|
|
- */
|
510
|
|
- public static function tableize($className) {
|
511
|
|
- if (!($result = self::_cache(__FUNCTION__, $className))) {
|
512
|
|
- $result = Inflector::pluralize(Inflector::underscore($className));
|
513
|
|
- self::_cache(__FUNCTION__, $className, $result);
|
514
|
|
- }
|
515
|
|
- return $result;
|
516
|
|
- }
|
517
|
|
-
|
518
|
|
-/**
|
519
|
|
- * Returns Cake model class name ("Person" for the database table "people".) for given database table.
|
520
|
|
- *
|
521
|
|
- * @param string $tableName Name of database table to get class name for
|
522
|
|
- * @return string Class name
|
523
|
|
- * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::classify
|
524
|
|
- */
|
525
|
|
- public static function classify($tableName) {
|
526
|
|
- if (!($result = self::_cache(__FUNCTION__, $tableName))) {
|
527
|
|
- $result = Inflector::camelize(Inflector::singularize($tableName));
|
528
|
|
- self::_cache(__FUNCTION__, $tableName, $result);
|
529
|
|
- }
|
530
|
|
- return $result;
|
531
|
|
- }
|
532
|
|
-
|
533
|
|
-/**
|
534
|
|
- * Returns camelBacked version of an underscored string.
|
535
|
|
- *
|
536
|
|
- * @param string $string String to convert.
|
537
|
|
- * @return string in variable form
|
538
|
|
- * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::variable
|
539
|
|
- */
|
540
|
|
- public static function variable($string) {
|
541
|
|
- if (!($result = self::_cache(__FUNCTION__, $string))) {
|
542
|
|
- $camelized = Inflector::camelize(Inflector::underscore($string));
|
543
|
|
- $replace = strtolower(substr($camelized, 0, 1));
|
544
|
|
- $result = preg_replace('/\\w/', $replace, $camelized, 1);
|
545
|
|
- self::_cache(__FUNCTION__, $string, $result);
|
546
|
|
- }
|
547
|
|
- return $result;
|
548
|
|
- }
|
549
|
|
-
|
550
|
|
-/**
|
551
|
|
- * Returns a string with all spaces converted to underscores (by default), accented
|
552
|
|
- * characters converted to non-accented characters, and non word characters removed.
|
553
|
|
- *
|
554
|
|
- * @param string $string the string you want to slug
|
555
|
|
- * @param string $replacement will replace keys in map
|
556
|
|
- * @return string
|
557
|
|
- * @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::slug
|
558
|
|
- */
|
559
|
|
- public static function slug($string, $replacement = '_') {
|
560
|
|
- $quotedReplacement = preg_quote($replacement, '/');
|
561
|
|
-
|
562
|
|
- $merge = array(
|
563
|
|
- '/[^\s\p{Zs}\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu' => ' ',
|
564
|
|
- '/[\s\p{Zs}]+/mu' => $replacement,
|
565
|
|
- sprintf('/^[%s]+|[%s]+$/', $quotedReplacement, $quotedReplacement) => '',
|
566
|
|
- );
|
567
|
|
-
|
568
|
|
- $map = self::$_transliteration + $merge;
|
569
|
|
- return preg_replace(array_keys($map), array_values($map), $string);
|
570
|
|
- }
|
571
|
|
-
|
572
|
|
-}
|
573
|
|
-
|
574
|
|
-// Store the initial state
|
575
|
|
-Inflector::reset();
|