CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.5 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.5
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

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

Generated using CakePHP API Docs