diff --git a/src/ColumnSchema.php b/src/ColumnSchema.php deleted file mode 100644 index 9d81cd14..00000000 --- a/src/ColumnSchema.php +++ /dev/null @@ -1,96 +0,0 @@ -name('id'); - * $column->allowNull(false); - * $column->dbType('int(11)'); - * $column->phpType('integer'); - * $column->type('integer'); - * $column->defaultValue(0); - * $column->autoIncrement(true); - * $column->primaryKey(true); - * ``` - * - * @psalm-suppress DeprecatedInterface - * @psalm-suppress DeprecatedClass - */ -final class ColumnSchema extends AbstractColumnSchema -{ - /** - * Converts the input value according to {@see phpType} after retrieval from the database. - * - * If the value is `null` or an {@see \Yiisoft\Db\Expression\Expression}, it won't be converted. - * - * @param mixed $value The value to convert. - * - * @throws JsonException If the value can't be decoded. - * - * @return mixed The converted value. - */ - public function phpTypecast(mixed $value): mixed - { - if ($value === null) { - return null; - } - - if ($this->getType() === SchemaInterface::TYPE_JSON) { - return json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR); - } - - /** @psalm-suppress DeprecatedClass */ - return parent::phpTypecast($value); - } - - /** - * Converts the input value according to {@see type} and {@see dbType} for use in a db query. - * - * If the value is `null` or an {@see \Yiisoft\Db\Expression\Expression}, it won't be converted. - * - * @param mixed $value The value to convert. - * - * @return mixed The converted value. This may also be an array containing the value as the first element and the - * PDO type as the second element. - */ - public function dbTypecast(mixed $value): mixed - { - if ($value === null || $value instanceof ExpressionInterface) { - return $value; - } - - if ($this->getType() === SchemaInterface::TYPE_JSON) { - return new JsonExpression($value, $this->getDbType()); - } - - /** @psalm-suppress DeprecatedClass */ - return parent::dbTypecast($value); - } -} diff --git a/src/Schema.php b/src/Schema.php index 5ff6ee3d..9230ff7b 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -223,7 +223,7 @@ protected function findColumns(TableSchemaInterface $table): bool } $column = $this->loadColumnSchema($info); - $table->column($column->getName(), $column); + $table->column($info['field'], $column); if ($column->isPrimaryKey()) { $table->primaryKey($column->getName()); @@ -488,7 +488,6 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface } $column->extra($extra); - $column->phpType($this->getColumnPhpType($type)); $column->defaultValue($this->normalizeDefaultValue($info['default'], $column)); if (str_starts_with($extra, 'DEFAULT_GENERATED')) { diff --git a/tests/ColumnSchemaTest.php b/tests/ColumnSchemaTest.php index 385b1dad..1f026d0e 100644 --- a/tests/ColumnSchemaTest.php +++ b/tests/ColumnSchemaTest.php @@ -85,7 +85,7 @@ public function testPhpTypeCast(): void $jsonColPhpType = $tableSchema->getColumn('json_col')?->phpTypecast($query['json_col']); $this->assertSame(1, $intColPhpType); - $this->assertSame(1234567890, $bigUnsignedColPhpType); + $this->assertSame('1234567890', $bigUnsignedColPhpType); $this->assertSame(str_repeat('x', 100), $charColPhpType); $this->assertNull($charCol3PhpType); $this->assertSame(1.234, $floatColPhpType); diff --git a/tests/Provider/SchemaProvider.php b/tests/Provider/SchemaProvider.php index 77e677d4..880f597e 100644 --- a/tests/Provider/SchemaProvider.php +++ b/tests/Provider/SchemaProvider.php @@ -45,7 +45,7 @@ public static function columns(): array 'bigunsigned_col' => [ 'type' => 'bigint', 'dbType' => 'bigint(20) unsigned', - 'phpType' => 'integer', + 'phpType' => 'string', 'primaryKey' => false, 'allowNull' => true, 'autoIncrement' => false,