2024-04-20 00:04:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Matchers;
|
|
|
|
|
2024-07-12 00:16:50 +02:00
|
|
|
use App\Lib\Editor\Comparator;
|
|
|
|
|
2024-04-20 00:04:20 +02:00
|
|
|
class SingleValueMatcher extends Matcher
|
|
|
|
{
|
|
|
|
|
2024-07-12 00:16:50 +02:00
|
|
|
public function matches(Comparator $comparator, mixed $value): bool
|
2024-04-20 00:04:20 +02:00
|
|
|
{
|
2024-07-12 00:16:50 +02:00
|
|
|
if ($comparator === Comparator::EQUAL && $value === $this->value) {
|
2024-04-20 00:04:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-07-12 00:16:50 +02:00
|
|
|
if ($comparator === Comparator::NOTEQUAL && $value !== $this->value) {
|
2024-04-20 00:04:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-07-12 00:16:50 +02:00
|
|
|
if ($comparator === Comparator::IN && in_array($this->value, $value)) {
|
2024-04-20 00:04:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-07-12 00:16:50 +02:00
|
|
|
if ($comparator === Comparator::NOTIN && !in_array($this->value, $value)) {
|
2024-04-20 00:04:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|