You are here

protected static function RestfulManager::matchContentType in RESTful 7

Matches a string with path style wildcards.

Parameters

string $content_type: The string to check.

string $pattern: The pattern to check against.

Return value

bool TRUE if the input matches the pattern.

See also

drupal_match_path().

1 call to RestfulManager::matchContentType()
RestfulManager::outputFormat in includes/RestfulManager.php
Helper function to get the default output format from the current request.

File

includes/RestfulManager.php, line 265
Contains \RestfulManager.

Class

RestfulManager
@file Contains \RestfulManager.

Code

protected static function matchContentType($content_type, $pattern) {
  $regexps =& drupal_static(__FUNCTION__);
  if (!isset($regexps[$pattern])) {

    // Convert path settings to a regular expression.
    $to_replace = array(
      '/\\\\\\*/',
    );
    $replacements = array(
      '.*',
    );
    $patterns_quoted = preg_quote($pattern, '/');

    // This will turn 'application/*' into '/^(application\/.*)(;.*)$/' allowing
    // us to match 'application/json; charset: utf8'
    $regexps[$pattern] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')(;.*)?$/i';
  }
  return (bool) preg_match($regexps[$pattern], $content_type);
}