From 9ea94297572434e7a3db0908cc0302dc241635f5 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Tue, 2 Dec 2014 16:11:22 +0200 Subject: [PATCH 1/2] camel case convertation improvements --- application/Espo/Core/Utils/Util.php | 22 ++++++++-- tests/Espo/Core/Utils/UtilTest.php | 60 ++++++++++++++++++++++------ 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/application/Espo/Core/Utils/Util.php b/application/Espo/Core/Utils/Util.php index 2fbbcaa541..a94f34ba92 100644 --- a/application/Espo/Core/Utils/Util.php +++ b/application/Espo/Core/Utils/Util.php @@ -63,13 +63,21 @@ class Util * Convert name to Camel Case format, ex. camel_case to camelCase * * @param string $name - * @param string $symbol + * @param string | array $symbol * @param boolean $capitaliseFirstChar * * @return string */ public static function toCamelCase($name, $symbol = '_', $capitaliseFirstChar = false) { + if (is_array($name)) { + foreach ($name as &$value) { + $value = static::toCamelCase($value, $symbol, $capitaliseFirstChar); + } + + return $name; + } + if($capitaliseFirstChar) { $name[0] = strtoupper($name[0]); } @@ -85,12 +93,20 @@ class Util * Convert name from Camel Case format. * ex. camelCase to camel-case * - * @param string $name + * @param string | array $name * * @return string */ public static function fromCamelCase($name, $symbol = '_') { + if (is_array($name)) { + foreach ($name as &$value) { + $value = static::fromCamelCase($value, $symbol); + } + + return $name; + } + $name[0] = strtolower($name[0]); return preg_replace_callback('/([A-Z])/', function ($matches) use ($symbol) { return $symbol . strtolower($matches[1]); @@ -101,7 +117,7 @@ class Util * Convert name from Camel Case format to underscore. * ex. camelCase to camel_case * - * @param string $name + * @param string | array $name * * @return string */ diff --git a/tests/Espo/Core/Utils/UtilTest.php b/tests/Espo/Core/Utils/UtilTest.php index 6aa5d5de68..b10a2b00a5 100644 --- a/tests/Espo/Core/Utils/UtilTest.php +++ b/tests/Espo/Core/Utils/UtilTest.php @@ -13,25 +13,61 @@ class UtilTest extends \PHPUnit_Framework_TestCase public function testToCamelCase() { - $this->assertEquals('detail', Util::toCamelCase('detail')); - $this->assertEquals('detailView', Util::toCamelCase('detail-view', '-')); - $this->assertEquals('myDetailView', Util::toCamelCase('my_detail_view')); + $this->assertEquals('detail', Util::toCamelCase('detail')); + $this->assertEquals('detailView', Util::toCamelCase('detail-view', '-')); + $this->assertEquals('myDetailView', Util::toCamelCase('my_detail_view')); + + $input = array( + 'detail', + 'my_detail_view', + ); + $result = array( + 'detail', + 'myDetailView', + ); + $this->assertEquals($result, Util::toCamelCase($input)); } public function testFromCamelCase() { - $this->assertEquals('detail', Util::fromCamelCase('detail')); - $this->assertEquals('detail-view', Util::fromCamelCase('detailView', '-')); - $this->assertEquals('my_detail_view', Util::fromCamelCase('myDetailView')); - $this->assertEquals('my_f_f', Util::fromCamelCase('myFF')); + $this->assertEquals('detail', Util::fromCamelCase('detail')); + $this->assertEquals('detail-view', Util::fromCamelCase('detailView', '-')); + $this->assertEquals('my_detail_view', Util::fromCamelCase('myDetailView')); + $this->assertEquals('my_f_f', Util::fromCamelCase('myFF')); + + $input = array( + 'detail', + 'myDetailView', + 'myFF', + ); + $result = array( + 'detail', + 'my_detail_view', + 'my_f_f', + ); + $this->assertEquals($result, Util::fromCamelCase($input)); } - public function testToUnderScoree() + public function testToUnderScore() { - $this->assertEquals('detail', Util::toUnderScore('detail')); - $this->assertEquals('detail_view', Util::toUnderScore('detailView')); - $this->assertEquals('my_detail_view', Util::toUnderScore('myDetailView')); - $this->assertEquals('my_f_f', Util::toUnderScore('myFF')); + $this->assertEquals('detail', Util::toUnderScore('detail')); + $this->assertEquals('detail_view', Util::toUnderScore('detailView')); + $this->assertEquals('my_detail_view', Util::toUnderScore('myDetailView')); + $this->assertEquals('my_f_f', Util::toUnderScore('myFF')); + + $input = array( + 'detail', + 'detailView', + 'myDetailView', + 'myFF', + ); + $result = array( + 'detail', + 'detail_view', + 'my_detail_view', + 'my_f_f', + ); + $this->assertEquals($result, Util::toUnderScore($input)); } public function testMerge() From 6a5239cedc8ee65ff235cdac01205592f8d8c6ba Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Tue, 2 Dec 2014 16:12:03 +0200 Subject: [PATCH 2/2] added camel case for indexes --- application/Espo/Core/Utils/Database/Schema/Converter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/Espo/Core/Utils/Database/Schema/Converter.php b/application/Espo/Core/Utils/Database/Schema/Converter.php index 617a11a4be..063eb0de28 100644 --- a/application/Espo/Core/Utils/Database/Schema/Converter.php +++ b/application/Espo/Core/Utils/Database/Schema/Converter.php @@ -167,7 +167,8 @@ class Converter if (isset($entityParams['indexes']) && is_array($entityParams['indexes'])) { foreach ($entityParams['indexes'] as $indexName => $indexParams) { if (is_array($indexParams['columns'])) { - $indexList[$indexName] = $indexParams['columns']; + $uIndexName = strtoupper( Util::toUnderScore($indexName) ); + $indexList[$uIndexName] = Util::toUnderScore($indexParams['columns']); } } }