=1. self::MEMBER_NAME_GLOBALLY_ALLOWED_CHARACTER_CLASS . '{1}(' . // As many non-globally allowed characters as desired. self::MEMBER_NAME_INNER_ALLOWED_CHARACTERS . '*' . // If length > 1, then it must end in a "globally allowed" character. self::MEMBER_NAME_GLOBALLY_ALLOWED_CHARACTER_CLASS . '{1}' . // >1 characters is optional. ')?$/u'; /** * 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" * * @param string $member_name * A member name to validate. * * @return bool * Whether the given member name is in compliance with the JSON:API * specification. * * @see http://jsonapi.org/format/#document-member-names */ public static function isValidMemberName($member_name) { return preg_match(static::MEMBER_NAME_REGEXP, $member_name) === 1; } /** * The reserved (official) query parameters. */ const RESERVED_QUERY_PARAMETERS = [ 'filter', 'sort', 'page', 'fields', 'include', ]; /** * The query parameter for providing a version (revision) value. * * @var string */ const VERSION_QUERY_PARAMETER = 'resourceVersion'; /** * Gets the reserved (official) JSON:API query parameters. * * @return string[] * Gets the query parameters reserved by the specification. */ public static function getReservedQueryParameters() { return static::RESERVED_QUERY_PARAMETERS; } /** * 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). * * @param string $custom_query_parameter_name * A custom query parameter name to validate. * * @return bool * Whether the given query parameter is in compliane with the JSON:API * specification. * * @see http://jsonapi.org/format/#query-parameters */ 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; } }