sirix / cycle-orm-factory
Cycle ORM Factories for Mezzio
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
- cycle/annotated: ^4.4
- cycle/database: ^2.15
- cycle/orm: ^2.12.3
- spiral/tokenizer: ^2.14 || ^3.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8
- cycle/entity-behavior: ^1.7
- cycle/migrations: ^4.2
- cycle/schema-migrations-generator: ^2.3
- mockery/mockery: ^1.6
- phpstan/phpstan-mockery: ^1.1
- phpunit/phpunit: ^11.5
- symfony/console: ^7.3
Suggests
- cycle/entity-behavior: Optional: Entity behavior package for behavior-driven entity mapping
- cycle/entity-behavior-uuid: Optional: UUID behavior extensions for cycle/entity-behavior
- cycle/migrations: Optional: Database migrations runtime (Migrator). Required to run migration commands
- cycle/schema-migrations-generator: Optional: Generate migration files from schema changes
- laminas/laminas-cli: Optional: Provides convenient CLI integration for Laminas/Mezzio applications
- sirix/cycle-orm-extensions: Optional: Practical extensions for Cycle ORM: base repositories, entity traits, typecasts, and more
- symfony/console: Optional: Required only for built-in CLI commands
This package is auto-updated.
Last update: 2026-03-09 14:45:31 UTC
README
Migration guides:
Factories for integrating Cycle ORM into Mezzio with a runtime-focused schema pipeline.
Installation
composer require sirix/cycle-orm-factory
Optional packages:
symfony/console: required for built-in CLI commands.laminas/laminas-cli: optional CLI integration for Mezzio/Laminas.cycle/migrations: required for migration runtime commands.cycle/schema-migrations-generator: required forcycle:schema:migration:generate.cycle/entity-behaviorandcycle/entity-behavior-uuid: optional behavior events; runtime falls back to default Cycle command generator if not installed.
Configuration
Create config/autoload/cycle-orm.global.php:
<?php declare(strict_types=1); use Cycle\Database\Config; use Cycle\ORM\Mapper\Mapper; use Cycle\ORM\Relation; use Cycle\ORM\SchemaInterface; return [ 'cycle' => [ 'db-config' => [ 'default' => 'default', 'databases' => [ 'default' => [ 'connection' => 'mysql', ], ], 'connections' => [ 'mysql' => new Config\MySQLDriverConfig( connection: new Config\MySQL\TcpConnectionConfig( database: 'cycle-orm', host: '127.0.0.1', port: 3306, user: 'cycle', password: 'password', ), reconnect: true, timezone: 'UTC', queryCache: true, ), ], ], 'migrator' => [ 'directory' => 'db/migrations', 'table' => 'migrations', 'seed_directory' => 'db/seeds', 'namespace' => 'App\\Migrations', // optional 'vendor_directories' => ['vendor/path'], // optional 'safe' => false, // optional ], 'entities' => [ 'src/App/src/Entity', ], 'generators' => [ // 'my.custom.generator.service', // \App\Cycle\Schema\Generator\MyCustomGenerator::class, // new \App\Cycle\Schema\Generator\InlineGenerator(), ], 'schema' => [ 'cache' => [ 'enabled' => true, ], 'compiled' => [ 'path' => 'data/cache/cycle/schema.php', ], 'manual_mapping_schema_definitions' => [ 'user' => [ SchemaInterface::ENTITY => User::class, SchemaInterface::MAPPER => Mapper::class, SchemaInterface::DATABASE => 'default', SchemaInterface::TABLE => 'user', SchemaInterface::PRIMARY_KEY => 'id', SchemaInterface::COLUMNS => [ 'id' => 'id', 'email' => 'email', ], SchemaInterface::TYPECAST => [ 'id' => 'int', ], SchemaInterface::RELATIONS => [ 'profile' => [ Relation::TYPE => Relation::HAS_ONE, Relation::TARGET => 'profile', Relation::SCHEMA => [ Relation::CASCADE => true, Relation::INNER_KEY => 'id', Relation::OUTER_KEY => 'user_id', ], ], ], ], ], ], ], ];
Runtime schema contract (v3)
Runtime behavior is controlled by cycle.schema.cache.enabled.
When true:
- ORM tries to load compiled schema from
cycle.schema.compiled.path. - If file exists: schema is loaded via
requireand ORM is created. - If file is missing: schema is compiled on first start, persisted to file, then reused.
When false:
- Schema is compiled on every start in memory.
- No compiled schema file is read or written by runtime.
Recommended production setup:
- keep
cache.enabled=true - run
cycle:schema:compileduring build/release.
Additional schema generators
cycle.generators supports:
- service ID from container,
- generator FQCN with zero-arg constructor,
- direct instance implementing
Cycle\Schema\GeneratorInterface.
Invalid entries throw Cycle\ORM\Exception\ConfigException.
Manual mapping key compatibility
Primary key is cycle.schema.manual_mapping_schema_definitions.
For migration compatibility, the package also reads legacy key:
cycle.schema.manual_entity_schema_definition
Use the new key for all new configs.
Services
Aliases provided by ConfigProvider:
orm->Cycle\ORM\ORMInterfacedbal->Cycle\Database\DatabaseInterfacemigrator->Sirix\Cycle\Service\MigratorInterface
CLI commands
Commands are registered only when symfony/console is installed.
cycle:schema:* commands:
cycle:schema:compile: compile schema and store compiled file.cycle:schema:sync: run sync pipeline; refresh compiled file only when cache is enabled.cycle:schema:migration:generate: generate migrations via schema pipeline; available only withcycle/migrationsandcycle/schema-migrations-generator, and when migrations are not disabled by env.
Other commands:
cycle:cache:clear: remove compiled schema file.cycle:migration:runcycle:migration:rollbackcycle:migration:createcycle:seed:createcycle:seed:run
Migration/seed command availability:
- registered only when
cycle/migrationsis installed, - can be force-disabled by
CYCLE_MIGRATIONS_DISABLED=1|true|yes|on.
Create migration notes
cycle:migration:create supports --database (-b).
Generated filename includes database alias:
<timestamp>_0_<counter>_<database-alias>_<migration_name_in_snake_case>.php
CLI usage examples
With laminas-cli:
php vendor/bin/laminas cycle:schema:compile php vendor/bin/laminas cycle:schema:sync php vendor/bin/laminas cycle:migration:create CreateUsers --database default
With standalone Symfony Console (manual command wiring in your app):
php bin/console cycle:schema:compile
Performance note
Compiled schema is stored as plain PHP and loaded by require, which works well with OPcache and avoids PSR-6 serialization overhead in runtime hot paths.