You are here

public static function JsonApiSpec::isValidCustomQueryParameter in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/JsonApiSpec.php \Drupal\jsonapi\JsonApiSpec::isValidCustomQueryParameter()

Checks whether the given custom query parameter name is valid.

A custom query parameter name must be a valid member name, with one additional requirement: it MUST contain at least one non a-z character.

Requirements:

  • it MUST contain at least one character.
  • it MUST contain only the allowed characters
  • it MUST start and end with a "globally allowed character"
  • it MUST contain at least none a-z (U+0061 to U+007A) character

It is RECOMMENDED that a hyphen (U+002D), underscore (U+005F) or capital letter is used (i.e. camelCasing).

Parameters

string $custom_query_parameter_name: A custom query parameter name to validate.

Return value

bool Whether the given query parameter is in compliance with the JSON:API specification.

See also

http://jsonapi.org/format/#query-parameters

2 calls to JsonApiSpec::isValidCustomQueryParameter()
JsonApiRequestValidator::validateQueryParams in core/modules/jsonapi/src/EventSubscriber/JsonApiRequestValidator.php
Validates custom (implementation-specific) query parameter names.
JsonApiSpecTest::testIsValidCustomQueryParameter in core/modules/jsonapi/tests/src/Unit/JsonApiSpecTest.php
Provides test cases.

File

core/modules/jsonapi/src/JsonApiSpec.php, line 142

Class

JsonApiSpec
Defines constants used for compliance with the JSON:API specification.

Namespace

Drupal\jsonapi

Code

public static function isValidCustomQueryParameter($custom_query_parameter_name) {
  return static::isValidMemberName($custom_query_parameter_name) && preg_match('/[^a-z]/u', $custom_query_parameter_name) === 1;
}