public function ServicesClientConnectionRestServer::prepareRequest in Services Client 7
Same name and namespace in other branches
- 7.2 services_client_connection/plugins/ServicesClientConnectionRestServer.inc \ServicesClientConnectionRestServer::prepareRequest()
Implements prepareRequest().
Overrides ServicesClientConnectionPlugin::prepareRequest
File
- services_client_connection/
plugins/ ServicesClientConnectionRestServer.inc, line 81
Class
Code
public function prepareRequest(ServicesClientConnectionHttpRequest &$request) {
parent::prepareRequest($request);
// Normalize endpoint URL
$endpoint = rtrim($this->connection->endpoint, '/');
// No special changes to URL
$url_parts = array(
$endpoint,
$request->resource,
);
// Add resource ID if present
if ($request->id) {
$url_parts[] = $request->id;
}
// For special REST actions - CRUD don't add action to URL and
// add HTTP method.
if (in_array($request->action, array_keys($this->rest_actions))) {
$request->http_method = $this->rest_actions[$request->action];
}
elseif (!empty($request->relation)) {
$url_parts[] = $request->relation;
$request->http_method = 'GET';
}
elseif (!empty($request->action)) {
$url_parts[] = $request->action;
$request->http_method = 'POST';
}
elseif (empty($request->http_method)) {
$request->http_method = 'POST';
}
// Build URL if not set in Request object
if (empty($request->url)) {
$request->url = implode('/', $url_parts);
}
else {
$request->url = $endpoint . '/' . ltrim($request->url, '/');
}
// Allow parser to prepare request
$this->parser
->prepareRequest($request);
// Format request
$this->formatter
->format($request);
}