Skip to content

Instantly share code, notes, and snippets.

@frankdejonge
Created June 22, 2015 15:06
Show Gist options
  • Save frankdejonge/354fa45dd9d786875962 to your computer and use it in GitHub Desktop.
Save frankdejonge/354fa45dd9d786875962 to your computer and use it in GitHub Desktop.
<?php
class Any implements Specification
{
private $specifications = [];
public function __construct(array $specifications = [])
{
$this->specifications = $specifications;
}
public function isSatisfiedBy($payload)
{
foreach ($this->specifications as $specification) {
if ($specification->isSatisfiedBy($payload)) {
return true;
}
}
return empty($this->specifications);
}
}
class All implements Specification
{
private $specifications = [];
public function __construct(array $specifications = [])
{
$this->specifications = $specifications;
}
public function isSatisfiedBy($payload)
{
foreach ($this->specifications as $specification) {
if (! $specification->isSatisfiedBy($payload)) {
return false;
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment