api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Inflector.php 18KB

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