mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-30 19:50:12 +02:00
PHP7 Specification
This commit is contained in:
30
Behavioral/Specification/OrSpecification.php
Normal file
30
Behavioral/Specification/OrSpecification.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user