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

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