Skip to content
This repository was archived by the owner on Feb 24, 2019. It is now read-only.

mbrevda/SpecificationPattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Specification Pattern

Sample implementation for the Specification Pattern in PHP, based on https://en.wikipedia.org/wiki/Specification_pattern.

Usage

An example of how this might be used. Also check out the tests.

$invoices       = /* load invoices from somewhere*/;
$overDue        = new OverDueSpecification(time());
$noticeNotSent  = new NoticeNotSentSpecification();
$inCollection   = new InCollectionSpecification();

// we want a list of invoices that need to be remitted
// show all invoices that are overdue, no notice has been sent, and isn't in collection
$needsToBeRemitted = $overDue
    ->andX($noticeNotSent)
    ->andX(new NotSpecification($inCollection));

$satisfying = array_filter($invoices, function($invoice) {
    return $needsToBeRemitted->isSatisfyableBy($invoice);
})

About

A sample Specification Pattern in PHP, based on: https://en.wikipedia.org/wiki/Specification_pattern

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages