mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-28 10:40:17 +02:00
36 lines
759 B
PHP
36 lines
759 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\Specification;
|
|
|
|
class AndSpecification implements Specification
|
|
{
|
|
/**
|
|
* @var Specification[]
|
|
*/
|
|
private array $specifications;
|
|
|
|
/**
|
|
* @param Specification[] $specifications
|
|
*/
|
|
public function __construct(Specification ...$specifications)
|
|
{
|
|
$this->specifications = $specifications;
|
|
}
|
|
|
|
/**
|
|
* if at least one specification is false, return false, else return true.
|
|
*/
|
|
public function isSatisfiedBy(Item $item): bool
|
|
{
|
|
foreach ($this->specifications as $specification) {
|
|
if (!$specification->isSatisfiedBy($item)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|