定制 david-garcia/value-object 二次开发

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

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

david-garcia/value-object

Composer 安装命令:

composer require david-garcia/value-object

包简介

Just another library to handle Value Objects and prevent the bad habit of Primitive Obsession

README 文档

README

Just another library to handle Value Objects and prevent the bad habit of Primitive Obsession

Latest Version Build Status Code Coverage Quality Score Total Downloads

Changelog

All notable changes to this project will be documented in this ChangeLog file.

Install

Require the vendor with Composer:

composer require david-garcia/value-object

Usage

Make sure you are loading the Composer autoload:

require 'vendor/autoload.php';

Don't forget adding the use statement for each one of the value objects you need to use:

// Example for StringValue
use DavidGarcia\ValueObject\Primitive\StringValue;

All value objects have a static create() method:

StringValue::create('qwerty');

The first argument is the value to be wrapped by the value object. The second argument allows you to statically cache the value object, so you can instantiate twice an object with the same value but the system will create it just once:

$stringValue1 = StringValue::create('qwerty', true);
$stringValue2 = StringValue::create('qwerty', true);

if ($stringValue1 === $stringValue2) {
    // TRUE
    // It's the same object, so it goes inside this conditional
}

$stringValue3 = StringValue::create('qwerty');
$stringValue4 = StringValue::create('qwerty');

if ($stringValue3 === $stringValue4) {
    // FALSE
    // Although they have the same value, the system has created two different objects
}

Null values always hold a null value:

// `NullValue` does not expect any argument
$nullValue = NullValue::create();

All value objects have a getValue() method to expose the value:

$stringValue = StringValue::create('qwerty');
$stringValue->getValue(); // Returns 'qwerty'

The StringValue value object and any other that extends from this one can use the __toString magic method to return the string value, as an alternative to the getValue() method:

$stringValue = StringValue::create('qwerty');
(string) $stringValue; // Returns 'qwerty'

All value objects (except NullValue) have an equals() method that compares the content of two value objects of the same type:

$stringValue1 = StringValue::create('qwerty', true);
$stringValue2 = StringValue::create('qwerty', true);

if ($stringValue1->equals($stringValue2)) {
    // TRUE
    // We ignore the fact that is a cached object, as we compare the value
}

$stringValue3 = StringValue::create('qwerty');
$stringValue4 = StringValue::create('qwerty');

if ($stringValue3->equals($stringValue4)) {
    // TRUE
    // We have a match for the values, so even if we handle two different objects,
    // their values are equal
}

david-garcia/value-object 适用场景与选型建议

david-garcia/value-object 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 02 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 david-garcia/value-object 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-09