LTI Integration Library  3.1.0
PHP class library for building LTI integrations
HTTPMessage.php
Go to the documentation of this file.
1 <?php
2 
3 namespace ceLTIc\LTI;
4 
7 
17 {
18 
24  public $ok = false;
25 
31  public $request = null;
32 
38  public $requestHeaders = '';
39 
45  public $response = null;
46 
52  public $responseHeaders = '';
53 
59  public $status = 0;
60 
66  public $error = '';
67 
73  private $url = null;
74 
80  private $method = null;
81 
87  private static $httpClient;
88 
97  function __construct($url, $method = 'GET', $params = null, $header = null)
98  {
99  $this->url = $url;
100  $this->method = strtoupper($method);
101  if (is_array($params)) {
102  $this->request = http_build_query($params);
103  } else {
104  $this->request = $params;
105  }
106  if (!empty($header)) {
107  $this->requestHeaders = explode("\n", $header);
108  }
109  }
110 
116  public function getUrl()
117  {
118  return $this->url;
119  }
120 
126  public function getMethod()
127  {
128  return $this->method;
129  }
130 
136  public static function setHttpClient($httpClient = null)
137  {
138  self::$httpClient = $httpClient;
139  }
140 
146  public static function getHttpClient()
147  {
148  if (!self::$httpClient) {
149  if (function_exists('curl_init')) {
150  self::$httpClient = new Http\CurlClient();
151  } elseif (ini_get('allow_url_fopen')) {
152  self::$httpClient = new Http\StreamClient();
153  }
154  }
155 
156  return self::$httpClient;
157  }
158 
164  public function send()
165  {
166  $client = self::getHttpClient();
167  $this->ok = !empty($client);
168  if ($this->ok) {
169  $this->ok = $client->send($this);
170  } else {
171  $this->error = 'No HTTP client interface is available';
172  }
173 
174  return $this->ok;
175  }
176 
177 }
$status
Status of response (0 if undetermined).
Definition: HTTPMessage.php:59
getUrl()
Get the target URL for the request.
$error
Error message.
Definition: HTTPMessage.php:66
__construct($url, $method='GET', $params=null, $header=null)
Class constructor.
Definition: HTTPMessage.php:97
getMethod()
Get the HTTP method for the request.
static getHttpClient()
Get the HTTP client to use for sending the message.
send()
Send the request to the target URL.
$responseHeaders
Response headers.
Definition: HTTPMessage.php:52
Class to implement the HTTP message interface using the Curl library.
Definition: CurlClient.php:15
Class to represent an HTTP message request.
Definition: HTTPMessage.php:16
Class to implement the HTTP message interface using a file stream.
$request
Request body.
Definition: HTTPMessage.php:31
static setHttpClient($httpClient=null)
Set the HTTP client to use for sending the message.
$ok
True if message was processed successfully.
Definition: HTTPMessage.php:24
$response
Response body.
Definition: HTTPMessage.php:45
Interface to represent an HTTP message client.
$requestHeaders
Request headers.
Definition: HTTPMessage.php:38