phpgears/aggregate
Composer 安装命令:
composer require phpgears/aggregate
包简介
Aggregate base
关键字:
README 文档
README
Aggregate
Aggregate base
Installation
Composer
composer require phpgears/aggregate
Usage
Require composer autoload file
require './vendor/autoload.php';
Aggregate identity
Aggregate identities are provided by gears/identity, head over there to learn about them
Aggregate root
Aggregate roots should implement Gears\Aggregate\AggregateRoot interface. You can extend from Gears\Aggregate\AbstractAggregateRoot for simplicity
use Gears\Aggregate\AbstractAggregateRoot; use Gears\Identity\Identity; class CustomAggregate extends AbstractAggregateRoot { public static function instantiate(Identity $identity): self { return new self($identity); } }
Mind that AbstractAggregateRoot constructor is protected forcing you to create static named constructors methods
Entities
Entities can implement Gears\Aggregate\Entity interface. You can extend from Gears\Aggregate\AbstractEntity for simplicity
Events
Aggregate roots can record gears/event as operations are performed
use Gears\Aggregate\AbstractAggregateRoot; use Gears\Identity\Identity; class CustomAggregate extends AbstractAggregateRoot { public static function instantiate(Identity $identity): self { return new self($identity); } public function doSomething(): void { // do something $this->recordEvent(new SomethingHappened()); } }
These events could be collected afterwards and sent to an event bus such as gears/event
$customAggregate = CustomAggregate::instantiate( UuidIdentity::fromString('4c4316cb-b48b-44fb-a034-90d789966bac') ); $customAggregate->doSomething(); foreach ($customAggregate->collectRecordedEvents() as $event) { /** @var \Gears\Event\EventBus $eventBus */ $eventBus->dispatch($event); }
Contributing
Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before.
See file CONTRIBUTING.md
License
See file LICENSE included with the source code for a copy of the license terms.
统计信息
- 总下载量: 242
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-12-05