mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Closes #5792, Inflector optimization by returning replaced values instead of assining before returning
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7940 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
d5b86bc4bf
commit
eb653b8cba
2 changed files with 9 additions and 21 deletions
|
@ -137,7 +137,6 @@ class Inflector extends Object {
|
||||||
$instance[0]->__singularRules = $singularRules;
|
$instance[0]->__singularRules = $singularRules;
|
||||||
$instance[0]->__uninflectedSingular = $uninflectedPlural;
|
$instance[0]->__uninflectedSingular = $uninflectedPlural;
|
||||||
$instance[0]->__irregularSingular = array_flip($irregularPlural);
|
$instance[0]->__irregularSingular = array_flip($irregularPlural);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $instance[0];
|
return $instance[0];
|
||||||
|
@ -216,7 +215,6 @@ class Inflector extends Object {
|
||||||
'trilby' => 'trilbys',
|
'trilby' => 'trilbys',
|
||||||
'turf' => 'turfs');
|
'turf' => 'turfs');
|
||||||
|
|
||||||
|
|
||||||
$pluralRules = Set::pushDiff($this->__pluralRules, $corePluralRules);
|
$pluralRules = Set::pushDiff($this->__pluralRules, $corePluralRules);
|
||||||
$uninflected = Set::pushDiff($this->__uninflectedPlural, $coreUninflectedPlural);
|
$uninflected = Set::pushDiff($this->__uninflectedPlural, $coreUninflectedPlural);
|
||||||
$irregular = Set::pushDiff($this->__irregularPlural, $coreIrregularPlural);
|
$irregular = Set::pushDiff($this->__irregularPlural, $coreIrregularPlural);
|
||||||
|
@ -242,8 +240,8 @@ class Inflector extends Object {
|
||||||
if (isset($_this->pluralized[$word])) {
|
if (isset($_this->pluralized[$word])) {
|
||||||
return $_this->pluralized[$word];
|
return $_this->pluralized[$word];
|
||||||
}
|
}
|
||||||
|
|
||||||
extract($_this->pluralRules);
|
extract($_this->pluralRules);
|
||||||
|
|
||||||
if (!isset($regexUninflected) || !isset($regexIrregular)) {
|
if (!isset($regexUninflected) || !isset($regexIrregular)) {
|
||||||
$regexUninflected = __enclose(join( '|', $uninflected));
|
$regexUninflected = __enclose(join( '|', $uninflected));
|
||||||
$regexIrregular = __enclose(join( '|', array_keys($irregular)));
|
$regexIrregular = __enclose(join( '|', array_keys($irregular)));
|
||||||
|
@ -267,8 +265,6 @@ class Inflector extends Object {
|
||||||
return $_this->pluralized[$word];
|
return $_this->pluralized[$word];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$_this->pluralized[$word] = $word;
|
|
||||||
return $word;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Initializes singular inflection rules.
|
* Initializes singular inflection rules.
|
||||||
|
@ -379,8 +375,8 @@ class Inflector extends Object {
|
||||||
if (isset($_this->singularized[$word])) {
|
if (isset($_this->singularized[$word])) {
|
||||||
return $_this->singularized[$word];
|
return $_this->singularized[$word];
|
||||||
}
|
}
|
||||||
|
|
||||||
extract($_this->singularRules);
|
extract($_this->singularRules);
|
||||||
|
|
||||||
if (!isset($regexUninflected) || !isset($regexIrregular)) {
|
if (!isset($regexUninflected) || !isset($regexIrregular)) {
|
||||||
$regexUninflected = __enclose(join( '|', $uninflected));
|
$regexUninflected = __enclose(join( '|', $uninflected));
|
||||||
$regexIrregular = __enclose(join( '|', array_keys($irregular)));
|
$regexIrregular = __enclose(join( '|', array_keys($irregular)));
|
||||||
|
@ -417,8 +413,7 @@ class Inflector extends Object {
|
||||||
* @link http://book.cakephp.org/view/572/Class-methods
|
* @link http://book.cakephp.org/view/572/Class-methods
|
||||||
*/
|
*/
|
||||||
function camelize($lowerCaseAndUnderscoredWord) {
|
function camelize($lowerCaseAndUnderscoredWord) {
|
||||||
$replace = str_replace(" ", "", ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord)));
|
return str_replace(" ", "", ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord)));
|
||||||
return $replace;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the given camelCasedWord as an underscored_word.
|
* Returns the given camelCasedWord as an underscored_word.
|
||||||
|
@ -430,8 +425,7 @@ class Inflector extends Object {
|
||||||
* @link http://book.cakephp.org/view/572/Class-methods
|
* @link http://book.cakephp.org/view/572/Class-methods
|
||||||
*/
|
*/
|
||||||
function underscore($camelCasedWord) {
|
function underscore($camelCasedWord) {
|
||||||
$replace = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
|
return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
|
||||||
return $replace;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the given underscored_word_group as a Human Readable Word Group.
|
* Returns the given underscored_word_group as a Human Readable Word Group.
|
||||||
|
@ -444,8 +438,7 @@ class Inflector extends Object {
|
||||||
* @link http://book.cakephp.org/view/572/Class-methods
|
* @link http://book.cakephp.org/view/572/Class-methods
|
||||||
*/
|
*/
|
||||||
function humanize($lowerCaseAndUnderscoredWord) {
|
function humanize($lowerCaseAndUnderscoredWord) {
|
||||||
$replace = ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord));
|
return ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord));
|
||||||
return $replace;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns corresponding table name for given model $className. ("people" for the model class "Person").
|
* Returns corresponding table name for given model $className. ("people" for the model class "Person").
|
||||||
|
@ -457,8 +450,7 @@ class Inflector extends Object {
|
||||||
* @link http://book.cakephp.org/view/572/Class-methods
|
* @link http://book.cakephp.org/view/572/Class-methods
|
||||||
*/
|
*/
|
||||||
function tableize($className) {
|
function tableize($className) {
|
||||||
$replace = Inflector::pluralize(Inflector::underscore($className));
|
return Inflector::pluralize(Inflector::underscore($className));
|
||||||
return $replace;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns Cake model class name ("Person" for the database table "people".) for given database table.
|
* Returns Cake model class name ("Person" for the database table "people".) for given database table.
|
||||||
|
@ -470,8 +462,7 @@ class Inflector extends Object {
|
||||||
* @link http://book.cakephp.org/view/572/Class-methods
|
* @link http://book.cakephp.org/view/572/Class-methods
|
||||||
*/
|
*/
|
||||||
function classify($tableName) {
|
function classify($tableName) {
|
||||||
$replace = Inflector::camelize(Inflector::singularize($tableName));
|
return Inflector::camelize(Inflector::singularize($tableName));
|
||||||
return $replace;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns camelBacked version of an underscored string.
|
* Returns camelBacked version of an underscored string.
|
||||||
|
@ -485,8 +476,7 @@ class Inflector extends Object {
|
||||||
function variable($string) {
|
function variable($string) {
|
||||||
$string = Inflector::camelize(Inflector::underscore($string));
|
$string = Inflector::camelize(Inflector::underscore($string));
|
||||||
$replace = strtolower(substr($string, 0, 1));
|
$replace = strtolower(substr($string, 0, 1));
|
||||||
$variable = preg_replace('/\\w/', $replace, $string, 1);
|
return preg_replace('/\\w/', $replace, $string, 1);
|
||||||
return $variable;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a string with all spaces converted to underscores (by default), accented
|
* Returns a string with all spaces converted to underscores (by default), accented
|
||||||
|
@ -522,8 +512,7 @@ class Inflector extends Object {
|
||||||
'/\\s+/' => $replacement,
|
'/\\s+/' => $replacement,
|
||||||
String::insert('/^[:replacement]+|[:replacement]+$/', array('replacement' => preg_quote($replacement, '/'))) => '',
|
String::insert('/^[:replacement]+|[:replacement]+$/', array('replacement' => preg_quote($replacement, '/'))) => '',
|
||||||
);
|
);
|
||||||
$string = preg_replace(array_keys($map), array_values($map), $string);
|
return preg_replace(array_keys($map), array_values($map), $string);
|
||||||
return $string;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
*/
|
*/
|
||||||
App::import('Core', 'Inflector');
|
App::import('Core', 'Inflector');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for class.
|
* Short description for class.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue