2017 © Pedro Peláez
 

library spec

Specification in PHP

image

kayladnls/spec

Specification in PHP

  • Wednesday, October 21, 2015
  • by greydnls
  • Repository
  • 0 Watchers
  • 13 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Spec

A Simple Specification library for PHP, (*1)

Build Status Code Climate, (*2)

Installation

composer require kayladnls/spec

What is it?

"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." -- wikipedia, (*3)

How do I use it?

Use the builder

$all_spec = Kayladnls/Spec/Builder::all(new MustHaveFourLegs(), new MustHaveStripesSpec());

$all_spec->isSatisfiedBy($elephpant) //False 
$all_spec->isSatisfiedBy($zebra)     // True

$any_spec = Kayladnls/Spec/Builder::any($all_spec, new IsLizardSpec());
$any_spec->isSatisfiedBy($iguana) // True

Or, you can use functions if that's what tickles your fancy., (*4)

Function Based

$all_spec = Kayladnls/Spec/all([new MustHaveFourLegs(), new MustHaveStripesSpec()]);

Kayladnls/Spec/satisfies($elephpant, $all_spec) //False 
Kayladnls/Spec/satisfies($zebra, $all_spec) //True 

$any_spec = Kayladnls/Spec/any([$all_spec, new IsLizardSpec()]);
Kayladnls/Spec/satisfies($iguana, $any_spec) // True

$none_spec = Kayladnls/Spec/none([new MustHaveFourLegs(), new MustHaveSpotsSpec()]);
Kayladnls/Spec/satisfies($kangaroo, $none_spec) // true
Kayladnls/Spec/satisfies($cheetah, $none_spec) // false

Example

if ($all_spec->isSatisfiedBy($zebra)){
    // Do Some cool Zebra Stuff here. 
}

// Function Based
if (satisfies($iguana, $any_spec)){
    // do some cool lizard-based stuff here. 
}

The Versions

21/10 2015

dev-master

9999999-dev

Specification in PHP

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Kayla Daniels

17/08 2015

v0.1.2

0.1.2.0

Specification in PHP

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Kayla Daniels

23/07 2015

v0.1.0

0.1.0.0

Specification in PHP

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Kayla Daniels

23/07 2015

0.1.1

0.1.1.0

Specification in PHP

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Kayla Daniels