mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-28 18:50:11 +02:00
31 lines
682 B
PHP
31 lines
682 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;
|
|
}
|
|
|
|
public function isSatisfiedBy(Item $item): bool
|
|
{
|
|
$satisfied = [];
|
|
|
|
foreach ($this->specifications as $specification) {
|
|
$satisfied[] = $specification->isSatisfiedBy($item);
|
|
}
|
|
|
|
return in_array(true, $satisfied);
|
|
}
|
|
}
|