Exception
1 day ago
SpecificationFactory
1 day ago
AggregateSpecification.php
1 day ago
AndSpecification.php
1 day ago
CollectionOperators.php
1 day ago
CollectionSpecification.php
1 day ago
ComparisonOperators.php
1 day ago
ComparisonSpecification.php
1 day ago
CompositeSpecification.php
1 day ago
ContainsSpecification.php
1 day ago
Context.php
1 day ago
ContextAwareSpecification.php
1 day ago
DateComparisonSpecification.php
1 day ago
DateOperators.php
1 day ago
DateRangeSpecification.php
1 day ago
DateRelativeDaysSpecification.php
1 day ago
DateRelativeDeductedSpecification.php
1 day ago
DateSpecification.php
1 day ago
DateTimeFactory.php
1 day ago
DateTrait.php
1 day ago
EndsWithSpecification.php
1 day ago
FactSpecification.php
1 day ago
FactTrait.php
1 day ago
FloatComparisonSpecification.php
1 day ago
FloatRangeSpecification.php
1 day ago
IntegerComparisonSpecification.php
1 day ago
IntegerRangeSpecification.php
1 day ago
NotSpecification.php
1 day ago
NullSpecification.php
1 day ago
OperatorExpression.php
1 day ago
OrSpecification.php
1 day ago
RangeOperators.php
1 day ago
RangeSpecification.php
1 day ago
Specification.php
1 day ago
SpecificationFactory.php
1 day ago
StartsWithSpecification.php
1 day ago
StringComparisonSpecification.php
1 day ago
StringMatchSpecification.php
1 day ago
StringOperators.php
1 day ago
Type.php
1 day ago
TypeSpecification.php
1 day ago
TypeTrait.php
1 day ago
Types.php
1 day ago
CollectionSpecification.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Expression; |
| 6 | |
| 7 | use AC\Expression\Exception\OperatorNotFoundException; |
| 8 | use Traversable; |
| 9 | |
| 10 | class CollectionSpecification extends OperatorExpression implements FactSpecification |
| 11 | { |
| 12 | use FactTrait; |
| 13 | |
| 14 | public function __construct( |
| 15 | string $operator, |
| 16 | Traversable $fact |
| 17 | ) { |
| 18 | parent::__construct($operator); |
| 19 | |
| 20 | $this->fact = $fact; |
| 21 | } |
| 22 | |
| 23 | public function is_satisfied_by($value): bool |
| 24 | { |
| 25 | switch ($this->operator) { |
| 26 | case CollectionOperators::CONTAINS: |
| 27 | case CollectionOperators::NOT_CONTAINS: |
| 28 | foreach ($this->fact as $item) { |
| 29 | if ($item === $value) { |
| 30 | return $this->operator === CollectionOperators::CONTAINS; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | return $this->operator === CollectionOperators::NOT_CONTAINS; |
| 35 | } |
| 36 | |
| 37 | throw new OperatorNotFoundException($this->operator); |
| 38 | } |
| 39 | |
| 40 | public function export(): array |
| 41 | { |
| 42 | return array_merge( |
| 43 | parent::export(), |
| 44 | $this->export_fact() |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | } |
| 49 |