Skip to content
Permalink
Browse files

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
  • Loading branch information...
markstory committed May 27, 2015
1 parent c6e4208 commit 733ddc7ff447bbb6ed036363b951768ca402fccb
Showing with 5 additions and 10 deletions.
  1. +5 −10 lib/Cake/Utility/Inflector.php
@@ -480,11 +480,7 @@ public static function camelize($lowerCaseAndUnderscoredWord) {
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 @@ public static function underscore($camelCasedWord) {
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;

0 comments on commit 733ddc7

Please sign in to comment.
You can’t perform that action at this time.