Util impovements

This commit is contained in:
Taras Machyshyn
2014-10-30 16:24:43 +02:00
parent c8bfa823e5
commit fcead3379b
4 changed files with 16 additions and 14 deletions
@@ -118,7 +118,7 @@ class RelationManager
$method = $currentType;
if ($foreignLink !== false) {
$method .= '-'.$foreignLink['params']['type'];
$method .= '_' . $foreignLink['params']['type'];
}
$method = Util::toCamelCase($method);
@@ -63,7 +63,7 @@ class ManyMany extends Base
{
$tables = $this->getSortEntities($tableName1, $tableName2);
return Util::toCamelCase( implode('-', $tables) );
return Util::toCamelCase( implode('_', $tables) );
}
protected function getSortEntities($entity1, $entity2)
+9 -7
View File
@@ -60,13 +60,15 @@ class Util
/**
* Convert name to Camel Case format, ex. camel-case to camelCase
* Convert name to Camel Case format, ex. camel_case to camelCase
*
* @param string $name
* @param boolean $capitaliseFirstChar
* @param string $symbol
* @param boolean $capitaliseFirstChar
*
* @return string
*/
public static function toCamelCase($name, $capitaliseFirstChar = false, $symbol = '-')
public static function toCamelCase($name, $symbol = '_', $capitaliseFirstChar = false)
{
if($capitaliseFirstChar) {
$name[0] = strtoupper($name[0]);
@@ -87,7 +89,7 @@ class Util
*
* @return string
*/
public static function fromCamelCase($name, $symbol = '-')
public static function fromCamelCase($name, $symbol = '_')
{
$name[0] = strtolower($name[0]);
return preg_replace_callback('/([A-Z])/', function ($matches) use ($symbol) {
@@ -236,12 +238,12 @@ class Util
*
* @return string
*/
public static function getNaming($name, $prePostFix, $type = 'prefix', $symbol = '-')
public static function getNaming($name, $prePostFix, $type = 'prefix', $symbol = '_')
{
if ($type == 'prefix') {
return static::toCamelCase($prePostFix.$symbol.$name, false, $symbol);
return static::toCamelCase($prePostFix.$symbol.$name, $symbol);
} else if ($type == 'postfix') {
return static::toCamelCase($name.$symbol.$prePostFix, false, $symbol);
return static::toCamelCase($name.$symbol.$prePostFix, $symbol);
}
return null;
+5 -5
View File
@@ -14,16 +14,16 @@ 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('detailView', Util::toCamelCase('detail-view', '-'));
$this->assertEquals('myDetailView', Util::toCamelCase('my_detail_view'));
}
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-view', Util::fromCamelCase('detailView', '-'));
$this->assertEquals('my_detail_view', Util::fromCamelCase('myDetailView'));
$this->assertEquals('my_f_f', Util::fromCamelCase('myFF'));
}
public function testToUnderScoree()