restServer = PROTOCOL_HTTP . COLON . PATH_SEP . PATH_SEP; $this->restServer .= $_SERVER['SERVER_NAME'] . PATH_SEP; $this->restServer .= $this->serviceTechnic . PATH_SEP . $workspace . PATH_SEP; $this->ch = curl_init(); curl_setopt( $this->ch, CURLOPT_TIMEOUT, 2 ); curl_setopt( $this->ch, CURLOPT_POST, 1 ); curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, 1 ); } /** * set the message in order to follow the message format */ abstract protected function format (array $message); /** * Set properties used in a simpleMessage Class like a set in a URI, or formatted as a JSon msg. */ abstract protected function setMoreProperties ($messageFormated); /** * Attach the method to the restServer path, set the type of the message, and the message itself. */ protected function setMessageProperties ($method, array $message) { $messageFormated = $this->format( $message ); $this->server_method = $this->restServer . $method; $this->setMoreProperties( $messageFormated ); } /** * Send or execute(curl notation) the message using a rest method */ public function send ($method, array $message) { self::setMessageProperties( $method, $message ); $this->output = curl_exec( $this->ch ); return $this->output; } /** * Set the message to GET method type */ public function sendGET ($method, array $message) { curl_setopt( $this->ch, CURLOPT_HTTPGET, true ); return $this->send( $method, $message ); } /** * Set the message to POST method type */ public function sendPOST ($method, array $message) { curl_setopt( $this->ch, CURLOPT_POST, true ); return $this->send( $method, $message ); } /** * Set the message to PUT method type */ public function sendPUT ($method, array $message) { curl_setopt( $this->ch, CURLOPT_PUT, true ); return $this->send( $method, $message ); } /** * Set the message to DELETE method type */ public function sendDELETE ($method, array $message) { curl_setopt( $this->ch, CURLOPT_CUSTOMREQUEST, "DELETE" ); return $this->send( $method, $message ); } /** * Display all the data that the response could got. */ public function displayResponse () { G::LoadSystem('inputfilter'); $filter = new InputFilter(); $error = curl_error( $this->ch ); $error = $filter->xssFilterHard($error); $result = array ('header' => '','body' => '','curl_error' => '','http_code' => '','last_url' => '' ); if ($error != "") { $result['curl_error'] = $error; return $result; } $response = $this->output; $response = $filter->xssFilterHard($response); $header_size = curl_getinfo( $this->ch, CURLINFO_HEADER_SIZE ); $result['header'] = substr( $response, 0, $header_size ); $result['body'] = substr( $response, $header_size ); $result['http_code'] = curl_getinfo( $this->ch, CURLINFO_HTTP_CODE ); $result['last_url'] = curl_getinfo( $this->ch, CURLINFO_EFFECTIVE_URL ); $result = $filter->xssFilterHard($result); $this->type = $filter->xssFilterHard($this->type); echo $this->type . " Response: " . $response . "
"; foreach ($result as $index => $data) { if ($data != "") { echo $index . "=" . $data . "
"; } } echo "
"; } /** * Close the Curl session using the Curl Handle set by curl_init() function. */ public function close () { curl_close( $this->ch ); } }