-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated inflector to conserve internal caps #16
Conversation
@@ -238,7 +238,7 @@ public function camelize($term, $downcase_first_letter = self::UPCASE_FIRST_LETT | |||
|
|||
$m = $matches[0]; | |||
|
|||
return !empty($acronyms[$m]) ? $acronyms[$m] : capitalize($m); | |||
return !empty($acronyms[$m]) ? $acronyms[$m] : ucfirst($m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ucfirst()
won't do because it doesn't work with UTF-8. Maybe add a private method:
static private function ucfirst($str)
{
return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, good spotting. Should there be tests for this (all current tests pass)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't actually seen that helpers file until now - would that be a more appropriate place to add it? e.g.
if (!function_exists(__NAMESPACE__ . '\mb_ucfirst'))
{
function mb_ucfirst($str)
{
return upcase(mb_substr($str, 0, 1)) . mb_substr($str, 1);
}
}
Is that naming ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather use a private method, or define mb_ucfirst()
without namespace, that's because mb_
functions are defined in the global namespace, contrary to the helpers in that file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plan a done.
* @param $str | ||
* @return string | ||
*/ | ||
private static function ucfirst($str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing, please define the static method at the top of the class, after static public function get($locale = self::DEFAULT_LOCALE)
, and use static private
rather than private static
. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok cool, except it's not going to work because of the closure context
/** | ||
* Multi-byte safe ucfirst | ||
* | ||
* @param $str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be @param string $str
.
Obviously not ideal having the function out there, but it seems like the cleanest way to retain PHP 5.3 compatibility. |
Also added a test case for this
Fixes #15