pauci/cqrs 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pauci/cqrs

最新稳定版本:v0.7.1

Composer 安装命令:

composer require pauci/cqrs

包简介

CQRS library

README 文档

README

Source Code PHP Latest Version Build Status Coverage Status Software License Total Downloads

Installation & Requirements

The core library has no dependencies on other libraries. Plugins have dependencies on their specific libraries.

Install with composer:

composer require pauci/cqrs

Usage

final class User extends \CQRS\Domain\Model\AbstractEventSourcedAggregateRoot
{
    private int $id;
    private string $name;

    public static function create(int $id, string $name): self
    {
        $user = new self($id);
        $user->apply(new UserCreated($name));
        return $user;
    }

    private function __construct(int $id)
    {
        $this->id = $id;
    }

    protected function applyUserCreated(UserCreated $event): void
    {
        $this->name = $event->getName();
    }

    public function getId(): int
    {
        return $this->id;
    }

    public function changeName(string $name): void
    {
        if ($name !== $this->name) {
            $this->apply(new UserNameChanged($name));
        }
    }

    protected function applyUserNameChanged(UserNameChanged $event): void
    {
        $this->name = $event->getName();
    }
}

final class UserCreated
{
    private string $name;

    public function __construct(string $name)
    {
        $this->name = $name;
    }

    public function getName(): string
    {
        return $this->name;
    }
}

final class ChangeUserName
{
    public int $id;
    public string $name;
}

final class UserNameChanged
{
    private string $name;

    public function __construct(string $name)
    {
        $this->name = $name;
    }
    
    public function getName(): string
    {
        return $this->name;
    }
}

class UserService
{
    protected $repository;

    public function __construct($repository)
    {
        $this->repository = $repository;
    }

    public function changeUserName(ChangeUserName $command): void
    {
        $user = $this->repository->find($command->id);
        $user->changeName($command->name);
    }
}

class EchoEventListener
{
    public function onUserNameChanged(
        UserNameChanged $event,
        \CQRS\Domain\Message\Metadata $metadata,
        \DateTimeInterface $timestamp,
        int $sequenceNumber,
        int $userId
    ): void {
        echo "Name of user #{$userId} changed to {$event->getName()}.\n";
    }
}

$command = new ChangeUserName([
    'id' => 1,
    'name' => 'Jozko Mrkvicka',
]);
$commandBus->dispatch($command);

统计信息

  • 总下载量: 25.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 3
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固