mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-20 16:27:31 +02:00
36 lines
754 B
PHP
36 lines
754 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\Specification;
|
|
|
|
class OrSpecification implements Specification
|
|
{
|
|
/**
|
|
* @var Specification[]
|
|
*/
|
|
private array $specifications;
|
|
|
|
/**
|
|
* @param Specification[] $specifications
|
|
*/
|
|
public function __construct(Specification ...$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;
|
|
}
|
|
}
|