diff --git a/src/Scaffolding/Definitions.php b/src/Scaffolding/Definitions.php index 35f523987db13deaf28d2e1e915e759f4be82370..04f5efe0be327d1679ad5a5e8a64b75bd2218258 100644 --- a/src/Scaffolding/Definitions.php +++ b/src/Scaffolding/Definitions.php @@ -11,12 +11,13 @@ use Grifart\ClassScaffolder\Definition\ClassDefinition; */ final class Definitions implements \IteratorAggregate { + private ?ClassDefinition $factoryClass = null; + private function __construct( private ClassDefinition $rowClass, private ClassDefinition $modificationsClass, private ?ClassDefinition $primaryKeyClass, private ClassDefinition $tableClass, - private ?ClassDefinition $factoryClass, ) {} public static function from( @@ -24,7 +25,6 @@ final class Definitions implements \IteratorAggregate ClassDefinition $modificationsClass, ClassDefinition $primaryKeyClass, ClassDefinition $tableClass, - ClassDefinition $factoryClass, ): self { return new self( @@ -32,7 +32,6 @@ final class Definitions implements \IteratorAggregate $modificationsClass, $primaryKeyClass, $tableClass, - $factoryClass, ); } @@ -66,19 +65,13 @@ final class Definitions implements \IteratorAggregate return $this; } - public function factoryClassWith(Capability $capability, Capability ...$capabilities): self - { - $this->factoryClass = $this->factoryClass?->with($capability, ...$capabilities); - return $this; - } - - public function withoutFactory(): self + public function withFactory(): self { - $this->factoryClass = null; + $tableClassName = $this->tableClass->getFullyQualifiedName(); + $this->factoryClass = (new ClassDefinition($tableClassName . 'Factory'))->with(new TableFactoryImplementation($tableClassName)); return $this; } - public function getIterator(): \Traversable { yield $this->rowClass; diff --git a/src/Scaffolding/TablesDefinitions.php b/src/Scaffolding/TablesDefinitions.php index 805ac51c7bdcf010df7c359aeca58d123ec69ef5..8f6a1b15c1e000750283f5bc9ff798a3b5b449fe 100644 --- a/src/Scaffolding/TablesDefinitions.php +++ b/src/Scaffolding/TablesDefinitions.php @@ -100,9 +100,6 @@ final class TablesDefinitions $columnPhpTypes, )); - $factoryClass = (new ClassDefinition($tableClassName . 'Factory')) - ->with(new TableFactoryImplementation($tableClassName)); - - return Definitions::from($rowClass, $modificationsClass, $primaryKeyClass, $tableClass, $factoryClass); + return Definitions::from($rowClass, $modificationsClass, $primaryKeyClass, $tableClass); } } diff --git a/tests/Fixtures/.definition.php b/tests/Fixtures/.definition.php index 7f6dc2a5f3b9bb40a4c2a93755d9c7c99eb7cb81..155eba0013b2416eaa2b2634d37c2c72653c0a57 100644 --- a/tests/Fixtures/.definition.php +++ b/tests/Fixtures/.definition.php @@ -23,7 +23,7 @@ return [ TestModifications::class, TestsTable::class, TestPrimaryKey::class, - ), + )->withFactory(), ...$tableDefinitions->for( 'public', 'config', diff --git a/tests/Fixtures/ConfigTableFactory.php b/tests/Fixtures/ConfigTableFactory.php deleted file mode 100644 index de03067eb41e2e495bf8514c88872714fef2a187..0000000000000000000000000000000000000000 --- a/tests/Fixtures/ConfigTableFactory.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/** - * Do not edit. This is generated file. Modify definition file instead. - */ - -declare(strict_types=1); - -namespace Grifart\Tables\Tests\Fixtures; - -use Dibi\IConnection; -use Grifart\Tables\SingleConnectionTableManager; -use Grifart\Tables\TableManager; -use Grifart\Tables\TypeResolver; - -final readonly class ConfigTableFactory implements \Grifart\Tables\TableFactory -{ - public function __construct( - private TableManager $tableManager, - private TypeResolver $typeResolver, - ) { - } - - - public function create(): ConfigTable - { - return new ConfigTable($this->tableManager, $this->typeResolver); - } - - - public function withTableManager(TableManager $tableManager): ConfigTable - { - return new ConfigTable($tableManager, $this->typeResolver); - } - - - public function withConnection(IConnection $connection): ConfigTable - { - $tableManager = new SingleConnectionTableManager($connection); - return new ConfigTable($tableManager, $this->typeResolver); - } -} diff --git a/tests/Fixtures/GeneratedTableFactory.php b/tests/Fixtures/GeneratedTableFactory.php deleted file mode 100644 index ac9413d722e6420b9a5e178a838052b24ad3be1e..0000000000000000000000000000000000000000 --- a/tests/Fixtures/GeneratedTableFactory.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/** - * Do not edit. This is generated file. Modify definition file instead. - */ - -declare(strict_types=1); - -namespace Grifart\Tables\Tests\Fixtures; - -use Dibi\IConnection; -use Grifart\Tables\SingleConnectionTableManager; -use Grifart\Tables\TableManager; -use Grifart\Tables\TypeResolver; - -final readonly class GeneratedTableFactory implements \Grifart\Tables\TableFactory -{ - public function __construct( - private TableManager $tableManager, - private TypeResolver $typeResolver, - ) { - } - - - public function create(): GeneratedTable - { - return new GeneratedTable($this->tableManager, $this->typeResolver); - } - - - public function withTableManager(TableManager $tableManager): GeneratedTable - { - return new GeneratedTable($tableManager, $this->typeResolver); - } - - - public function withConnection(IConnection $connection): GeneratedTable - { - $tableManager = new SingleConnectionTableManager($connection); - return new GeneratedTable($tableManager, $this->typeResolver); - } -} diff --git a/tests/Fixtures/PackagesTableFactory.php b/tests/Fixtures/PackagesTableFactory.php deleted file mode 100644 index 72bfcce37be7a9c4d9b4e3dda113c0157db38172..0000000000000000000000000000000000000000 --- a/tests/Fixtures/PackagesTableFactory.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/** - * Do not edit. This is generated file. Modify definition file instead. - */ - -declare(strict_types=1); - -namespace Grifart\Tables\Tests\Fixtures; - -use Dibi\IConnection; -use Grifart\Tables\SingleConnectionTableManager; -use Grifart\Tables\TableManager; -use Grifart\Tables\TypeResolver; - -final readonly class PackagesTableFactory implements \Grifart\Tables\TableFactory -{ - public function __construct( - private TableManager $tableManager, - private TypeResolver $typeResolver, - ) { - } - - - public function create(): PackagesTable - { - return new PackagesTable($this->tableManager, $this->typeResolver); - } - - - public function withTableManager(TableManager $tableManager): PackagesTable - { - return new PackagesTable($tableManager, $this->typeResolver); - } - - - public function withConnection(IConnection $connection): PackagesTable - { - $tableManager = new SingleConnectionTableManager($connection); - return new PackagesTable($tableManager, $this->typeResolver); - } -} diff --git a/tests/Scaffolding/ScaffoldingTest.phpt b/tests/Scaffolding/ScaffoldingTest.phpt index a956c0720ea2becd79ee5198a98f49b50de3929a..c484dcbca5bf23ba1b7c0ebba4b35f3ba2994385 100644 --- a/tests/Scaffolding/ScaffoldingTest.phpt +++ b/tests/Scaffolding/ScaffoldingTest.phpt @@ -34,5 +34,5 @@ $results = $fileProcessor->processFile( }, ); -Assert::count(20, $results->getDefinitions()); +Assert::count(17, $results->getDefinitions()); Assert::true($results->isSuccessful());