All Projects → mbrevda → SpecificationPattern

mbrevda / SpecificationPattern

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

Programming Languages

PHP
23972 projects - #3 most used programming language

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);
})
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].