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 1.3 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.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

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BakeTask
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeRoute
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbConfigTask
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • FileLog
  • FixtureTask
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • MootoolsEngineHelper
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginShortRoute
  • PluginTask
  • ProjectTask
  • PrototypeEngineHelper
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • Set
  • Shell
  • String
  • TemplateTask
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

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