There is no license information available for the latest version (dev-master) of this package.

dev-master 2015-11-27 13:56 UTC

This package is auto-updated.

Last update: 2020-02-14 14:31:54 UTC


The ArpSpecification module is an implementation of the Specification Pattern for PHP 5.4+; an expressive and flexible data selection pattern that can greatly reduce the complexity of business logic, with a fluid, testable and easy to understand API.


  • PHP 5.6+ (v2.*)
  • PHP 5.4+ (v1.*)


Installation via composer dependency manager

For php 5.6+

> php composer.phar require alex-patterson-webdev/arp-specification : "v2.*",

For PHP 5.4+

> php composer.phar require alex-patterson-webdev/arp-specification : "v1.*",

Comparison Specifications

Comparison specification compare one value to another; these represent the simplest form of validation.

  • IsEqual, IsNotEqual, IsNull, IsLessThan, IsGreaterThanOrEqualTo

    $spec = new IsEqual(1, 1); $spec->isSatisfied(); // true

    $spec = new IsNotEqual(1, 2); $spec->isSatisfied(); // true


The true power of specifications comes from composition; we can combine specifications together using logical operators.

  • AndX, OrX

A specification that is composed of one or more specifications. In order to be considered satisfied, all composed specifications should return true.

$spec = new AndX(
    new IsEqual(1, 1),
    new IsNotEqual(7, 4)
$spec->isSatisfied($spec); // true

// Which is the same as a PHP if statement
if (1 == 1 && 7 != 4) {


A factory class is included to provide convenience for creating specifications.

$sf = new \ArpSpecification\Spec\Factory;

$spec = new $sf->andX($sf->eq(1,1),$sf->neq(7,4));