function JsonApiSpec::isValidCustomQueryParameter

Same name in other branches
  1. 8.9.x core/modules/jsonapi/src/JsonApiSpec.php \Drupal\jsonapi\JsonApiSpec::isValidCustomQueryParameter()
  2. 10 core/modules/jsonapi/src/JsonApiSpec.php \Drupal\jsonapi\JsonApiSpec::isValidCustomQueryParameter()
  3. 11.x 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.