mirror of
https://codeberg.org/reflect/reflect-rules-plugin.git
synced 2025-09-14 08:53:42 +02:00
fix: eval method for Type::ARRAY and Type::OBJECT
This commit is contained in:
parent
067896dafe
commit
a2154faef0
1 changed files with 23 additions and 3 deletions
|
@ -137,6 +137,26 @@
|
||||||
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 {
|
||||||
|
// Arrays in POST parameters should already be decoded
|
||||||
|
if ($scope === Scope::POST) {
|
||||||
|
return is_array($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode stringified JSON
|
||||||
|
$json = json_decode($value);
|
||||||
|
|
||||||
|
// Failed to decode JSON
|
||||||
|
if ($json === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate property on superglobal with decoded JSON
|
||||||
|
$GLOBALS[Scope::GET->value][$this->property] = $json;
|
||||||
|
|
||||||
|
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
|
||||||
|
@ -167,7 +187,7 @@
|
||||||
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,
|
||||||
Type::OBJECT => $match = is_array($value),
|
Type::OBJECT => $match = $this->eval_json($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)
|
||||||
};
|
};
|
||||||
|
@ -189,7 +209,7 @@
|
||||||
Type::NUMBER => $this->eval_type($value, $scope) && $value >= $this->min,
|
Type::NUMBER => $this->eval_type($value, $scope) && $value >= $this->min,
|
||||||
Type::STRING => $this->eval_type($value, $scope) && strlen($value) >= $this->min,
|
Type::STRING => $this->eval_type($value, $scope) && strlen($value) >= $this->min,
|
||||||
Type::ARRAY,
|
Type::ARRAY,
|
||||||
Type::OBJECT => $this->eval_type($value, $scope) && count($value) >= $this->min,
|
Type::OBJECT => $this->eval_type($value, $scope) && count($GLOBALS[$scope->value][$this->property]) >= $this->min,
|
||||||
default => true
|
default => true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -199,7 +219,7 @@
|
||||||
Type::NUMBER => $this->eval_type($value, $scope) && $value <= $this->max,
|
Type::NUMBER => $this->eval_type($value, $scope) && $value <= $this->max,
|
||||||
Type::STRING => $this->eval_type($value, $scope) && strlen($value) <= $this->max,
|
Type::STRING => $this->eval_type($value, $scope) && strlen($value) <= $this->max,
|
||||||
Type::ARRAY,
|
Type::ARRAY,
|
||||||
Type::OBJECT => $this->eval_type($value, $scope) && count($value) <= $this->max,
|
Type::OBJECT => $this->eval_type($value, $scope) && count($GLOBALS[$scope->value][$this->property]) <= $this->max,
|
||||||
default => true
|
default => true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue