mirror of
https://codeberg.org/reflect/reflect-rules-plugin.git
synced 2025-09-14 08:53:42 +02:00
fix: use CSV for GET array
This commit is contained in:
parent
a2154faef0
commit
d748d5205a
1 changed files with 24 additions and 3 deletions
|
@ -20,8 +20,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
class Rules {
|
class Rules {
|
||||||
|
private const CSV_DELIMITER = ",";
|
||||||
|
|
||||||
private string $property;
|
private string $property;
|
||||||
|
|
||||||
|
/*
|
||||||
|
# Rule properties
|
||||||
|
These properties store rules for an instance of a property
|
||||||
|
*/
|
||||||
|
|
||||||
public bool $required = false;
|
public bool $required = false;
|
||||||
|
|
||||||
// Matched Type against $types array
|
// Matched Type against $types array
|
||||||
|
@ -137,7 +144,7 @@
|
||||||
return !is_bool($value) && in_array($value, $this->enum);
|
return !is_bool($value) && in_array($value, $this->enum);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function eval_json(mixed $value, Scope $scope): bool {
|
private function eval_object(mixed $value, Scope $scope): bool {
|
||||||
// Arrays in POST parameters should already be decoded
|
// Arrays in POST parameters should already be decoded
|
||||||
if ($scope === Scope::POST) {
|
if ($scope === Scope::POST) {
|
||||||
return is_array($value);
|
return is_array($value);
|
||||||
|
@ -157,6 +164,20 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function eval_array(string $value, Scope $scope): bool {
|
||||||
|
// Arrays in POST parameters should already be decoded
|
||||||
|
if ($scope === Scope::POST) {
|
||||||
|
return is_array($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate property on superglobal with decoded CSV if not already an array
|
||||||
|
if (!is_array($_GET[$this->property])) {
|
||||||
|
$GLOBALS[Scope::GET->value][$this->property] = explode(self::CSV_DELIMITER, $_GET[$this->property]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
## Public eval methods
|
## Public eval methods
|
||||||
These are the entry-point eval methods that in turn can call other
|
These are the entry-point eval methods that in turn can call other
|
||||||
|
@ -186,8 +207,8 @@
|
||||||
Type::NUMBER => $match = is_numeric($value),
|
Type::NUMBER => $match = is_numeric($value),
|
||||||
Type::STRING => $match = is_string($value),
|
Type::STRING => $match = is_string($value),
|
||||||
Type::BOOLEAN => $match = $this->eval_type_boolean($value, $scope),
|
Type::BOOLEAN => $match = $this->eval_type_boolean($value, $scope),
|
||||||
Type::ARRAY,
|
Type::ARRAY => $match = $this->eval_array($value, $scope),
|
||||||
Type::OBJECT => $match = $this->eval_json($value, $scope),
|
Type::OBJECT => $match = $this->eval_object($value, $scope),
|
||||||
Type::ENUM => $match = $this->eval_type_enum($value),
|
Type::ENUM => $match = $this->eval_type_enum($value),
|
||||||
Type::NULL => $match = is_null($value)
|
Type::NULL => $match = is_null($value)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue