Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"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",
Expand Down
9 changes: 0 additions & 9 deletions src/Cycle/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@

namespace App\Cycle;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;

#[Entity(table: 'Users', database: 'default')]
class User
{
#[Column(type: 'primary')]
private int $id;

public function __construct(
#[Column(type: 'string')]
private string $name,
#[Column(type: 'integer')]
private int $age,
#[Column(type: 'float')]
private float $microtime,
#[Column(type: 'timestamp')]
private \DateTimeImmutable $created_at = new \DateTimeImmutable(),
) {}

Expand Down
37 changes: 16 additions & 21 deletions src/test-cycle.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php declare(strict_types=1);

include 'init.php';

use App\Cycle\User;
use Cycle\Schema;
use Cycle\Annotated;
use Cycle\Database;
use Cycle\Database\Config;
use Cycle\ORM;
Expand All @@ -29,25 +28,21 @@
])
);

$finder = (new \Symfony\Component\Finder\Finder())->files()->in([__DIR__ . '/Cycle']); // __DIR__ here is folder with entities
$classLocator = new \Spiral\Tokenizer\ClassLocator($finder);

$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\TableInheritance(), // register STI/JTI
new Annotated\MergeColumns(), // add @Table column declarations
new Schema\Generator\GenerateRelations(), // generate entity relations
new Schema\Generator\GenerateModifiers(), // generate changes from schema modifiers
new Schema\Generator\ValidateEntities(), // make sure all entity schemas are correct
new Schema\Generator\RenderTables(), // declare table schemas
new Schema\Generator\RenderRelations(), // declare relation keys and indexes
new Schema\Generator\RenderModifiers(), // render all schema modifiers
new Annotated\MergeIndexes(), // add @Table column declarations
new Schema\Generator\SyncTables(), // sync table changes to database
new Schema\Generator\GenerateTypecast(), // typecast non string columns
]);
$schema = [
'user' => [
ORM\SchemaInterface::ENTITY => User::class,
ORM\SchemaInterface::DATABASE => 'default',
ORM\SchemaInterface::TABLE => 'Users',
ORM\SchemaInterface::PRIMARY_KEY => ['id'],
ORM\SchemaInterface::COLUMNS => ['id', 'name', 'age', 'microtime', 'created_at'],
ORM\SchemaInterface::TYPECAST => [
'id' => 'int',
'age' => 'int',
'microtime' => 'float',
'created_at' => 'datetime',
],
],
];
$orm = new ORM\ORM(
factory: new ORM\Factory($dbal),
schema: new ORM\Schema($schema),
Expand Down