定制 robin-malfait/event-sourcing 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

robin-malfait/event-sourcing

Composer 安装命令:

composer require robin-malfait/event-sourcing

包简介

An EventSourcing Package

README 文档

README

Software License

This is a simple EventSourcing package that you can use in your projects. This project is written using PSR2

Install

Via Composer

$ composer require robin-malfait/event-sourcing

Usage

Register the service provider

'providers' => [
    ...
    \EventSourcing\Laravel\EventSourcingServiceProvider::class,
]

Publish the configuration file

php artisan vendor:publish --provider="EventSourcing\Laravel\EventSourcingServiceProvider"

The config file looks like this:

Config File

You can now tweak some configurations

Last but not least make the event store table:

php artisan event-sourcing:table

Update v1 to v2

If you are still using the first version you better update to version 2. You will have less problems in the future, I promise.

In Version 2 we give each DomainEvent the responsibility to give data and receive data. Those methods are

serialize(); Which returns an array of serialized data

deserialize(array $data); Which has a parameter with the data that basically comes from the serialize method. This method should also return an instance of the current event.

For Example:

<?php namespace App\Users\Events;

use EventSourcing\Domain\DomainEvent;

class UserWasRegistered implements DomainEvent
{
    private $user_id;

    private $email;

    private $password; // Yes, this is encrypted

    public function __construct($user_id, $email, $password)
    {
        $this->user_id = $user_id;
        $this->email = $email;
        $this->password = $password;
    }

    /**
     * @return UserId
     */
    public function getAggregateId()
    {
        return $this->user_id;
    }

    public function getMetaData() 
    {
        return []; // Could be for example the logged in user, ...
    }

    /**
     * @return array
     */
    public function serialize()
    {
        return [
            'user_id' => $this->user_id,
            'email' => $this->email,
            'password' => $this->password
        ];
    }

    /**
     * @param array $data
     * @return mixed
     */
    public static function deserialize(array $data)
    {
        return new static(
            $data['user_id'],
            $data['email'],
            $data['password']
        );
    }
}

Once you have defined every serialize / deserialize method in your events you can start the migration process.

In your database rename eventstore to eventstore_backup

Now you can run the following command in your terminal:

php artisan event-sourcing:table

This will create the eventstore, now you should see 2 tables in your database

  1. eventstore_backup => Your old table with all data in
  2. eventstore => Your new empty table

I also have written a helper method to do the migration now.

php artisan event-sourcing:1to2 eventstore_backup eventstore

Or you can also just run the following command because eventstore_backup and eventstore are the defaults.

php artisan event-sourcing:1to2

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email malfait.robin@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

robin-malfait/event-sourcing 适用场景与选型建议

robin-malfait/event-sourcing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 126 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「cqrs」 「EventSourcing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 robin-malfait/event-sourcing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 robin-malfait/event-sourcing 我们能提供哪些服务?
定制开发 / 二次开发

基于 robin-malfait/event-sourcing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 126
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-25