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.1 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.1
      • 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
    • Network
      • Email
      • Http
    • Routing
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

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