- Merged getValue override

This commit is contained in:
Dave Mc Nicoll committed 2026-02-25 20:09:28 +00:00
1 parent b0b3aca6d9
commit fd5d31fa17
11 files changed
+183 -106

No files matched your search

+10 -2
View File
@@ -10,6 +10,8 @@ class OrderBy extends Fragment {
const SQL_TOKEN = "ORDER BY";
const SQL_COLLATE = "COLLATE";
# const 'NULLS LAST|FIRST' must be handlded
public function set(array $order) : self
{
$this->orderBy = $order;
@@ -17,9 +19,9 @@ class OrderBy extends Fragment {
return $this;
}
public function add(string|\Stringable $field, ? string $direction = null) : self
public function add(string|\Stringable $field, string|\Stringable|null $direction = null) : self
{
$this->validateFieldType($field);
$this->validateDirectionType($direction);
$this->orderBy[] = [ $field, $direction ];
@@ -39,4 +41,10 @@ class OrderBy extends Fragment {
]);
}
protected function validateDirectionType(mixed $direction) {
# Could be coming from user-input, we must whitelist
if (is_string($direction) && ! in_array(strtoupper($direction), [ 'ASC', 'DESC' ])) {
throw new \Ulmus\Exception\InvalidFieldType(sprintf("Validation of string `%s` failed from query `%s`", $direction, get_class($this)));
}
}
}