Exemplo n.º 1
0
 /**
  * Launch a synchrone request
  * returns the request identifier or false if fire is aborted
  * @param  array
  * @return integer or false
  */
 public function fire(REST_Request $request)
 {
     if ($this->loads === 0) {
         $this->time = microtime(true);
     }
     ++$this->loads;
     self::$handles++;
     // create a fresh request identifier
     $request->setCurlOption(CURLOPT_USERAGENT, 'REST_Client/' . self::$version);
     // launch the fire hooks
     foreach ($this->fire_hook as $hook) {
         $ret = call_user_func($hook, $request, self::$handles, $this);
         // this hook want to stop the fire ?
         if ($ret === false) {
             ++$this->loads_null;
             self::$handles--;
             return false;
         }
     }
     // configure curl client
     curl_setopt_array($this->handle, $request->toCurl());
     if (!is_resource($this->handle)) {
         ++$this->loads_null;
         return trigger_error(sprintf('%s::%s() cURL session was lost', __CLASS__, $method), E_USER_ERROR);
     }
     // send the request and create the response object
     ++$this->requests;
     $response = new REST_Response(curl_exec($this->handle), curl_errno($this->handle), curl_error($this->handle));
     if (!$response->isError()) {
         foreach (REST_Response::$properties as $name => $const) {
             $response->{$name} = curl_getinfo($this->handle, $const);
         }
     }
     $response->id = self::$handles;
     $this->responses[] = $response;
     // append the response to the stack
     return self::$handles;
     // return a unique identifier for the request
 }