diff --git a/composer.json b/composer.json index 01e27fd..cdb360b 100644 --- a/composer.json +++ b/composer.json @@ -13,14 +13,14 @@ ], "require": { "ext-pdo": "*", - "compositephp/db": "0.4.2", - "cycle/orm": "2.6", - "cycle/annotated": "3.4", - "cycle/entity-behavior": "1.2", - "doctrine/orm": "2.17.2", - "illuminate/database": "10.38.2", - "vlucas/phpdotenv": "5.6.0", - "symfony/cache": "7.0.0", - "phpfui/orm": "^1.7" + "compositephp/db": "^0.5", + "cycle/orm": "^2.10", + "cycle/annotated": "^4.3", + "cycle/entity-behavior": "^1.2", + "doctrine/orm": "^3.0", + "illuminate/database": "^12.0", + "vlucas/phpdotenv": "^5.6.0", + "symfony/cache": "^7.0", + "phpfui/orm": "^2.0" } } diff --git a/src/PHPFUIORM/Record/Definition/Users.php b/src/PHPFUIORM/Record/Definition/Users.php index b5db279..170d322 100644 --- a/src/PHPFUIORM/Record/Definition/Users.php +++ b/src/PHPFUIORM/Record/Definition/Users.php @@ -15,18 +15,27 @@ abstract class Users extends \PHPFUI\ORM\Record { protected static bool $autoIncrement = true; - /** @var array> */ - protected static array $fields = [ - // MYSQL_TYPE, PHP_TYPE, LENGTH, ALLOWS_NULL, DEFAULT - 'age' => ['int', 'int', 0, false, ], - 'created_at' => ['timestamp', 'string', 20, false, NULL, ], - 'id' => ['int', 'int', 0, false, ], - 'microtime' => ['float', 'float', 0, false, ], - 'name' => ['varchar(255)', 'string', 255, false, ], - ]; + /** @var array */ + protected static array $fields = []; /** @var array */ protected static array $primaryKeys = ['id', ]; protected static string $table = 'users'; + + public function initFieldDefinitions() : static + { + if (! \count(static::$fields)) + { + static::$fields = [ + 'age' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, false, ), + 'created_at' => new \PHPFUI\ORM\FieldDefinition('timestamp', 'string', 20, false, NULL, ), + 'id' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, false, ), + 'microtime' => new \PHPFUI\ORM\FieldDefinition('float', 'float', 0, false, ), + 'name' => new \PHPFUI\ORM\FieldDefinition('varchar(255)', 'string', 255, false, ), + ]; + } + + return $this; + } } diff --git a/src/test-cycle.php b/src/test-cycle.php index 2e03679..fed44f4 100644 --- a/src/test-cycle.php +++ b/src/test-cycle.php @@ -31,11 +31,13 @@ $finder = (new \Symfony\Component\Finder\Finder())->files()->in([__DIR__ . '/Cycle']); // __DIR__ here is folder with entities $classLocator = new \Spiral\Tokenizer\ClassLocator($finder); +$tokenizer = new \Cycle\Annotated\Locator\TokenizerEmbeddingLocator($classLocator); +$entityLocator = new \Cycle\Annotated\Locator\TokenizerEntityLocator($classLocator); $schema = (new Schema\Compiler())->compile(new Schema\Registry($dbal), [ new Schema\Generator\ResetTables(), // re-declared table schemas (remove columns) - new Annotated\Embeddings($classLocator), // register embeddable entities - new Annotated\Entities($classLocator), // register annotated entities + new Annotated\Embeddings($tokenizer), // register embeddable entities + new Annotated\Entities($entityLocator), // register annotated entities new Annotated\TableInheritance(), // register STI/JTI new Annotated\MergeColumns(), // add @Table column declarations new Schema\Generator\GenerateRelations(), // generate entity relations