mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-24 09:42:24 +01:00
35 lines
791 B
PHP
35 lines
791 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\Specification;
|
|
|
|
class AndSpecification implements SpecificationInterface
|
|
{
|
|
/**
|
|
* @var SpecificationInterface[]
|
|
*/
|
|
private $specifications;
|
|
|
|
/**
|
|
* @param SpecificationInterface[] ...$specifications
|
|
*/
|
|
public function __construct(SpecificationInterface ...$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;
|
|
}
|
|
}
|