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

Public Member Functions

 __construct ()
 
 setHttpVersion ($version)
 
 getHttpVersion ()
 
 parse ($packet)
 
 getHeaders ()
 
 getHeadersFormatted ()
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 getIterator ()
 
 count ()
 
 setBody ($body)
 
 getBody ()
 
 __toString ()
 

Protected Member Functions

 _parse (Array $headers)
 

Protected Attributes

 $_httpVersion = 1.1
 
 $_headers = []
 
 $_body = null
 

Static Protected Attributes

static $_fcgi = null
 

Detailed Description

Class .

Generic class to manage HTTP headers (parse, set, get) only.

Definition at line 49 of file Http.php.

Constructor & Destructor Documentation

Hoa\Http\Http::__construct ( )

Constructor.

Returns
void

Definition at line 86 of file Http.php.

87  {
88  if (null === self::$_fcgi) {
89  self::$_fcgi = 'cgi-fcgi' === PHP_SAPI;
90  }
91 
92  return;
93  }

Member Function Documentation

Hoa\Http\Http::__toString ( )

Dump (parse^-1).

Returns
string

Definition at line 279 of file Http.php.

280  {
281  $out = null;
282 
283  foreach ($this->getHeaders() as $key => $value) {
284  $out .= $key . ': ' . $value . CRLF;
285  }
286 
287  return $out;
288  }
getHeaders()
Definition: Http.php:152

Here is the call graph for this function:

Hoa\Http\Http::_parse ( Array  $headers)
protected

Helper to parse HTTP headers and distribute them in array accesses.

Parameters
array$hedaersHeaders to parse and distribute.
Returns
array

Definition at line 134 of file Http.php.

135  {
136  unset($this->_headers);
137  $this->_headers = [];
138 
139  foreach ($headers as $header) {
140  list($name, $value) = explode(':', $header, 2);
141  $this->_headers[strtolower($name)] = trim($value);
142  }
143 
144  return $this->_headers;
145  }

Here is the caller graph for this function:

Hoa\Http\Http::count ( )

Count number of headers.

Returns
int

Definition at line 245 of file Http.php.

246  {
247  return count($this->getHeaders());
248  }
getHeaders()
Definition: Http.php:152

Here is the call graph for this function:

Hoa\Http\Http::getBody ( )

Get request body.

Returns
string

Definition at line 269 of file Http.php.

270  {
271  return $this->_body;
272  }
Hoa\Http\Http::getHeaders ( )

Get headers.

Returns
array

Definition at line 152 of file Http.php.

153  {
154  return $this->_headers;
155  }

Here is the caller graph for this function:

Hoa\Http\Http::getHeadersFormatted ( )

Get headers (formatted).

Returns
array

Definition at line 162 of file Http.php.

163  {
164  $out = [];
165 
166  foreach ($this->getHeaders() as $header => $value) {
167  if ('x-' == strtolower(substr($header, 0, 2))) {
168  $header = 'http_' . $header;
169  }
170 
171  $out[strtoupper(str_replace('-', '_', $header))] = $value;
172  }
173 
174  return $out;
175  }
getHeaders()
Definition: Http.php:152

Here is the call graph for this function:

Hoa\Http\Http::getHttpVersion ( )

Get request HTTP version.

Returns
float

Definition at line 114 of file Http.php.

115  {
116  return $this->_httpVersion;
117  }

Here is the caller graph for this function:

Hoa\Http\Http::getIterator ( )

Get iterator.

Returns

Definition at line 235 of file Http.php.

236  {
237  return new \ArrayIterator($this->getHeaders());
238  }
getHeaders()
Definition: Http.php:152

Here is the call graph for this function:

Hoa\Http\Http::offsetExists (   $offset)

Check if header exists.

Parameters
string$offsetHeader.
Returns
bool

Definition at line 183 of file Http.php.

184  {
185  return array_key_exists($offset, $this->_headers);
186  }

Here is the caller graph for this function:

Hoa\Http\Http::offsetGet (   $offset)

Get a header's value.

Parameters
string$offsetHeader.
Returns
string

Definition at line 194 of file Http.php.

195  {
196  if (false === $this->offsetExists($offset)) {
197  return null;
198  }
199 
200  return $this->_headers[$offset];
201  }
offsetExists($offset)
Definition: Http.php:183

Here is the call graph for this function:

Hoa\Http\Http::offsetSet (   $offset,
  $value 
)

Set a value to a header.

Parameters
string$offsetHeader.
string$valueValue.
Returns
void

Definition at line 210 of file Http.php.

211  {
212  $this->_headers[$offset] = $value;
213 
214  return;
215  }
Hoa\Http\Http::offsetUnset (   $offset)

Unset a header.

Parameters
string$offsetHeader.
Returns
void

Definition at line 223 of file Http.php.

224  {
225  unset($this->_headers[$offset]);
226 
227  return;
228  }
Hoa\Http\Http::parse (   $packet)
abstract

Parse a HTTP packet.

Parameters
string$packetHTTP packet.
Returns
void
Exceptions
Hoa\Http\Http::setBody (   $body)

Set request body.

Parameters
string$bodyBody.
Returns
string

Definition at line 256 of file Http.php.

257  {
258  $old = $this->_body;
259  $this->_body = $body;
260 
261  return $old;
262  }

Here is the caller graph for this function:

Hoa\Http\Http::setHttpVersion (   $version)

Set request HTTP version.

Parameters
float$versionHTTP version.
Returns
float

Definition at line 101 of file Http.php.

102  {
103  $old = $this->_httpVersion;
104  $this->_httpVersion = $version;
105 
106  return $old;
107  }

Here is the caller graph for this function:

Member Data Documentation

Hoa\Http\Http::$_body = null
protected

Definition at line 77 of file Http.php.

Hoa\Http\Http::$_fcgi = null
staticprotected

Definition at line 56 of file Http.php.

Hoa\Http\Http::$_headers = []
protected

Definition at line 70 of file Http.php.

Hoa\Http\Http::$_httpVersion = 1.1
protected

Definition at line 63 of file Http.php.


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