GithubHelp home page GithubHelp logo

spec's Introduction

#Spec A Simple Specification library for PHP

Build Status Code Climate

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

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.

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. 
}

spec's People

Contributors

greydnls avatar jeroenvdgulik avatar localheinz avatar

Stargazers

Nico Müller avatar Márcio Almada avatar Matt A avatar Carsten Brandt avatar Colin O'Dell avatar Alex Bilbie avatar James Wiens avatar Mitchell van Wijngaarden avatar Scott Robinson avatar Jacky Alciné avatar Will Murray avatar  avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.