mirror of
https://github.com/OPSnet/Gazelle.git
synced 2026-01-16 18:04:34 -05:00
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Gazelle\Request;
|
|
|
|
abstract class AbstractValue {
|
|
protected array $label;
|
|
|
|
public function __construct(
|
|
protected bool $all = false,
|
|
protected array $list = [],
|
|
) {
|
|
$legal = $this->legal();
|
|
$this->label = [];
|
|
foreach ($this->list as $value) {
|
|
$offset = array_search($value, $legal);
|
|
if ($offset !== false) {
|
|
$this->label[$offset] = $value;
|
|
}
|
|
}
|
|
ksort($this->label);
|
|
}
|
|
|
|
abstract protected function legal(): array;
|
|
|
|
public function all(): bool {
|
|
return $this->all || in_array(count($this->label), [0, count($this->legal())]);
|
|
}
|
|
|
|
public function isValid(): bool {
|
|
return $this->all() || count($this->label) > 0;
|
|
}
|
|
|
|
public function exists(string $value): bool {
|
|
return $this->all() || array_search($value, $this->label) !== false;
|
|
}
|
|
|
|
public function dbList(): array|null {
|
|
return $this->all() ? null : array_values($this->label);
|
|
}
|
|
|
|
public function dbValue(): string {
|
|
return $this->all() || count($this->label) == count($this->legal())
|
|
? 'Any'
|
|
: implode('|', array_values($this->label));
|
|
}
|
|
|
|
public function display(): string {
|
|
return $this->all || count($this->label) == count($this->legal())
|
|
? 'Any'
|
|
: implode(', ', array_values($this->label));
|
|
}
|
|
}
|