定制 premiervirtual/complex-heart 二次开发

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

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

premiervirtual/complex-heart

Composer 安装命令:

composer require premiervirtual/complex-heart

包简介

Domain driven design tools.

README 文档

README

Latest Stable Version License Tests codecov

About

The Complex Heart name stands from "Domain-Driven Design: Tackling Complexity in the Heart of Software" Eric Evans Book. This project intends to provide a set of useful classes and tools to ease the adoption of Domain Driven Design into your project.

Domain Modeling: Aggregates, Entities and Value Objects

Complex Heart allows you to model your domain Aggregates, Entities, and Value Objects using a set of traits. Great, but why traits and not classes? Well, sometimes you have some kind of inheritance in your classes. Being forced to use a certain base class is too invasive and personally, I don't like it. By using a set of traits and interfaces you have all the functionality you need without compromising the essence of your own domain.

Let's see a very basic example:

use OtherCode\ComplexHeart\Domain\Contracts\ValueObject;
use OtherCode\ComplexHeart\Domain\Traits\IsValueObject;

/**
 * Class Color
 * @method string value()
 */
final class Color implements ValueObject 
{
    use IsValueObject;
    
    private string $value;
 
    public function __construct(string $value) {
        $this->initialize(['value' => $value]);
    }
    
    protected function invariantValueMustBeHexadecimal(): bool {
        return preg_match('/^#(?:[0-9a-fA-F]{3}){1,2}$/', $this->value) === 1;
    }
    
    public function __toString(): string {
        return $this->value();
    }
}

$red = new Color('#ff0000');
$red->equals(new Color('#00ff00')); // false
$red->value(); // #ff0000
$magenta = new Color('ff00ff'); // Exception InvariantViolation: Value must be hexadecimal.

To define a Value Object you only need to use the IsValueObject trait, this will allow you to use some functions like equals() that will automatically compare the value of the objects or initialize() that will allow you to run invariant validations against the object values. Optionally, and recommended, you can use the ValueObject interface.

The available traits are:

  • HasAttributes Provide some functionality to manage attributes.
  • HasEquality Provide functionality to handle equality between objects.
  • HasInvariants Allow invariant checking on instantiation (Guard Clause).
  • HasIdentity Define the Entity/Aggregate identity.
  • HasDomainEvents Provide domain event management.

On top of those base traits Complex Heart provide ready to use compositions:

  • IsModel composed by HasAttributes and HasInvariants
  • IsValueObject composed by IsModel and HasEquality
  • IsEntity composed by IsModel, HasIdentity, HasEquality
  • IsAggregate composed by IsEntity, HasDomainEvents

Service Bus: Commands, Queries and Events

The Service Bus integration contains some basic interfaces (ServiceBus, CommandBus, QueryBus, and EventBus) and classes to build on top of them.

  • Message Base DTO to transfer objects between layers.
    • Request
      • Command Command DTO.
      • Event Event DTO.
      • Query Query DTO.
    • Response

Check this small example of the usage:

$response = $queryBus->ask(new GetUserQuery('some-uuid-value'));

Check the wiki for more detailed examples.

References

premiervirtual/complex-heart 适用场景与选型建议

premiervirtual/complex-heart 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.64k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 premiervirtual/complex-heart 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-12