|
|
|
@ -22,34 +22,6 @@ class ColumnSchema extends \yii\db\ColumnSchema
|
|
|
|
|
* @var int the dimension of array. Defaults to 0, means this column is not an array. |
|
|
|
|
*/ |
|
|
|
|
public $dimension = 0; |
|
|
|
|
/** |
|
|
|
|
* @var bool whether the column schema should OMIT using JSON support feature. |
|
|
|
|
* You can use this property to make upgrade to Yii 2.0.14 easier. |
|
|
|
|
* Default to `false`, meaning JSON support is enabled. |
|
|
|
|
* |
|
|
|
|
* @since 2.0.14.1 |
|
|
|
|
* @deprecated Since 2.0.14.1 and will be removed in 2.1. |
|
|
|
|
*/ |
|
|
|
|
public $disableJsonSupport = false; |
|
|
|
|
/** |
|
|
|
|
* @var bool whether the column schema should OMIT using PgSQL Arrays support feature. |
|
|
|
|
* You can use this property to make upgrade to Yii 2.0.14 easier. |
|
|
|
|
* Default to `false`, meaning Arrays support is enabled. |
|
|
|
|
* |
|
|
|
|
* @since 2.0.14.1 |
|
|
|
|
* @deprecated Since 2.0.14.1 and will be removed in 2.1. |
|
|
|
|
*/ |
|
|
|
|
public $disableArraySupport = false; |
|
|
|
|
/** |
|
|
|
|
* @var bool whether the Array column value should be unserialized to an [[ArrayExpression]] object. |
|
|
|
|
* You can use this property to make upgrade to Yii 2.0.14 easier. |
|
|
|
|
* Default to `true`, meaning arrays are unserialized to [[ArrayExpression]] objects. |
|
|
|
|
* |
|
|
|
|
* @since 2.0.14.1 |
|
|
|
|
* @deprecated Since 2.0.14.1 and will be removed in 2.1. |
|
|
|
|
*/ |
|
|
|
|
public $deserializeArrayColumnToArrayExpression = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@inheritdoc} |
|
|
|
@ -60,10 +32,10 @@ class ColumnSchema extends \yii\db\ColumnSchema
|
|
|
|
|
return $value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!$this->disableArraySupport && $this->dimension > 0) { |
|
|
|
|
if ($this->dimension > 0) { |
|
|
|
|
return new ArrayExpression($value, $this->dbType, $this->dimension); |
|
|
|
|
} |
|
|
|
|
if (!$this->disableJsonSupport && in_array($this->dbType, [Schema::TYPE_JSON, Schema::TYPE_JSONB], true)) { |
|
|
|
|
if (in_array($this->dbType, [Schema::TYPE_JSON, Schema::TYPE_JSONB], true)) { |
|
|
|
|
return new JsonExpression($value, $this->type); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -75,7 +47,7 @@ class ColumnSchema extends \yii\db\ColumnSchema
|
|
|
|
|
*/ |
|
|
|
|
public function phpTypecast($value) |
|
|
|
|
{ |
|
|
|
|
if (!$this->disableArraySupport && $this->dimension > 0) { |
|
|
|
|
if ($this->dimension > 0) { |
|
|
|
|
if (!is_array($value)) { |
|
|
|
|
$value = $this->getArrayParser()->parse($value); |
|
|
|
|
} |
|
|
|
@ -85,9 +57,7 @@ class ColumnSchema extends \yii\db\ColumnSchema
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $this->deserializeArrayColumnToArrayExpression |
|
|
|
|
? new ArrayExpression($value, $this->dbType, $this->dimension) |
|
|
|
|
: $value; |
|
|
|
|
return new ArrayExpression($value, $this->dbType, $this->dimension); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $this->phpTypecastValue($value); |
|
|
|
@ -117,7 +87,7 @@ class ColumnSchema extends \yii\db\ColumnSchema
|
|
|
|
|
} |
|
|
|
|
return (bool) $value; |
|
|
|
|
case Schema::TYPE_JSON: |
|
|
|
|
return $this->disableJsonSupport ? $value : json_decode($value, true); |
|
|
|
|
return json_decode($value, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return parent::phpTypecast($value); |
|
|
|
|