You are here

public static function JsonApiSpec::isValidMemberName in Drupal 8

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

Checks whether the given member name is valid.

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"

Parameters

string $member_name: A member name to validate.

Return value

bool Whether the given member name is in compliance with the JSON:API specification.

See also

http://jsonapi.org/format/#document-member-names

2 calls to JsonApiSpec::isValidMemberName()
JsonApiSpec::isValidCustomQueryParameter in core/modules/jsonapi/src/JsonApiSpec.php
Checks whether the given custom query parameter name is valid.
JsonApiSpecTest::testIsValidMemberName in core/modules/jsonapi/tests/src/Unit/JsonApiSpecTest.php
Ensures that member names are properly validated.

File

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

Class

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

Namespace

Drupal\jsonapi

Code

public static function isValidMemberName($member_name) {

  // @todo When D8 requires PHP >=5.6, move to a MEMBER_NAME_REGEXP constant.
  static $regexp;

  // @codingStandardsIgnoreStart
  if (!isset($regexp)) {
    $regexp = '/^' . self::MEMBER_NAME_GLOBALLY_ALLOWED_CHARACTER_CLASS . '{1}' . '(' . self::MEMBER_NAME_INNER_ALLOWED_CHARACTERS . '*' . self::MEMBER_NAME_GLOBALLY_ALLOWED_CHARACTER_CLASS . '{1}' . ')?' . '$/u';
  }

  // @codingStandardsIgnoreEnd
  return preg_match($regexp, $member_name) === 1;
}