atyagi/specifier

一个帮助实现规范设计模式的库

v1.0.0 2015-06-28 20:00 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:42:53 UTC


README

Build Status Coverage Status Latest Version

提供了一组基本的类,以利用规范设计模式。

使用方法

包含的测试提供了类的常见用法。

基本用法

在创建规范类时,只需扩展AbstractSpecification类并实现isSatisfiedBy方法。

您创建的任何规范都足够灵活,可以接受构造函数中的任何参数,例如存储库或服务。

此外,还提供了一个isNotSatisfiedBy方法,以提供所需的逻辑非。

组合用法

当您需要在同一对象上链式调用多个规范时,可以利用AbstractSpecification的链式方法pluseither

例如

(new CustomerIsPremium())
    ->either(new CustomerRegisteredBeforeLastWeek())
    ->isSatisfiedBy($customer);

(new CustomerIsPremium())
    ->plus(new CustomerRegisteredBeforeLastWeek())
    ->isSatisfiedBy($customer);