You are here

private function RESTServer::resolveController in Services 6.3

Same name and namespace in other branches
  1. 7.3 servers/rest_server/includes/RESTServer.inc \RESTServer::resolveController()
1 call to RESTServer::resolveController()
RESTServer::handle in servers/rest_server/includes/RESTServer.inc
Handles the call to the REST server

File

servers/rest_server/includes/RESTServer.inc, line 534
Class for handling REST calls.

Class

RESTServer
@file Class for handling REST calls.

Code

private function resolveController($resource, $method, $path) {
  $pc = count($path);
  $class = NULL;
  $operation = NULL;

  // Use the index handler for all empty path GET-requests
  if (!$pc && $method == 'GET') {
    $class = 'operations';
    $operation = 'index';
  }
  elseif ($pc == 1 && ($method == 'GET' || $method == 'PUT' || $method == 'DELETE') || $pc == 0 && $method == 'POST') {
    $action_mapping = array(
      'GET' => 'retrieve',
      'POST' => 'create',
      'PUT' => 'update',
      'DELETE' => 'delete',
    );
    $class = 'operations';
    $operation = $action_mapping[$method];
  }
  elseif ($pc >= 2 && $method == 'GET') {
    $class = 'relationships';
    $operation = $path[1];
  }
  elseif ($pc == 1 && $method == 'POST') {
    $class = 'actions';
    $operation = $path[0];
  }
  elseif ($pc >= 2 && $method == 'POST') {
    $class = 'targeted_actions';
    $operation = $path[1];
  }
  $controller = FALSE;
  if (!empty($class) && !empty($operation) && !empty($resource[$class][$operation])) {
    $controller = $resource[$class][$operation];
    if (isset($resource['file']) && empty($controller['file'])) {
      $controller['file'] = $resource['file'];
    }
  }
  return $controller;
}