Commit 5d0452b2 by Carsten Brandt

rename ColumnSchema::typecast to phpTypecast

parent 8a70d9fb
...@@ -621,9 +621,9 @@ abstract class ActiveRecord extends BaseActiveRecord ...@@ -621,9 +621,9 @@ abstract class ActiveRecord extends BaseActiveRecord
if (isset($columns[$name])) { if (isset($columns[$name])) {
if ($columns[$name]->isMva) { if ($columns[$name]->isMva) {
$mvaValue = explode(',', $value); $mvaValue = explode(',', $value);
$row[$name] = array_map(array($columns[$name], 'typecast'), $mvaValue); $row[$name] = array_map(array($columns[$name], 'phpTypecast'), $mvaValue);
} else { } else {
$row[$name] = $columns[$name]->typecast($value); $row[$name] = $columns[$name]->phpTypecast($value);
} }
} }
} }
......
...@@ -8,7 +8,7 @@ Yii Framework 2 sphinx extension Change Log ...@@ -8,7 +8,7 @@ Yii Framework 2 sphinx extension Change Log
- Bug #4018: AR relation eager loading does not work with db models (klimov-paul) - Bug #4018: AR relation eager loading does not work with db models (klimov-paul)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue) - Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) - Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Chg #2287: Split `yii\sphinx\ColumnSchema::typecast()` into two methods `typecast()` and `dbTypecast()` to allow specifying PDO type explicitly (cebe) - Chg #2287: Split `yii\sphinx\ColumnSchema::typecast()` into two methods `phpTypecast()` and `dbTypecast()` to allow specifying PDO type explicitly (cebe)
2.0.0-beta April 13, 2014 2.0.0-beta April 13, 2014
......
...@@ -60,7 +60,7 @@ class ColumnSchema extends Object ...@@ -60,7 +60,7 @@ class ColumnSchema extends Object
* @param mixed $value input value * @param mixed $value input value
* @return mixed converted value * @return mixed converted value
*/ */
public function typecast($value) public function phpTypecast($value)
{ {
if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) { if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) {
return $value; return $value;
...@@ -93,6 +93,6 @@ class ColumnSchema extends Object ...@@ -93,6 +93,6 @@ class ColumnSchema extends Object
{ {
// the default implementation does the same as casting for PHP but it should be possible // the default implementation does the same as casting for PHP but it should be possible
// to override this with annotation of explicit PDO type. // to override this with annotation of explicit PDO type.
return $this->typecast($value); return $this->phpTypecast($value);
} }
} }
...@@ -124,7 +124,7 @@ Yii Framework 2 Change Log ...@@ -124,7 +124,7 @@ Yii Framework 2 Change Log
- Enh: Improved `yii\helpers\Inflector::slug` to support more cases for Russian, Hebrew and special characters (samdark) - Enh: Improved `yii\helpers\Inflector::slug` to support more cases for Russian, Hebrew and special characters (samdark)
- Enh #3926: `yii\widgets\Breadcrumbs::$links`. Allows individual link to have its own `template` (creocoder, umneeq) - Enh #3926: `yii\widgets\Breadcrumbs::$links`. Allows individual link to have its own `template` (creocoder, umneeq)
- Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq) - Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq)
- Chg #2287: Split `yii\db\ColumnSchema::typecast()` into two methods `typecast()` and `dbTypecast()` to allow specifying PDO type explicitly (cebe) - Chg #2287: Split `yii\db\ColumnSchema::typecast()` into two methods `phpTypecast()` and `dbTypecast()` to allow specifying PDO type explicitly (cebe)
- Chg #2898: `yii\console\controllers\AssetController` is now using hashes instead of timestamps (samdark) - Chg #2898: `yii\console\controllers\AssetController` is now using hashes instead of timestamps (samdark)
- Chg #2913: RBAC `DbManager` is now initialized via migration (samdark) - Chg #2913: RBAC `DbManager` is now initialized via migration (samdark)
- Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue) - Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue)
......
...@@ -369,7 +369,7 @@ class ActiveRecord extends BaseActiveRecord ...@@ -369,7 +369,7 @@ class ActiveRecord extends BaseActiveRecord
$columns = static::getTableSchema()->columns; $columns = static::getTableSchema()->columns;
foreach ($row as $name => $value) { foreach ($row as $name => $value) {
if (isset($columns[$name])) { if (isset($columns[$name])) {
$row[$name] = $columns[$name]->typecast($value); $row[$name] = $columns[$name]->phpTypecast($value);
} }
} }
parent::populateRecord($record, $row); parent::populateRecord($record, $row);
...@@ -466,7 +466,7 @@ class ActiveRecord extends BaseActiveRecord ...@@ -466,7 +466,7 @@ class ActiveRecord extends BaseActiveRecord
if ($table->sequenceName !== null) { if ($table->sequenceName !== null) {
foreach ($table->primaryKey as $name) { foreach ($table->primaryKey as $name) {
if ($this->getAttribute($name) === null) { if ($this->getAttribute($name) === null) {
$id = $table->columns[$name]->typecast($db->getLastInsertID($table->sequenceName)); $id = $table->columns[$name]->phpTypecast($db->getLastInsertID($table->sequenceName));
$this->setAttribute($name, $id); $this->setAttribute($name, $id);
$values[$name] = $id; $values[$name] = $id;
break; break;
......
...@@ -84,7 +84,7 @@ class ColumnSchema extends Object ...@@ -84,7 +84,7 @@ class ColumnSchema extends Object
* @param mixed $value input value * @param mixed $value input value
* @return mixed converted value * @return mixed converted value
*/ */
public function typecast($value) public function phpTypecast($value)
{ {
if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY) { if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY) {
return null; return null;
...@@ -117,6 +117,6 @@ class ColumnSchema extends Object ...@@ -117,6 +117,6 @@ class ColumnSchema extends Object
{ {
// the default implementation does the same as casting for PHP but it should be possible // the default implementation does the same as casting for PHP but it should be possible
// to override this with annotation of explicit PDO type. // to override this with annotation of explicit PDO type.
return $this->typecast($value); return $this->phpTypecast($value);
} }
} }
...@@ -251,7 +251,7 @@ class Schema extends \yii\db\Schema ...@@ -251,7 +251,7 @@ class Schema extends \yii\db\Schema
} elseif (isset($type) && $type === 'bit') { } elseif (isset($type) && $type === 'bit') {
$column->defaultValue = hexdec(trim($info['Default'],'X\'')); $column->defaultValue = hexdec(trim($info['Default'],'X\''));
} else { } else {
$column->defaultValue = $column->typecast($info['Default']); $column->defaultValue = $column->phpTypecast($info['Default']);
} }
return $column; return $column;
......
...@@ -222,7 +222,7 @@ class Schema extends \yii\db\Schema ...@@ -222,7 +222,7 @@ class Schema extends \yii\db\Schema
$info['column_default'] = null; $info['column_default'] = null;
} }
if (!$column->isPrimaryKey && ($column->type !== 'timestamp' || $info['column_default'] !== 'CURRENT_TIMESTAMP')) { if (!$column->isPrimaryKey && ($column->type !== 'timestamp' || $info['column_default'] !== 'CURRENT_TIMESTAMP')) {
$column->defaultValue = $column->typecast($info['column_default']); $column->defaultValue = $column->phpTypecast($info['column_default']);
} }
return $column; return $column;
......
...@@ -177,7 +177,7 @@ class Schema extends \yii\db\Schema ...@@ -177,7 +177,7 @@ class Schema extends \yii\db\Schema
} elseif (isset($type) && $type === 'bit') { } elseif (isset($type) && $type === 'bit') {
$column->defaultValue = bindec(trim($info['Default'],'b\'')); $column->defaultValue = bindec(trim($info['Default'],'b\''));
} else { } else {
$column->defaultValue = $column->typecast($info['Default']); $column->defaultValue = $column->phpTypecast($info['Default']);
} }
} }
......
...@@ -174,7 +174,7 @@ EOD; ...@@ -174,7 +174,7 @@ EOD;
if (stripos($column['DATA_DEFAULT'], 'timestamp') !== false) { if (stripos($column['DATA_DEFAULT'], 'timestamp') !== false) {
$c->defaultValue = null; $c->defaultValue = null;
} else { } else {
$c->defaultValue = $c->typecast($column['DATA_DEFAULT']); $c->defaultValue = $c->phpTypecast($column['DATA_DEFAULT']);
} }
} }
......
...@@ -416,9 +416,9 @@ SQL; ...@@ -416,9 +416,9 @@ SQL;
} elseif (preg_match("/^'(.*?)'::/", $column->defaultValue, $matches)) { } elseif (preg_match("/^'(.*?)'::/", $column->defaultValue, $matches)) {
$column->defaultValue = $matches[1]; $column->defaultValue = $matches[1];
} elseif (preg_match("/^(.*?)::/", $column->defaultValue, $matches)) { } elseif (preg_match("/^(.*?)::/", $column->defaultValue, $matches)) {
$column->defaultValue = $column->typecast($matches[1]); $column->defaultValue = $column->phpTypecast($matches[1]);
} else { } else {
$column->defaultValue = $column->typecast($column->defaultValue); $column->defaultValue = $column->phpTypecast($column->defaultValue);
} }
} }
} }
......
...@@ -251,7 +251,7 @@ class Schema extends \yii\db\Schema ...@@ -251,7 +251,7 @@ class Schema extends \yii\db\Schema
$column->defaultValue = new Expression('CURRENT_TIMESTAMP'); $column->defaultValue = new Expression('CURRENT_TIMESTAMP');
} else { } else {
$value = trim($info['dflt_value'], "'\""); $value = trim($info['dflt_value'], "'\"");
$column->defaultValue = $column->typecast($value); $column->defaultValue = $column->phpTypecast($value);
} }
} }
......
...@@ -50,6 +50,6 @@ class ColumnSchemaTest extends SphinxTestCase ...@@ -50,6 +50,6 @@ class ColumnSchemaTest extends SphinxTestCase
$columnSchema = new ColumnSchema(); $columnSchema = new ColumnSchema();
$columnSchema->type = $type; $columnSchema->type = $type;
$columnSchema->phpType = $phpType; $columnSchema->phpType = $phpType;
$this->assertEquals($expectedResult, $columnSchema->typecast($value)); $this->assertEquals($expectedResult, $columnSchema->phpTypecast($value));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment