best-served-cold/phalue-objects 问题修复 & 功能扩展

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

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

best-served-cold/phalue-objects

最新稳定版本:v0.0.11-alpha

Composer 安装命令:

composer require best-served-cold/phalue-objects

包简介

Phalue Objects - PHP Value Objects

README 文档

README

Build Status Scrutinizer Quality Score Code Coverage SensioLabsInsight

A generic set of PHP Value Objects for use in any project.

Wikipedia

When people exchange business cards, they generally do not distinguish between each unique card; they only are concerned about the information printed on the card. In this context, business cards are value objects.

Table of contents

Installation

composer require best-served-cold/phalue-objects

Philosophy

To make this code consistent, we've stuck to a certain set of restrictions:

Rules

Disclaimer: This is my interpretation of "The rules".

Must be immutable

The value object's value must be set at the time of construction. At no point should the value be mutated within the object.

Must contain one value

The value object can only be constructed from one value, this can be any of the following types:

  • boolean
  • integer
  • float/double
  • string
  • array
  • object
  • resource
  • null

Can instantiate new object from value

Rather than mutating, a new object can be instantiated from an existing one.

Example:

//...
public function double() 
{
    return new static($this->getValue() * 2);
}
...//

Can be created from multiple arguments

Instead of an object having multiple object properties, it should be created from multiple arguments.

Example:

//...
public static function fromVars($one = 1, $two = 2, $three = 3)
{
    return new static([$one, $two, $three]); 
}
...//

Can be equal regardless of object

The type of a value object is irrelevant to equality:

Example:

//...
$bob = $stringValueObject->equals($csvValueObject);
...//

$bob is true where the type and value are equal.

Must have a zero lifespan

Value objects must not persist data between run times. For example: no database or session information should be collected from within the object.

Conventions

Follow PSR-FIG rules.

Constructor

Example:

new SomeClass('value');
  • Must only have one argument of any type

Creation methods (From)

Example:

SomeClass::fromSomeObject($someObject);
  • Always start with "from"
  • Must be static
  • Can contain multiple arguments
  • Must return new static instance

Conversion methods (To)

Example:

$someObject->toArray();
  • Always start with "to"
  • Must not be static
  • Must have zero arguments
  • Must return new static instance

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固