Hoa central
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Hoa\Http\Request Class Reference
Inheritance diagram for Hoa\Http\Request:

Public Member Functions

 parse ($packet)
 
 setMethod ($method)
 
 getMethod ()
 
 setUrl ($url)
 
 getUrl ()
 
 __toString ()
 
- Public Member Functions inherited from Hoa\Http\Http
 __construct ()
 
 setHttpVersion ($version)
 
 getHttpVersion ()
 
 parse ($packet)
 
 getHeaders ()
 
 getHeadersFormatted ()
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 getIterator ()
 
 count ()
 
 setBody ($body)
 
 getBody ()
 
 __toString ()
 

Public Attributes

const METHOD_CONNECT = 'connect'
 
const METHOD_DELETE = 'delete'
 
const METHOD_GET = 'get'
 
const METHOD_HEAD = 'head'
 
const METHOD_OPTIONS = 'options'
 
const METHOD_PATCH = 'patch'
 
const METHOD_POST = 'post'
 
const METHOD_PUT = 'put'
 
const METHOD_TRACE = 'trace'
 
const METHOD_EXTENDED = 'extended'
 

Protected Attributes

 $_method = null
 
 $_url = null
 
- Protected Attributes inherited from Hoa\Http\Http
 $_httpVersion = 1.1
 
 $_headers = []
 
 $_body = null
 

Additional Inherited Members

- Protected Member Functions inherited from Hoa\Http\Http
 _parse (Array $headers)
 
- Static Protected Attributes inherited from Hoa\Http\Http
static $_fcgi = null
 

Detailed Description

Class .

HTTP request support.

Definition at line 47 of file Request.php.

Member Function Documentation

Hoa\Http\Request::__toString ( )

Dump (parse^-1).

Returns
string

Definition at line 249 of file Request.php.

250  {
251  return
252  strtoupper($this->getMethod()) . ' ' .
253  $this->getUrl() . ' ' .
254  'HTTP/' . $this->getHttpVersion() . CRLF .
255  parent::__toString() . CRLF;
256  }
getHttpVersion()
Definition: Http.php:114

Here is the call graph for this function:

Hoa\Http\Request::getMethod ( )

Get request method.

Returns
string

Definition at line 215 of file Request.php.

216  {
217  return $this->_method;
218  }

Here is the caller graph for this function:

Hoa\Http\Request::getUrl ( )

Get request URL.

Returns
string

Definition at line 239 of file Request.php.

240  {
241  return $this->_url;
242  }

Here is the caller graph for this function:

Hoa\Http\Request::parse (   $packet)

Parse a HTTP packet.

Parameters
string$packetHTTP packet.
Returns
void
Exceptions

Definition at line 142 of file Request.php.

143  {
144  $headers = explode("\r\n", $packet);
145  $http = array_shift($headers);
146  $this->setBody(null);
147 
148  foreach ($headers as $i => $header) {
149  if ('' == trim($header)) {
150  unset($headers[$i]);
151  $this->setBody(
152  trim(
153  implode("\r\n", array_splice($headers, $i))
154  )
155  );
156 
157  break;
158  }
159  }
160 
161  if (0 === preg_match('#^([^\s]+)\s+([^\s]+)\s+HTTP/(1\.(?:0|1))$#i', $http, $matches)) {
162  throw new Exception(
163  'HTTP headers are not well-formed: %s',
164  0,
165  $http
166  );
167  }
168 
169  switch ($method = strtolower($matches[1])) {
170  case self::METHOD_CONNECT:
171  case self::METHOD_DELETE:
172  case self::METHOD_GET:
173  case self::METHOD_HEAD:
174  case self::METHOD_OPTIONS:
175  case self::METHOD_PATCH:
176  case self::METHOD_POST:
177  case self::METHOD_PUT:
178  case self::METHOD_TRACE:
179  $this->_method = $method;
180 
181  break;
182 
183  default:
184  $this->_method = self::METHOD_EXTENDED;
185  }
186 
187  $this->setUrl($matches[2]);
188  $this->setHttpVersion((float) $matches[3]);
189 
190  $this->_parse($headers);
191 
192  return;
193  }
setBody($body)
Definition: Http.php:256
setHttpVersion($version)
Definition: Http.php:101
_parse(Array $headers)
Definition: Http.php:134

Here is the call graph for this function:

Hoa\Http\Request::setMethod (   $method)

Set request method.

Parameters
string$methodMethod (please, see self::METHOD_* constants).
Returns
string

Definition at line 202 of file Request.php.

203  {
204  $old = $this->_method;
205  $this->_method = $method;
206 
207  return $old;
208  }
Hoa\Http\Request::setUrl (   $url)

Set request URL.

Parameters
string$urlURL.
Returns
string

Definition at line 226 of file Request.php.

227  {
228  $old = $this->_url;
229  $this->_url = $url;
230 
231  return $old;
232  }

Here is the caller graph for this function:

Member Data Documentation

Hoa\Http\Request::$_method = null
protected

Definition at line 124 of file Request.php.

Hoa\Http\Request::$_url = null
protected

Definition at line 131 of file Request.php.

const Hoa\Http\Request::METHOD_CONNECT = 'connect'

Method: CONNECT.

string

Definition at line 54 of file Request.php.

const Hoa\Http\Request::METHOD_DELETE = 'delete'

Method: DELETE.

string

Definition at line 61 of file Request.php.

const Hoa\Http\Request::METHOD_EXTENDED = 'extended'

Other methods.

string

Definition at line 117 of file Request.php.

const Hoa\Http\Request::METHOD_GET = 'get'

Method: GET.

string

Definition at line 68 of file Request.php.

const Hoa\Http\Request::METHOD_HEAD = 'head'

Method: HEAD.

string

Definition at line 75 of file Request.php.

const Hoa\Http\Request::METHOD_OPTIONS = 'options'

Method: OPTIONS.

string

Definition at line 82 of file Request.php.

const Hoa\Http\Request::METHOD_PATCH = 'patch'

Method: PATCH.

string

Definition at line 89 of file Request.php.

const Hoa\Http\Request::METHOD_POST = 'post'

Method: POST.

string

Definition at line 96 of file Request.php.

const Hoa\Http\Request::METHOD_PUT = 'put'

Method: PUT.

string

Definition at line 103 of file Request.php.

const Hoa\Http\Request::METHOD_TRACE = 'trace'

Method: TRACE.

string

Definition at line 110 of file Request.php.


The documentation for this class was generated from the following file: