@@ -316,7 +316,7 @@ class Endpoint {
316316 public bool $ reverse = false ;
317317
318318 /**
319- * @var string|null $sort_by
319+ * @var string|array| null $sort_by
320320 * Sets the default value(s) for the `sort_by` field in the request data. This value is used to control the sorting of
321321 * the Model objects returned by this Endpoint. This value can be overridden by the client in the request data. Use
322322 * caution when assigning this value as it may force objects to be sorted in this order when they are written to the
@@ -333,6 +333,15 @@ class Endpoint {
333333 */
334334 public string $ sort_order = 'SORT_ASC ' ;
335335
336+ /**
337+ * @var string $sort_flags
338+ * Sets the default value for the `sort_flags` field in the request data. This value is used to control the sorting
339+ * flags of the Model objects returned by this Endpoint. This value can be overridden by the client in the request
340+ * data. This value only takes effect when the `sort_by` field is also set. This value must be the name of a valid
341+ * PHP sort flags constant (e.g. 'SORT_REGULAR', 'SORT_NATURAL')
342+ */
343+ public string $ sort_flags = 'SORT_REGULAR ' ;
344+
336345 /**
337346 * @var bool $append
338347 * Sets the default value for the `append` field in the request data. This value is used to control how Model objects
@@ -854,6 +863,43 @@ class Endpoint {
854863 }
855864 }
856865
866+ /**
867+ * Validates the $sort_flags common control parameter for this request.
868+ * @note If the `sort_flags` field was not provided in the request data, the request will default to the
869+ * Endpoint's assigned $sort_flags property value.
870+ * @throws ValidationError When the `sort_flags` field is not a string or is not a valid sort flags constant.
871+ */
872+ private function validate_sort_flags (): void
873+ {
874+ # Valid sort_flags options
875+ $ flag_opts = [
876+ 'SORT_REGULAR ' , 'SORT_NUMERIC ' , 'SORT_STRING ' , 'SORT_LOCALE_STRING ' , 'SORT_NATURAL ' , 'SORT_FLAG_CASE '
877+ ];
878+
879+ # Only validate this field if the client specifically requested it in the request data
880+ if (isset ($ this ->request_data ['sort_flags ' ])) {
881+ # Ensure value is a string
882+ if (!is_string ($ this ->request_data ['sort_flags ' ])) {
883+ throw new ValidationError (
884+ message: 'Field `sort_flags` must be of type `string`. ' ,
885+ response_id: 'ENDPOINT_SORT_FLAGS_FIELD_INVALID_TYPE ' ,
886+ );
887+ }
888+
889+ # Ensure the field is a valid sort flags constant
890+ if (!in_array ($ this ->request_data ['sort_flags ' ], $ flag_opts )) {
891+ throw new ValidationError (
892+ message: 'Field `sort_flags` must be one of: ' . json_encode ($ flag_opts ),
893+ response_id: 'ENDPOINT_SORT_FLAGS_FIELD_UNKNOWN_SORT_FLAGS ' ,
894+ );
895+ }
896+
897+ # Update the sort_flags property to use the client's requested value and remove it from the request data
898+ $ this ->sort_flags = $ this ->request_data ['sort_flags ' ];
899+ unset($ this ->request_data ['sort_flags ' ]);
900+ }
901+ }
902+
857903 /**
858904 * Validates the $append common control parameter for this request.
859905 * @note If the `append` field was not provided in the request data, the request will default to the Endpoint's assigned
@@ -964,6 +1010,7 @@ class Endpoint {
9641010 $ this ->validate_reverse ();
9651011 $ this ->validate_sort_by ();
9661012 $ this ->validate_sort_order ();
1013+ $ this ->validate_sort_flags ();
9671014 $ this ->validate_append ();
9681015 $ this ->validate_remove ();
9691016 $ this ->validate_limit ();
@@ -1082,6 +1129,7 @@ class Endpoint {
10821129 reverse: $ this ->reverse ,
10831130 sort_by: $ this ->sort_by ,
10841131 sort_order: constant ($ this ->sort_order ),
1132+ sort_flags: constant ($ this ->sort_flags ),
10851133 );
10861134 }
10871135 # For GET requests on many Endpoints, obtain all objects from the assigned Model.
@@ -1105,6 +1153,7 @@ class Endpoint {
11051153 # Allow the endpoint/client to override the Model's sort_by and sort_order properties
11061154 $ this ->model ->sort_by = $ this ->sort_by ?? $ this ->model ->sort_by ;
11071155 $ this ->model ->sort_order = constant ($ this ->sort_order ) ?? $ this ->model ->sort_order ;
1156+ $ this ->model ->sort_flags = constant ($ this ->sort_flags ) ?? $ this ->model ->sort_flags ;
11081157
11091158 # Create the object and return it
11101159 return $ this ->model ->create (apply: $ this ->request_data ['apply ' ] === true );
@@ -1128,6 +1177,7 @@ class Endpoint {
11281177 # Allow the endpoint/client to override the Model's sort_by and sort_order properties
11291178 $ this ->model ->sort_by = $ this ->sort_by ?? $ this ->model ->sort_by ;
11301179 $ this ->model ->sort_order = constant ($ this ->sort_order ) ?? $ this ->model ->sort_order ;
1180+ $ this ->model ->sort_flags = constant ($ this ->sort_flags ) ?? $ this ->model ->sort_flags ;
11311181
11321182 # Update the object and return it
11331183 return $ this ->model ->update (
0 commit comments