mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Use mb* functions in Inflector humanize/underscore.
Use the mbstring shims we already provide to make Inflector more robust than it currently is. This solves the invalid ID attribute generation in a way that never varies between environments. Refs #6635
This commit is contained in:
parent
c6e4208bda
commit
733ddc7ff4
1 changed files with 5 additions and 10 deletions
|
@ -480,11 +480,7 @@ class Inflector {
|
|||
public static function underscore($camelCasedWord) {
|
||||
if (!($result = self::_cache(__FUNCTION__, $camelCasedWord))) {
|
||||
$underscoredWord = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord);
|
||||
if (function_exists('mb_convert_case')) {
|
||||
$result = mb_convert_case($underscoredWord, MB_CASE_LOWER, Configure::read('App.encoding'));
|
||||
} else {
|
||||
$result = strtolower($underscoredWord);
|
||||
}
|
||||
$result = mb_strtolower($underscoredWord);
|
||||
self::_cache(__FUNCTION__, $camelCasedWord, $result);
|
||||
}
|
||||
return $result;
|
||||
|
@ -501,12 +497,11 @@ class Inflector {
|
|||
public static function humanize($lowerCaseAndUnderscoredWord) {
|
||||
if (!($result = self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
|
||||
$lowerCaseAndUnderscoredWord = self::underscore($lowerCaseAndUnderscoredWord);
|
||||
$result = str_replace('_', ' ', $lowerCaseAndUnderscoredWord);
|
||||
if (function_exists('mb_convert_case')) {
|
||||
$result = mb_convert_case($result, MB_CASE_TITLE, Configure::read('App.encoding'));
|
||||
} else {
|
||||
$result = ucwords($result);
|
||||
$result = explode(' ', str_replace('_', ' ', $lowerCaseAndUnderscoredWord));
|
||||
foreach ($result as &$word) {
|
||||
$word = mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1);
|
||||
}
|
||||
$result = implode(' ', $result);
|
||||
self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
|
||||
}
|
||||
return $result;
|
||||
|
|
Loading…
Reference in a new issue