32 parent::__construct(
$data);
37 $this->validateField($this->
getField());
61 $this->validateField($field);
86 $this->validateDirection($direction);
97 private function validateDirection($direction): void
99 $this->validateDirectionIsString($direction);
100 $this->validateDirectionIsAscOrDesc($direction);
108 private function validateDirectionIsString($direction): void
110 if (!is_string($direction)) {
111 throw new InputException(
new Phrase(
112 'The sort order has to be specified as a string, got %1.',
113 [gettype($direction)]
123 private function validateDirectionIsAscOrDesc($direction): void
125 $normalizedDirection = $this->normalizeDirectionInput($direction);
127 throw new InputException(
new Phrase(
128 'The sort order has to be specified as %1 for ascending order or %2 for descending order.',
138 private function normalizeDirectionInput($direction)
140 return strtoupper($direction);
150 private function validateField(
string $field): void
152 if (preg_match(
'/[^a-z0-9\_]/i', $field)) {
153 throw new InputException(
155 'Sort order field %1 contains restricted symbols',
__construct(array $data=[])