- Merged getValue override
This commit is contained in:
1 parent
b0b3aca6d9
commit
fd5d31fa17
11 files changed
+183
-106
No files matched your search
+10
-2
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user