diff --git a/CHANGELOG.md b/CHANGELOG.md index 69152211..cc3a3236 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Enh #315: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov) - Enh #314: Implement `ColumnFactory` class (@Tigrov) - Enh #317: Separate column type constants (@Tigrov) +- Enh #318: Realize `ColumnBuilder` class (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Column/ColumnBuilder.php b/src/Column/ColumnBuilder.php new file mode 100644 index 00000000..b0476207 --- /dev/null +++ b/src/Column/ColumnBuilder.php @@ -0,0 +1,9 @@ +queryBuilder; } + public function getColumnFactory(): ColumnFactoryInterface + { + return new ColumnFactory(); + } + public function getQuoter(): QuoterInterface { if ($this->quoter === null) { diff --git a/src/Schema.php b/src/Schema.php index 29a321c1..67752a2a 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -18,10 +18,8 @@ use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Helper\DbArrayHelper; use Yiisoft\Db\Schema\Builder\ColumnInterface; -use Yiisoft\Db\Schema\Column\ColumnFactoryInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\TableSchemaInterface; -use Yiisoft\Db\Sqlite\Column\ColumnFactory; use function array_change_key_case; use function array_column; @@ -81,11 +79,6 @@ public function createColumn(string $type, array|int|string $length = null): Col return new Column($type, $length); } - public function getColumnFactory(): ColumnFactoryInterface - { - return new ColumnFactory(); - } - /** * Returns all table names in the database. * @@ -445,8 +438,10 @@ public function getSchemaDefaultValues(string $schema = '', bool $refresh = fals */ private function loadColumnSchema(array $info): ColumnSchemaInterface { + $columnFactory = $this->db->getColumnFactory(); + $dbType = strtolower($info['type']); - $column = $this->getColumnFactory()->fromDefinition($dbType, ['name' => $info['name']]); + $column = $columnFactory->fromDefinition($dbType, ['name' => $info['name']]); $column->dbType($dbType); $column->allowNull(!$info['notnull']); $column->primaryKey((bool) $info['pk']); diff --git a/tests/ColumnBuilderTest.php b/tests/ColumnBuilderTest.php new file mode 100644 index 00000000..61f45283 --- /dev/null +++ b/tests/ColumnBuilderTest.php @@ -0,0 +1,22 @@ +assertTrue($thrown, 'An exception should have been thrown by the command.'); } + public function testGetColumnFactory(): void + { + $db = $this->getConnection(); + + $this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory()); + } + private function createProfiler(): ProfilerInterface { return $this->createMock(ProfilerInterface::class); diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 758383d2..2a171127 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -11,7 +11,6 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Sqlite\Column\ColumnFactory; use Yiisoft\Db\Sqlite\Schema; use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Common\CommonSchemaTest; @@ -360,12 +359,4 @@ public function testNotConnectionPDO(): void $schema->refresh(); } - - public function testGetColumnFactory(): void - { - $db = $this->getConnection(); - $factory = $db->getSchema()->getColumnFactory(); - - $this->assertInstanceOf(ColumnFactory::class, $factory); - } }