示例#1
0
 /**
  * Send $event's data to the listener via an HTTP request.
  * Process the data if a custom processor is specified.
  *
  * @return $this
  */
 public function sendRequest()
 {
     $t = microtime(true);
     $client = new Client();
     $request = $client->createRequest($this->listener->method, $this->listener->url, $this->listener->headers, $this->listener->process($this->event));
     try {
         $response = $request->send();
     } catch (ClientErrorResponseException $exc) {
         $this->error = true;
         $this->time = microtime(true) - $t;
         $response = $exc->getResponse();
     } catch (RequestException $exc) {
         $this->error = true;
         $this->status = 0;
         $this->time = microtime(true) - $t;
         $this->body = $exc->getMessage();
         return $this;
     }
     $this->status = $response->getStatusCode();
     $this->headers = $response->getRawHeaders();
     $this->body = $response->getBody(true);
     $this->time = microtime(true) - $t;
     return $this;
 }