You are here

function restful_get_restful_handler in RESTful 7

Return the handler based on major and minor version, and resource name.

Parameters

$resource_name: The name of the resource (e.g. "articles").

int $major_version: (optional) The major version (not prefixed with "v"). Defaults to 1.

int $minor_version: (optional) The minor version. Defaults to 0.

Return value

RestfulInterface | NULL The handler object if found, or NULL.

55 calls to restful_get_restful_handler()
RestfulAuthenticationTestCase::testAccessTime in tests/RestfulAuthenticationTestCase.test
Test recording of access time.
RestfulAuthenticationTestCase::testAuthentication in tests/RestfulAuthenticationTestCase.test
Test authenticating a user.
RestfulAuthenticationTestCase::testSwitchUser in tests/RestfulAuthenticationTestCase.test
Test switching the user in an API call.
RestfulAutoCompleteTestCase::testAutocomplete in tests/RestfulAutoCompleteTestCase.test
Test the autocomplete functionality.
RestfulCreateEntityTestCase::testCreateEntity in tests/RestfulCreateEntityTestCase.test
Test creating an entity (POST method).

... See full list

1 string reference to 'restful_get_restful_handler'
RestfulTokenAuthenticationTestCase::testAuthentication in modules/restful_token_auth/tests/RestfulTokenAuthenticationTestCase.test
Test authenticating a user.

File

./restful.module, line 237

Code

function restful_get_restful_handler($resource_name, $major_version = 1, $minor_version = 0) {
  $cache =& drupal_static(__FUNCTION__);
  $identifier = implode(':', array(
    $major_version,
    $resource_name,
    $minor_version,
  ));
  if (isset($cache[$identifier])) {
    return $cache[$identifier];
  }
  $cache[$identifier] = NULL;

  // Array with all the handlers with the same major version and resource name.
  // We get all of them, so we can find the correct one if minor version is
  // present.
  $valid_plugins = array();
  foreach (restful_get_restful_plugins() as $plugin) {
    if ($plugin['major_version'] != $major_version) {
      continue;
    }
    if ($plugin['resource'] != $resource_name) {
      continue;
    }
    if ($minor_version == $plugin['minor_version']) {

      // We found out handler, so we can break.
      $valid_plugins[$plugin['minor_version']] = $plugin;
      break;
    }
    if ($plugin['minor_version'] > $minor_version) {

      // Minor version is above the needed one.
      continue;
    }
    $valid_plugins[$plugin['minor_version']] = $plugin;
  }
  if (!$valid_plugins) {
    return;
  }

  // Sort the handlers, and get the last one, as it is the closest one to the
  // requested minor version.
  ksort($valid_plugins);
  $plugin = end($valid_plugins);
  $cache[$identifier] = restful_get_restful_handler_by_name($plugin['name']);
  return $cache[$identifier];
}