2017 © Pedro Peláez
 

library specification

Yet another specification pattern implementation

image

gbprod/specification

Yet another specification pattern implementation

  • Thursday, February 22, 2018
  • by gbprod
  • Repository
  • 2 Watchers
  • 6 Stars
  • 13,544 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 15 % Grown

The README.md

Specification

Yet another specification pattern implementation in PHP., (*1)

Build Status codecov Scrutinizer Code Quality Dependency Status, (*2)

Latest Stable Version Total Downloads Latest Unstable Version License, (*3)

Usage

Create a Specification

<?php

use GBProd\Specification\CompositeSpecification;

class PriceGreaterThan extends CompositeSpecification
{
    private $threshold;

    public function __construct($threshold)
    {
        $this->threshold = $threshold;
    }

    public function isSatisfiedBy($product): bool
    {
        return $product->getPrice() > $this->threshold;
    }
}

Compose your specifications

$expensive = new PriceGreaterThan(1000);
$available = new IsAvailable();
$hightStock = new StockGreaterThan(4);


$lowStockExpensiveProduct = $expensive
    ->andX($available)
    ->andX($hightStock->not())
;

Use it !

foreach($products as $product) {
    if ($lowStockExpensiveProduct->isSatisfiedBy($product)) {
        $this->makeSomethingAwesome($product);
    }
}

Requirements

  • PHP 7.0+

For PHP 5 compatibility, use version 1.0, (*4)

Installation

Using composer

composer require gbprod/specification

The Versions

22/02 2018

dev-master

9999999-dev

Yet another specification pattern implementation

  Sources   Download

MIT WTFPL

The Requires

  • php ^7.0

 

The Development Requires

by Avatar gbprod

22/02 2018

dev-chore/licence

dev-chore/licence

Yet another specification pattern implementation

  Sources   Download

WTFPL

The Requires

  • php ^7.0

 

The Development Requires

by Avatar gbprod

08/02 2018

v2.0.1

2.0.1.0

Yet another specification pattern implementation

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Avatar gbprod

25/06 2017

v2.0.0

2.0.0.0

Yet another specification pattern implementation

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Avatar gbprod

23/06 2017

v1.0.x-dev

1.0.9999999.9999999-dev

Yet another specification pattern implementation

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar gbprod

23/06 2017

v1.0.0

1.0.0.0

Yet another specification pattern implementation

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar gbprod

31/05 2016

v0.1.3

0.1.3.0

Yet another specification pattern implementation

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Avatar gbprod

31/05 2016

dev-release/0.1.3

dev-release/0.1.3

Yet another specification pattern implementation

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Avatar gbprod

05/03 2016

v0.1.2

0.1.2.0

Yet another specification pattern implementation

  Sources   Download

MIT

The Development Requires

by Avatar gbprod

03/03 2016

v0.1.1

0.1.1.0

Yet another specification pattern implementation

  Sources   Download

MIT

The Development Requires

by Avatar gbprod

03/03 2016

v0.1.0

0.1.0.0

Yet another specification pattern implementation

  Sources   Download

MIT

The Development Requires

by Avatar gbprod