承接 tiny-blocks/value-object 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tiny-blocks/value-object

最新稳定版本:3.1.0

Composer 安装命令:

composer require tiny-blocks/value-object

包简介

Delimits default behaviors for Value Objects.

README 文档

README

License

Overview

A Value Object (VO) is an immutable type that is only distinguishable by the state of its properties, that is, unlike an entity, which has a unique identifier and remains distinct even if its properties are identical, VOs with the same properties can be considered the same.

Because they are immutable, VOs cannot be changed once created. Modifying one is conceptually the same as discard the old one and create a new one.

More details about VOs.

Installation

composer require tiny-blocks/value-object

How to use

The library exposes available behaviors through the ValueObject interface, and the implementation of these behaviors through the ValueObjectAdapter trait.

Concrete implementation

With the implementation of the ValueObject interface, and the ValueObjectAdapter trait, the use of __get, __set and __unset methods is suppressed, making the object immutable.

<?php

namespace Example;

use TinyBlocks\Vo\ValueObject;
use TinyBlocks\Vo\ValueObjectBehavior;

final class TransactionId implements ValueObject
{
    use ValueObjectBehavior;

    public function __construct(private readonly string $value)
    {
    }
}

Using the equals method

The equals method compares the value of two VOs, and checks if they are equal.

$transactionId = new TransactionId(value: 'e6e2442f-3bd8-421f-9ac2-f9e26ac4abd2');
$otherTransactionId = new TransactionId(value: 'e6e2442f-3bd8-421f-9ac2-f9e26ac4abd2');

$transactionId->equals(other: $otherTransactionId); # true

License

Value Object is licensed under MIT.

Contributing

Please follow the contributing guidelines to contribute to the project.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-26