Skip to content

Instantly share code, notes, and snippets.

@nojimage
Last active August 29, 2015 14:22
Show Gist options
  • Save nojimage/294d900c9d9e6d3dc772 to your computer and use it in GitHub Desktop.
Save nojimage/294d900c9d9e6d3dc772 to your computer and use it in GitHub Desktop.
Inflector fix
diff --git a/lib/Cake/Utility/Inflector.php b/lib/Cake/Utility/Inflector.php
index 61a63c2..48b9fa1 100644
--- a/lib/Cake/Utility/Inflector.php
+++ b/lib/Cake/Utility/Inflector.php
@@ -497,7 +497,7 @@ class Inflector {
public static function humanize($lowerCaseAndUnderscoredWord) {
if (!($result = self::_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
$lowerCaseAndUnderscoredWord = self::underscore($lowerCaseAndUnderscoredWord);
- $result = explode(' ', str_replace('_', ' ', $lowerCaseAndUnderscoredWord));
+ $result = explode(' ', str_replace(['_', '.'], [' ', '. '], $lowerCaseAndUnderscoredWord));
foreach ($result as &$word) {
$word = mb_strtoupper(mb_substr($word, 0, 1)) . mb_substr($word, 1);
}
@nojimage
Copy link
Author

nojimage commented Jun 3, 2015

$this->assertEquals(Inflector::humanize('model.field'), 'Model. Field');
$this->assertSame(Inflector::camelize('test_things'), 'TestThings');
$this->assertSame(Inflector::camelize('test_thing_extra'), 'TestThingExtra');
$this->assertSame(Inflector::camelize('test_thing_extrå'), 'TestThingExtrå');
$this->assertSame(Inflector::camelize('TestThing'), 'TestThing');
$this->assertSame(Inflector::camelize('Migrations.PrecheckException'), 'Migrations.PrecheckException');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment