mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-03 06:33:38 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -1,23 +1,24 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Utility
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pluralize and singularize English words.
|
||||
*
|
||||
* Inflector pluralizes and singularizes English nouns.
|
||||
* Used by Cake's naming conventions throughout the framework.
|
||||
* Used by CakePHP's naming conventions throughout the framework.
|
||||
*
|
||||
* @package Cake.Utility
|
||||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html
|
||||
|
@ -31,7 +32,7 @@ class Inflector {
|
|||
*/
|
||||
protected static $_plural = array(
|
||||
'rules' => array(
|
||||
'/(s)tatus$/i' => '\1\2tatuses',
|
||||
'/(s)tatus$/i' => '\1tatuses',
|
||||
'/(quiz)$/i' => '\1zes',
|
||||
'/^(ox)$/i' => '\1\2en',
|
||||
'/([m|l])ouse$/i' => '\1ice',
|
||||
|
@ -39,14 +40,14 @@ class Inflector {
|
|||
'/(x|ch|ss|sh)$/i' => '\1es',
|
||||
'/([^aeiouy]|qu)y$/i' => '\1ies',
|
||||
'/(hive)$/i' => '\1s',
|
||||
'/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
|
||||
'/(?:([^f])fe|([lre])f)$/i' => '\1\2ves',
|
||||
'/sis$/i' => 'ses',
|
||||
'/([ti])um$/i' => '\1a',
|
||||
'/(p)erson$/i' => '\1eople',
|
||||
'/(m)an$/i' => '\1en',
|
||||
'/(?<!u)(m)an$/i' => '\1en',
|
||||
'/(c)hild$/i' => '\1hildren',
|
||||
'/(buffal|tomat)o$/i' => '\1\2oes',
|
||||
'/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i',
|
||||
'/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin)us$/i' => '\1i',
|
||||
'/us$/i' => 'uses',
|
||||
'/(alias)$/i' => '\1es',
|
||||
'/(ax|cris|test)is$/i' => '\1es',
|
||||
|
@ -55,17 +56,29 @@ class Inflector {
|
|||
'/$/' => 's',
|
||||
),
|
||||
'uninflected' => array(
|
||||
'.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people', 'cookie'
|
||||
'.*[nrlm]ese',
|
||||
'.*data',
|
||||
'.*deer',
|
||||
'.*fish',
|
||||
'.*measles',
|
||||
'.*ois',
|
||||
'.*pox',
|
||||
'.*sheep',
|
||||
'people',
|
||||
'feedback',
|
||||
'stadia'
|
||||
),
|
||||
'irregular' => array(
|
||||
'atlas' => 'atlases',
|
||||
'beef' => 'beefs',
|
||||
'brief' => 'briefs',
|
||||
'brother' => 'brothers',
|
||||
'cafe' => 'cafes',
|
||||
'child' => 'children',
|
||||
'cookie' => 'cookies',
|
||||
'corpus' => 'corpuses',
|
||||
'cow' => 'cows',
|
||||
'criterion' => 'criteria',
|
||||
'ganglion' => 'ganglions',
|
||||
'genie' => 'genies',
|
||||
'genus' => 'genera',
|
||||
|
@ -89,7 +102,13 @@ class Inflector {
|
|||
'soliloquy' => 'soliloquies',
|
||||
'testis' => 'testes',
|
||||
'trilby' => 'trilbys',
|
||||
'turf' => 'turfs'
|
||||
'turf' => 'turfs',
|
||||
'potato' => 'potatoes',
|
||||
'hero' => 'heroes',
|
||||
'tooth' => 'teeth',
|
||||
'goose' => 'geese',
|
||||
'foot' => 'feet',
|
||||
'sieve' => 'sieves'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -110,7 +129,7 @@ class Inflector {
|
|||
'/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us',
|
||||
'/([ftw]ax)es/i' => '\1',
|
||||
'/(cris|ax|test)es$/i' => '\1is',
|
||||
'/(shoe|slave)s$/i' => '\1',
|
||||
'/(shoe)s$/i' => '\1',
|
||||
'/(o)es$/i' => '\1',
|
||||
'/ouses$/' => 'ouse',
|
||||
'/([^a])uses$/' => '\1us',
|
||||
|
@ -119,11 +138,11 @@ class Inflector {
|
|||
'/(m)ovies$/i' => '\1\2ovie',
|
||||
'/(s)eries$/i' => '\1\2eries',
|
||||
'/([^aeiouy]|qu)ies$/i' => '\1y',
|
||||
'/([lr])ves$/i' => '\1f',
|
||||
'/(tive)s$/i' => '\1',
|
||||
'/(hive)s$/i' => '\1',
|
||||
'/(drive)s$/i' => '\1',
|
||||
'/([^fo])ves$/i' => '\1fe',
|
||||
'/([le])ves$/i' => '\1f',
|
||||
'/([^rfoa])ves$/i' => '\1fe',
|
||||
'/(^analy)ses$/i' => '\1sis',
|
||||
'/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
|
||||
'/([ti])a$/i' => '\1um',
|
||||
|
@ -136,12 +155,11 @@ class Inflector {
|
|||
'/s$/i' => ''
|
||||
),
|
||||
'uninflected' => array(
|
||||
'.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', '.*ss'
|
||||
'.*data',
|
||||
'.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', '.*ss', 'feedback'
|
||||
),
|
||||
'irregular' => array(
|
||||
'foes' => 'foe',
|
||||
'waves' => 'wave',
|
||||
'curves' => 'curve'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -159,7 +177,7 @@ class Inflector {
|
|||
'jackanapes', 'Kiplingese', 'Kongoese', 'Lucchese', 'mackerel', 'Maltese', '.*?media',
|
||||
'mews', 'moose', 'mumps', 'Nankingese', 'news', 'nexus', 'Niasese',
|
||||
'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese',
|
||||
'proceedings', 'rabies', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors',
|
||||
'proceedings', 'rabies', 'research', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors',
|
||||
'sea[- ]bass', 'series', 'Shavese', 'shears', 'siemens', 'species', 'swine', 'testes',
|
||||
'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese', 'whiting', 'wildebeest',
|
||||
'Yengeese'
|
||||
|
@ -171,56 +189,63 @@ class Inflector {
|
|||
* @var array
|
||||
*/
|
||||
protected static $_transliteration = array(
|
||||
'/ä|æ|ǽ/' => 'ae',
|
||||
'/ö|œ/' => 'oe',
|
||||
'/ü/' => 'ue',
|
||||
'/Ä/' => 'Ae',
|
||||
'/Ü/' => 'Ue',
|
||||
'/Ö/' => 'Oe',
|
||||
'/À|Á|Â|Ã|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A',
|
||||
'/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/' => 'a',
|
||||
'/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
|
||||
'/ç|ć|ĉ|ċ|č/' => 'c',
|
||||
'/Ð|Ď|Đ/' => 'D',
|
||||
'/ð|ď|đ/' => 'd',
|
||||
'/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě/' => 'E',
|
||||
'/è|é|ê|ë|ē|ĕ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
|
||||
'/ç|ć|ĉ|ċ|č/' => 'c',
|
||||
'/ð|ď|đ/' => 'd',
|
||||
'/è|é|ê|ë|ē|ĕ|ė|ę|ě/' => 'e',
|
||||
'/ƒ/' => 'f',
|
||||
'/ĝ|ğ|ġ|ģ|ґ/' => 'g',
|
||||
'/ĥ|ħ/' => 'h',
|
||||
'/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|і/' => 'i',
|
||||
'/ij/' => 'ij',
|
||||
'/ĵ/' => 'j',
|
||||
'/ķ/' => 'k',
|
||||
'/ĺ|ļ|ľ|ŀ|ł/' => 'l',
|
||||
'/ñ|ń|ņ|ň|ʼn/' => 'n',
|
||||
'/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º/' => 'o',
|
||||
'/ö|œ/' => 'oe',
|
||||
'/ŕ|ŗ|ř/' => 'r',
|
||||
'/ś|ŝ|ş|ș|š|ſ/' => 's',
|
||||
'/ß/' => 'ss',
|
||||
'/ţ|ț|ť|ŧ/' => 't',
|
||||
'/þ/' => 'th',
|
||||
'/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/' => 'u',
|
||||
'/ü/' => 'ue',
|
||||
'/ŵ/' => 'w',
|
||||
'/ý|ÿ|ŷ/' => 'y',
|
||||
'/є/' => 'ye',
|
||||
'/ї/' => 'yi',
|
||||
'/ź|ż|ž/' => 'z',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -249,13 +274,13 @@ class Inflector {
|
|||
$key = '_' . $key;
|
||||
$type = '_' . $type;
|
||||
if ($value !== false) {
|
||||
self::$_cache[$type][$key] = $value;
|
||||
static::$_cache[$type][$key] = $value;
|
||||
return $value;
|
||||
}
|
||||
if (!isset(self::$_cache[$type][$key])) {
|
||||
if (!isset(static::$_cache[$type][$key])) {
|
||||
return false;
|
||||
}
|
||||
return self::$_cache[$type][$key];
|
||||
return static::$_cache[$type][$key];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -265,13 +290,13 @@ class Inflector {
|
|||
* @return void
|
||||
*/
|
||||
public static function reset() {
|
||||
if (empty(self::$_initialState)) {
|
||||
self::$_initialState = get_class_vars('Inflector');
|
||||
if (empty(static::$_initialState)) {
|
||||
static::$_initialState = get_class_vars('Inflector');
|
||||
return;
|
||||
}
|
||||
foreach (self::$_initialState as $key => $val) {
|
||||
if ($key != '_initialState') {
|
||||
self::${$key} = $val;
|
||||
foreach (static::$_initialState as $key => $val) {
|
||||
if ($key !== '_initialState') {
|
||||
static::${$key} = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -281,7 +306,7 @@ class Inflector {
|
|||
*
|
||||
* ### Usage:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables'));
|
||||
* Inflector::rules('plural', array(
|
||||
* 'rules' => array('/^(inflect)ors$/i' => '\1ables'),
|
||||
|
@ -289,11 +314,11 @@ class Inflector {
|
|||
* 'irregular' => array('red' => 'redlings')
|
||||
* ));
|
||||
* Inflector::rules('transliteration', array('/å/' => 'aa'));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* @param string $type The type of inflection, either 'plural', 'singular' or 'transliteration'
|
||||
* @param array $rules Array of rules to be added.
|
||||
* @param boolean $reset If true, will unset default inflections for all
|
||||
* @param bool $reset If true, will unset default inflections for all
|
||||
* new rules that are being defined in $rules.
|
||||
* @return void
|
||||
*/
|
||||
|
@ -303,37 +328,36 @@ class Inflector {
|
|||
switch ($type) {
|
||||
case 'transliteration':
|
||||
if ($reset) {
|
||||
self::$_transliteration = $rules;
|
||||
static::$_transliteration = $rules;
|
||||
} else {
|
||||
self::$_transliteration = $rules + self::$_transliteration;
|
||||
static::$_transliteration = $rules + static::$_transliteration;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
foreach ($rules as $rule => $pattern) {
|
||||
if (is_array($pattern)) {
|
||||
if ($reset) {
|
||||
self::${$var}[$rule] = $pattern;
|
||||
static::${$var}[$rule] = $pattern;
|
||||
} else {
|
||||
if ($rule === 'uninflected') {
|
||||
self::${$var}[$rule] = array_merge($pattern, self::${$var}[$rule]);
|
||||
static::${$var}[$rule] = array_merge($pattern, static::${$var}[$rule]);
|
||||
} else {
|
||||
self::${$var}[$rule] = $pattern + self::${$var}[$rule];
|
||||
static::${$var}[$rule] = $pattern + static::${$var}[$rule];
|
||||
}
|
||||
}
|
||||
unset($rules[$rule], self::${$var}['cache' . ucfirst($rule)]);
|
||||
if (isset(self::${$var}['merged'][$rule])) {
|
||||
unset(self::${$var}['merged'][$rule]);
|
||||
unset($rules[$rule], static::${$var}['cache' . ucfirst($rule)]);
|
||||
if (isset(static::${$var}['merged'][$rule])) {
|
||||
unset(static::${$var}['merged'][$rule]);
|
||||
}
|
||||
if ($type === 'plural') {
|
||||
self::$_cache['pluralize'] = self::$_cache['tableize'] = array();
|
||||
static::$_cache['pluralize'] = static::$_cache['tableize'] = array();
|
||||
} elseif ($type === 'singular') {
|
||||
self::$_cache['singularize'] = array();
|
||||
static::$_cache['singularize'] = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
self::${$var}['rules'] = $rules + self::${$var}['rules'];
|
||||
break;
|
||||
static::${$var}['rules'] = $rules + static::${$var}['rules'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -345,37 +369,39 @@ class Inflector {
|
|||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::pluralize
|
||||
*/
|
||||
public static function pluralize($word) {
|
||||
if (isset(self::$_cache['pluralize'][$word])) {
|
||||
return self::$_cache['pluralize'][$word];
|
||||
if (isset(static::$_cache['pluralize'][$word])) {
|
||||
return static::$_cache['pluralize'][$word];
|
||||
}
|
||||
|
||||
if (!isset(self::$_plural['merged']['irregular'])) {
|
||||
self::$_plural['merged']['irregular'] = self::$_plural['irregular'];
|
||||
if (!isset(static::$_plural['merged']['irregular'])) {
|
||||
static::$_plural['merged']['irregular'] = static::$_plural['irregular'];
|
||||
}
|
||||
|
||||
if (!isset(self::$_plural['merged']['uninflected'])) {
|
||||
self::$_plural['merged']['uninflected'] = array_merge(self::$_plural['uninflected'], self::$_uninflected);
|
||||
if (!isset(static::$_plural['merged']['uninflected'])) {
|
||||
static::$_plural['merged']['uninflected'] = array_merge(static::$_plural['uninflected'], static::$_uninflected);
|
||||
}
|
||||
|
||||
if (!isset(self::$_plural['cacheUninflected']) || !isset(self::$_plural['cacheIrregular'])) {
|
||||
self::$_plural['cacheUninflected'] = '(?:' . implode('|', self::$_plural['merged']['uninflected']) . ')';
|
||||
self::$_plural['cacheIrregular'] = '(?:' . implode('|', array_keys(self::$_plural['merged']['irregular'])) . ')';
|
||||
if (!isset(static::$_plural['cacheUninflected']) || !isset(static::$_plural['cacheIrregular'])) {
|
||||
static::$_plural['cacheUninflected'] = '(?:' . implode('|', static::$_plural['merged']['uninflected']) . ')';
|
||||
static::$_plural['cacheIrregular'] = '(?:' . implode('|', array_keys(static::$_plural['merged']['irregular'])) . ')';
|
||||
}
|
||||
|
||||
if (preg_match('/(.*)\\b(' . self::$_plural['cacheIrregular'] . ')$/i', $word, $regs)) {
|
||||
self::$_cache['pluralize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$_plural['merged']['irregular'][strtolower($regs[2])], 1);
|
||||
return self::$_cache['pluralize'][$word];
|
||||
if (preg_match('/(.*?(?:\\b|_))(' . static::$_plural['cacheIrregular'] . ')$/i', $word, $regs)) {
|
||||
static::$_cache['pluralize'][$word] = $regs[1] .
|
||||
substr($regs[2], 0, 1) .
|
||||
substr(static::$_plural['merged']['irregular'][strtolower($regs[2])], 1);
|
||||
return static::$_cache['pluralize'][$word];
|
||||
}
|
||||
|
||||
if (preg_match('/^(' . self::$_plural['cacheUninflected'] . ')$/i', $word, $regs)) {
|
||||
self::$_cache['pluralize'][$word] = $word;
|
||||
if (preg_match('/^(' . static::$_plural['cacheUninflected'] . ')$/i', $word, $regs)) {
|
||||
static::$_cache['pluralize'][$word] = $word;
|
||||
return $word;
|
||||
}
|
||||
|
||||
foreach (self::$_plural['rules'] as $rule => $replacement) {
|
||||
foreach (static::$_plural['rules'] as $rule => $replacement) {
|
||||
if (preg_match($rule, $word)) {
|
||||
self::$_cache['pluralize'][$word] = preg_replace($rule, $replacement, $word);
|
||||
return self::$_cache['pluralize'][$word];
|
||||
static::$_cache['pluralize'][$word] = preg_replace($rule, $replacement, $word);
|
||||
return static::$_cache['pluralize'][$word];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -388,46 +414,48 @@ class Inflector {
|
|||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::singularize
|
||||
*/
|
||||
public static function singularize($word) {
|
||||
if (isset(self::$_cache['singularize'][$word])) {
|
||||
return self::$_cache['singularize'][$word];
|
||||
if (isset(static::$_cache['singularize'][$word])) {
|
||||
return static::$_cache['singularize'][$word];
|
||||
}
|
||||
|
||||
if (!isset(self::$_singular['merged']['uninflected'])) {
|
||||
self::$_singular['merged']['uninflected'] = array_merge(
|
||||
self::$_singular['uninflected'],
|
||||
self::$_uninflected
|
||||
if (!isset(static::$_singular['merged']['uninflected'])) {
|
||||
static::$_singular['merged']['uninflected'] = array_merge(
|
||||
static::$_singular['uninflected'],
|
||||
static::$_uninflected
|
||||
);
|
||||
}
|
||||
|
||||
if (!isset(self::$_singular['merged']['irregular'])) {
|
||||
self::$_singular['merged']['irregular'] = array_merge(
|
||||
self::$_singular['irregular'],
|
||||
array_flip(self::$_plural['irregular'])
|
||||
if (!isset(static::$_singular['merged']['irregular'])) {
|
||||
static::$_singular['merged']['irregular'] = array_merge(
|
||||
static::$_singular['irregular'],
|
||||
array_flip(static::$_plural['irregular'])
|
||||
);
|
||||
}
|
||||
|
||||
if (!isset(self::$_singular['cacheUninflected']) || !isset(self::$_singular['cacheIrregular'])) {
|
||||
self::$_singular['cacheUninflected'] = '(?:' . join('|', self::$_singular['merged']['uninflected']) . ')';
|
||||
self::$_singular['cacheIrregular'] = '(?:' . join('|', array_keys(self::$_singular['merged']['irregular'])) . ')';
|
||||
if (!isset(static::$_singular['cacheUninflected']) || !isset(static::$_singular['cacheIrregular'])) {
|
||||
static::$_singular['cacheUninflected'] = '(?:' . implode('|', static::$_singular['merged']['uninflected']) . ')';
|
||||
static::$_singular['cacheIrregular'] = '(?:' . implode('|', array_keys(static::$_singular['merged']['irregular'])) . ')';
|
||||
}
|
||||
|
||||
if (preg_match('/(.*)\\b(' . self::$_singular['cacheIrregular'] . ')$/i', $word, $regs)) {
|
||||
self::$_cache['singularize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$_singular['merged']['irregular'][strtolower($regs[2])], 1);
|
||||
return self::$_cache['singularize'][$word];
|
||||
if (preg_match('/(.*?(?:\\b|_))(' . static::$_singular['cacheIrregular'] . ')$/i', $word, $regs)) {
|
||||
static::$_cache['singularize'][$word] = $regs[1] .
|
||||
substr($regs[2], 0, 1) .
|
||||
substr(static::$_singular['merged']['irregular'][strtolower($regs[2])], 1);
|
||||
return static::$_cache['singularize'][$word];
|
||||
}
|
||||
|
||||
if (preg_match('/^(' . self::$_singular['cacheUninflected'] . ')$/i', $word, $regs)) {
|
||||
self::$_cache['singularize'][$word] = $word;
|
||||
if (preg_match('/^(' . static::$_singular['cacheUninflected'] . ')$/i', $word, $regs)) {
|
||||
static::$_cache['singularize'][$word] = $word;
|
||||
return $word;
|
||||
}
|
||||
|
||||
foreach (self::$_singular['rules'] as $rule => $replacement) {
|
||||
foreach (static::$_singular['rules'] as $rule => $replacement) {
|
||||
if (preg_match($rule, $word)) {
|
||||
self::$_cache['singularize'][$word] = preg_replace($rule, $replacement, $word);
|
||||
return self::$_cache['singularize'][$word];
|
||||
static::$_cache['singularize'][$word] = preg_replace($rule, $replacement, $word);
|
||||
return static::$_cache['singularize'][$word];
|
||||
}
|
||||
}
|
||||
self::$_cache['singularize'][$word] = $word;
|
||||
static::$_cache['singularize'][$word] = $word;
|
||||
return $word;
|
||||
}
|
||||
|
||||
|
@ -439,9 +467,9 @@ class Inflector {
|
|||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::camelize
|
||||
*/
|
||||
public static function camelize($lowerCaseAndUnderscoredWord) {
|
||||
if (!($result = self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
|
||||
if (!($result = static::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
|
||||
$result = str_replace(' ', '', Inflector::humanize($lowerCaseAndUnderscoredWord));
|
||||
self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
|
||||
static::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -454,9 +482,10 @@ class Inflector {
|
|||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::underscore
|
||||
*/
|
||||
public static function underscore($camelCasedWord) {
|
||||
if (!($result = self::_cache(__FUNCTION__, $camelCasedWord))) {
|
||||
$result = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
|
||||
self::_cache(__FUNCTION__, $camelCasedWord, $result);
|
||||
if (!($result = static::_cache(__FUNCTION__, $camelCasedWord))) {
|
||||
$underscoredWord = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord);
|
||||
$result = mb_strtolower($underscoredWord);
|
||||
static::_cache(__FUNCTION__, $camelCasedWord, $result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -470,9 +499,13 @@ class Inflector {
|
|||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::humanize
|
||||
*/
|
||||
public static function humanize($lowerCaseAndUnderscoredWord) {
|
||||
if (!($result = self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
|
||||
$result = ucwords(str_replace('_', ' ', $lowerCaseAndUnderscoredWord));
|
||||
self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
|
||||
if (!($result = static::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
|
||||
$result = explode(' ', str_replace('_', ' ', $lowerCaseAndUnderscoredWord));
|
||||
foreach ($result as &$word) {
|
||||
$word = mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1);
|
||||
}
|
||||
$result = implode(' ', $result);
|
||||
static::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -485,9 +518,9 @@ class Inflector {
|
|||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::tableize
|
||||
*/
|
||||
public static function tableize($className) {
|
||||
if (!($result = self::_cache(__FUNCTION__, $className))) {
|
||||
if (!($result = static::_cache(__FUNCTION__, $className))) {
|
||||
$result = Inflector::pluralize(Inflector::underscore($className));
|
||||
self::_cache(__FUNCTION__, $className, $result);
|
||||
static::_cache(__FUNCTION__, $className, $result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -500,9 +533,9 @@ class Inflector {
|
|||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::classify
|
||||
*/
|
||||
public static function classify($tableName) {
|
||||
if (!($result = self::_cache(__FUNCTION__, $tableName))) {
|
||||
if (!($result = static::_cache(__FUNCTION__, $tableName))) {
|
||||
$result = Inflector::camelize(Inflector::singularize($tableName));
|
||||
self::_cache(__FUNCTION__, $tableName, $result);
|
||||
static::_cache(__FUNCTION__, $tableName, $result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -510,16 +543,16 @@ class Inflector {
|
|||
/**
|
||||
* Returns camelBacked version of an underscored string.
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $string String to convert.
|
||||
* @return string in variable form
|
||||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::variable
|
||||
*/
|
||||
public static function variable($string) {
|
||||
if (!($result = self::_cache(__FUNCTION__, $string))) {
|
||||
if (!($result = static::_cache(__FUNCTION__, $string))) {
|
||||
$camelized = Inflector::camelize(Inflector::underscore($string));
|
||||
$replace = strtolower(substr($camelized, 0, 1));
|
||||
$result = preg_replace('/\\w/', $replace, $camelized, 1);
|
||||
self::_cache(__FUNCTION__, $string, $result);
|
||||
static::_cache(__FUNCTION__, $string, $result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -537,12 +570,12 @@ class Inflector {
|
|||
$quotedReplacement = preg_quote($replacement, '/');
|
||||
|
||||
$merge = array(
|
||||
'/[^\s\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu' => ' ',
|
||||
'/\\s+/' => $replacement,
|
||||
'/[^\s\p{Zs}\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu' => ' ',
|
||||
'/[\s\p{Zs}]+/mu' => $replacement,
|
||||
sprintf('/^[%s]+|[%s]+$/', $quotedReplacement, $quotedReplacement) => '',
|
||||
);
|
||||
|
||||
$map = self::$_transliteration + $merge;
|
||||
$map = static::$_transliteration + $merge;
|
||||
return preg_replace(array_keys($map), array_values($map), $string);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue