phpgears / aggregate
聚合基础
0.2.1
2019-10-25 22:51 UTC
Requires
- php: ^7.1
- phpgears/event: ~0.3.2
- phpgears/identity: ~0.2
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.1
- friendsofphp/php-cs-fixer: ^2.0
- hashids/hashids: ^3.0
- infection/infection: ^0.9
- pascaldevink/shortuuid: ^2.1
- phpmd/phpmd: ^2.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ~0.11.12
- phpstan/phpstan-deprecation-rules: ~0.11.2
- phpstan/phpstan-strict-rules: ~0.11.1
- phpunit/phpunit: ^7.0|^8.0
- povils/phpmnd: ^2.0
- roave/security-advisories: dev-master
- sebastian/phpcpd: ^4.0
- squizlabs/php_codesniffer: ^3.0
- thecodingmachine/phpstan-strict-rules: ^0.11.2
Suggests
- hashids/hashids: for hashed UUID based identities
- pascaldevink/shortuuid: for short UUID based identities
This package is auto-updated.
Last update: 2024-09-17 06:56:34 UTC
README
聚合
聚合基础
安装
Composer
composer require phpgears/aggregate
用法
需要composer自动加载文件
require './vendor/autoload.php';
聚合身份
聚合身份由gears/identity提供,前往那里了解相关信息
聚合根
聚合根应该实现Gears\Aggregate\AggregateRoot
接口。为了简单起见,你可以从Gears\Aggregate\AbstractAggregateRoot
扩展
use Gears\Aggregate\AbstractAggregateRoot; use Gears\Identity\Identity; class CustomAggregate extends AbstractAggregateRoot { public static function instantiate(Identity $identity): self { return new self($identity); } }
请注意,AbstractAggregateRoot构造函数是受保护的,这强制你创建静态命名构造函数方法
实体
实体可以实现Gears\Aggregate\Entity
接口。为了简单起见,你可以从Gears\Aggregate\AbstractEntity
扩展
事件
在执行操作时,聚合根可以记录gears/event
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()); } }
这些事件可以在之后收集并发送到事件总线,例如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.md文件
许可
请参阅源代码中包含的LICENSE文件,以获取许可证条款的副本。