cycle / orm-promise-mapper
Promise mapper for Cycle ORM
2.0.0
2026-11-21 22:22 UTC
Requires
- php: >=8.2
- cycle/orm: ^2.19
- doctrine/instantiator: ^2.0
- symfony/polyfill-php83: ^1.33
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8
- buggregator/trap: ^1.20
- cycle/testing: ^0.1.2
- llm/skills: ^1.20
- roxblnfk/unpoly: ^1.8
- spiral/tokenizer: ^3.18
- testo/testo: ^0.10.60
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-22 10:15:30 UTC
README
Promise mapper for Cycle ORM
With cycle/orm-promise-mapper, Cycle ORM hydrates entities as instances of your own classes and puts \Cycle\ORM\Reference\Promise objects into lazy-loaded relations.
Get Started
Requirements
- PHP 8.2+
Installation
composer require cycle/orm-promise-mapper
Define the Entity
use Cycle\Annotated\Annotation\Entity; use Cycle\Annotated\Annotation\Column; use Cycle\Annotated\Annotation\Relation\BelongsTo; use Cycle\Annotated\Annotation\Relation\HasMany; use Cycle\ORM\PromiseMapper\PromiseMapper; use Cycle\ORM\Reference\ReferenceInterface; #[Entity(mapper: PromiseMapper::class)] class User { #[Column(type: 'primary')] public int $id; #[HasMany(target: Post::class, load: 'eager')] public array $posts; #[HasMany(target: Tag::class, load: 'lazy')] public ReferenceInterface|array $tags; } #[Entity(mapper: PromiseMapper::class)] class Post { // ... #[BelongsTo(target: User::class, load: 'lazy')] public ReferenceInterface|User $user; #[BelongsTo(target: Tag::class, load: 'eager')] public Tag $tag; }
Fetching entity data
$user = $orm->getRepository('user')->findByPK(1); // $user->posts contains an array because of eager loading foreach ($user->posts as $post) { // ... } // $user->tags contains Cycle\ORM\Reference\Promise object because of lazy loading $tags = $user->tags->fetch(); foreach ($tags as $tag) { // ... } $post = $orm->getRepository('post')->findByPK(1); // $post->user contains Cycle\ORM\Reference\Promise object because of lazy loading $userId = $post->user->fetch()->id; // $post->tag contains Tag object because of eager loading $tagName = $post->tag->name;
Testing
Tests run on Testo through the cycle/testing harness: tests/Unit needs no
database, tests/Feature runs once per database driver. Unit and SQLite tests need no containers:
composer test:unit composer test:sqlite
The other drivers run against the shared test databases:
composer db:up # or: composer db:up -- mysql composer test # every suite; drivers whose server is down are skipped composer test:mysql # also test:postgres, test:sqlserver composer db:down