Files
DesignPatternsPHP/Behavioral/Specification/OrSpecification.php
2017-04-12 18:01:43 +03:00

33 lines
761 B
PHP

<?php
namespace DesignPatterns\Behavioral\Specification;
class OrSpecification implements SpecificationInterface
{
/**
* @var SpecificationInterface[]
*/
private $specifications;
/**
* @param SpecificationInterface[] ...$specifications
*/
public function __construct(SpecificationInterface ...$specifications)
{
$this->specifications = $specifications;
}
/**
* if at least one specification is true, return true, else return false
*/
public function isSatisfiedBy(Item $item): bool
{
foreach ($this->specifications as $specification) {
if ($specification->isSatisfiedBy($item)) {
return true;
}
}
return false;
}
}