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

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