-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev Fixed some database related issues.
- Loading branch information
Showing
13 changed files
with
156 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,4 @@ public function alterEngine($table, $engine) { | |
return true; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,7 @@ public function createDatabase($name) { | |
} | ||
return true; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,47 @@ | ||
<?php | ||
|
||
trait SmartColumnTypeTrait { | ||
trait SmartColumnTypeTrait | ||
{ | ||
|
||
/** | ||
* Adds support for replacing default arguments. | ||
* @param string $type | ||
* @return string | ||
*/ | ||
public function getColumnType($type) | ||
{ | ||
if (isset(Yii::app()->db->schema->columnTypes[$type])) | ||
{ // Direct : get it | ||
$sResult=Yii::app()->db->schema->columnTypes[$type]; | ||
* Splits a column type into 3 parts: | ||
* - The base type. | ||
* - Any parameters that must be passed between brackets (brackets are ommitted). | ||
* - Any arguments that must be appended. | ||
* @param string $type | ||
*/ | ||
protected function splitColumnType($type) { | ||
$regex = '/^([a-zA-Z ]+)\s*(\(.+\))?\s*(.*)$/'; | ||
if (preg_match($regex, $type, $matches)) { | ||
return [ | ||
'base' => trim($matches[1]), | ||
'arguments' => substr($matches[2], 1, -1), | ||
'suffix' => $matches[3] | ||
]; | ||
} | ||
elseif (preg_match('/^([a-zA-Z ]+)\((.+?)\)(.*)$/', $type, $matches)) | ||
{ // With params : some test to do | ||
$baseType = $this->getColumnType($matches[1]); | ||
if(preg_match('/^([a-zA-Z ]+)\((.+?)\)(.*)$/', $baseType, $baseMatches)) | ||
{ // Replace the default Yii param | ||
$sResult=preg_replace('/\(.+\)/', "(".$matches[2].")",parent::getColumnType($matches[1]." ".$matches[3])); | ||
} | ||
else | ||
{ // Get the base type and join | ||
$sResult=join(" ",array($baseType,"(".$matches[2].")",$matches[3])); | ||
} | ||
} | ||
else | ||
{ | ||
$sResult = $this->getColumnType($type); | ||
throw new \Exception("Could not parse type."); | ||
} | ||
|
||
protected function parseType($type, callable $baseParser) { | ||
$parts = $this->splitColumnType($type); | ||
$base = $baseParser($parts['base']); | ||
// vd($base); | ||
$baseParts = $this->splitColumnType($base); | ||
if (!empty($parts['arguments'])) { | ||
$baseParts['arguments'] = $parts['arguments']; | ||
} | ||
return $sResult; | ||
|
||
$result = $baseParts['base'] . (!empty($baseParts['arguments']) ? "({$baseParts['arguments']}) " : " ") . $parts['suffix']; | ||
return $result; | ||
} | ||
/** | ||
* Adds support for replacing default arguments. | ||
* @param string $type | ||
* @return string | ||
*/ | ||
public function getColumnType($type) | ||
{ | ||
// This is bad practice, it assumes knowledge about the traits' parent. | ||
return $this->parseType($type, function($type) { return parent::getColumnType($type); }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.