承接 biberlabs/ddd-embeddables 相关项目开发

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

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

biberlabs/ddd-embeddables

Composer 安装命令:

composer require biberlabs/ddd-embeddables

包简介

A collection of re-usable value objects ready to use as Embeddable in Doctrine entities

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage

A collection of reusable value objects written in PHP and targeting versions 8.0 and above. Value objects are essential building blocks of Domain Driven Design approach and described by Martin Fowler in P of EAA page 486 as below:

"Value object is a small simple object, like money or a date range, whose equality isn't based on identity."

– Martin Fowler

All classes in this library annotated as ORM\Embeddable with appropriately adjusted column attributes. This makes them ready to use in any project with Doctrine ORM as Embeddables.

Installation & Usage

Install the library using composer.

$ composer require biberlabs/ddd-embeddables

and use it in your entities:

<?php

namespace MyApp\Entity;

use Doctrine\ORM\Mapping as ORM;
use DDD\Embeddable\EmailAddress;

/**
 * @ORM\Entity
 */
class User {

    /**
     * @ORM\Embedded(class="DDD\Embeddable\EmailAddress")
     */
    private $email;

    // Returns an EmailAddress instance, not a string
    public function getEmail();

    // Use type-hinting if you need a setter
    public function setEmail(EmailAddress $email);
}

Afterwards, you can write custom DQL queries based on your requirements while accessing properties of the value objects such as:

SELECT u FROM User u WHERE u.email = :email
-- OR
SELECT p FROM Payments p WHERE p.total.currency = :currency
SELECT p FROM Payments p WHERE p.total.amount > 1000
-- OR
SELECT u FROM User u WHERE u.name.surname = :surname
SELECT u FROM User u WHERE u.name.title = :title

Value objects enables us to write much more cleaner and readable rules when dealing with the domain rules, application-wide. For example:

$username  = $user->getEmail()->getLocalpart();

or

$blacklist = ['spam4me.io', 'foo.com'];
if(in_array($user->getEmail()->getDomain(), $blacklist)) {
   // ...
}

even

if($company->hasMap()) {
    $latLng = $company->getAddress()->getGeoPoint()->toArray();
    //..
}

class Company
{
    // ...
       
    /**
     * Returns a boolean TRUE if the geolocation of the company is known,
     * FALSE otherwise.
     *
     * @return bool
     */
    public function hasMap()
    {
        return $this->getAddress()->getGeoPoint() !== null;
    }
}

Running Tests

You can run unit tests locally via issuing the command below:

$ composer test

Please make sure that all test are green before creating a PR.

PHPUnit 9.5.25 #StandWithUkraine

................................................................. 65 / 75 ( 86%)
..........                                                        75 / 75 (100%)

Time: 00:00.037, Memory: 6.00 MB

OK (75 tests, 124 assertions)

Contributing

If you want to contribute to ddd-embeddables and make it better, your help is very welcome.

Please take a look our CONTRIBUTING.md before creating a pull request.

Further Reading

Are you interested in Domain Driven Design? Here is a list of good resources to dig in-depth.

统计信息

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

GitHub 信息

  • Stars: 65
  • Watchers: 7
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固