2017 © Pedro PelĂĄez
 

library spec

Specification pattern

image

danfekete/spec

Specification pattern

  • Thursday, November 3, 2016
  • by danfekete
  • Repository
  • 1 Watchers
  • 0 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 5 % Grown

The README.md

Spec

Build Status, (*1)

Spec is a PHP implementation of the Specification pattern which can be used for building simple or complex business rules., (*2)

In computer programming, the specification pattern is a particular software design pattern, whereby business rules can be recombined by chaining the business rules together using boolean logic. The pattern is frequently used in the context of domain-driven design., (*3)

https://en.wikipedia.org/wiki/Specification_pattern, (*4)

The library uses the incredible expression-language component from Symfony to provide the DSL for expressions., (*5)

Installation

$ composer require danfekete/spec, (*6)

Usage

1. Simple expression

$d = [2];
$spec = new Specification(new ExpressionSpec('1 > d[0]'));
$spec->isSatisfiedBy(['d' => $d]); // return false

2. Boolean chaining

/*
 * You can use classes in expression code
*/
class Nan {

    public function isNan($value)
    {
        return is_nan($value);
    }

}

$spec = new Specification(new AndSpec(
    new NotSpec(new ExpressionSpec('checker.isNan(d)')),
    new OrSpec(
        new ExpressionSpec('d != 12'),
        new ExpressionSpec('d > 10')
    ),
    new AndSpec(
        new ExpressionSpec('d > 5'),
        new ExpressionSpec('d < 20')
    )
));

$spec->isSatisfiedBy(['d' => 17, 'checker' => new Nan()]); // return true

TODO

  1. Cache parsed code permanently
  2. ~~Array builder, builds specification from arrays~~
  3. ~~JSON builder~~

License

MIT, see LICENSE, (*7)

The Versions

03/11 2016

dev-master

9999999-dev

Specification pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Fekete

03/11 2016

0.3.2

0.3.2.0

Specification pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Fekete

14/06 2016

0.3.1

0.3.1.0

Specification pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Fekete

14/06 2016

0.3

0.3.0.0

Specification pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Fekete

26/05 2016

0.2

0.2.0.0

Specification pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Fekete

25/05 2016

0.1

0.1.0.0

Specification pattern

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Fekete