承接 lhellemons/php-value-objects 相关项目开发

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

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

lhellemons/php-value-objects

Composer 安装命令:

composer require lhellemons/php-value-objects

包简介

Classes, traits and interfaces for implementing true PHP value objects

README 文档

README

Build Status

Author: Laurens Hellemons lhellemons@gmail.com

This library contains utility classes, traits and interfaces for working with value objects in PHP. By using these, you can easily define your own value objects.

Read the full documentation here.

Why value objects?

Value objects are a core component of domain-driven design (DDD). They are objects that do not have an identity, and are instead defined by their values. Any large system that deals with domain concepts will eventually develop a need to model some of these concepts as value objects. Examples of such concepts include

  • Dates
  • Amounts of money
  • Coordinates
  • Adresses
  • Physical quantities such as age, length or weight

This library helps circumvent PHP's limited support for value objects. Using the classes, interfaces and traits provided by this package, you can create your own value objects without worrying about the internals.

Usage

Install the package using composer.

composer require lhellemons/php-value-objects

Then, use the classes or traits in your own designs.

<?php

use SolidPhp\ValueObjects\Enum\EnumTrait;

final class Weekday
{
    use EnumTrait;

    public static function MONDAY(): self
    {
        return self::define('MONDAY');
    }

    public static function TUESDAY(): self
    {
        return self::define('TUESDAY');
    }

    // ...
}

// ...

$monday = Weekday::MONDAY();
$tuesday = Weekday::TUESDAY();
$deliveryDay = WeekDay::MONDAY();

$monday === $deliveryDay; // true
$monday === $tuesday; // false
use SolidPhp\ValueObjects\Value\ValueObjectTrait;

final class EmailAddress
{
    use ValueObjectTrait;

    /** @var string */
    private $emailAddressString;

    private function __construct(string $emailAddressString)
    {
        $this->emailAddressString = $emailAddressString;
    }

    public function of(string $emailAddressString): self
    {
        $normalizedString = strtolower(trim($emailAddressString));
        return static::getInstance($normalizedString);
    }

    public function getString(): string
    {
        return $this->emailAddressString;
    }
}

// ...

$emailAddress = EmailAddress::of("annie@email.com");
$sameEmailAddress = EmailAddress::of(" ANNIE@EMAIL.COM");

$emailAddress === $sameEmailAddress; // true

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固