.

GyroHeaders Class Reference

This class works around some limitations in PHP header handling. More...

List of all members.

Static Public Member Functions

static  headers ()
  Get all set headers as assoziative array with (lower case) header name as key and full header as value.
static  is_set ($name)
  Returns TRUE, if header with given name was alreday set or send.
static  remove ($name)
  Remove given header.
static  restore ($arr_headers)
  Restore headers.
static  send ()
  Send all headers set.
static  set ($name, $value=false, $override=true)
  Set a header.
static  split ($header)
  Split header into array with name as first element, and value as second.
static  sync ()
  Read headers send into internal array.
static  values ()
  Get all set headers as assoziative array with (lower case) header name as key and value as value.

Detailed Description

This class works around some limitations in PHP header handling.

LImitations are:

  • headers cannot be removes prior to PHP 5.3
  • if headers are removed, one cannot tell, so they may be set from other parts of application

Definition at line 10 of file headers.cls.php.


Member Function Documentation

static GyroHeaders::headers (  )  [static]

Get all set headers as assoziative array with (lower case) header name as key and full header as value.

Returns:
array

Definition at line 71 of file headers.cls.php.

00071                                          {
00072                 $ret = array();
00073                 foreach(self::$headers as $name => $value) {
00074                         if ($value) {
00075                                 $value = $name . ': ' . $value; 
00076                         }
00077                         $ret[strtolower($name)] = $value;
00078                 }
00079                 return $ret;
00080         }
static GyroHeaders::is_set ( name  )  [static]

Returns TRUE, if header with given name was alreday set or send.

Parameters:
string  $name
Returns:
bool

Definition at line 51 of file headers.cls.php.

00051                                              {
00052                 $ret = false;
00053                 
00054                 $name = strtolower($name);
00055                 foreach(self::$headers as $hdr => $value) {
00056                         $hdr = strtolower($hdr);
00057                         if ($hdr == $name) {
00058                                 $ret = true;
00059                                 break;
00060                         }       
00061                 }
00062                 return $ret;            
00063         }
static GyroHeaders::remove ( name  )  [static]

Remove given header.

Definition at line 41 of file headers.cls.php.

00041                                              {
00042                 self::$headers[$name] = '';             
00043         }
static GyroHeaders::restore ( arr_headers  )  [static]

Restore headers.

Headers not in passed array wil be removed, headers from array will be set

Attention:
Expects array
Parameters:
$arr_headers  Array of headers with header name as key and full header as value

Definition at line 105 of file headers.cls.php.

00105                                                      {
00106                 $current = self::headers();
00107                 // array_diff_key exists as of PHP 5.1.0 only
00108                 foreach(array_diff(array_keys($current), array_keys($arr_headers)) as $name) {
00109                         self::remove($name);
00110                 }
00111                 foreach($arr_headers as $name => $value) {
00112                         self::set($value, false, true);
00113                 }
00114         }
static GyroHeaders::send (  )  [static]

Send all headers set.

Exceptions:
Exception  if headers were already sent
Returns:
void

Definition at line 133 of file headers.cls.php.

00133                                       {
00134                 $file = '';
00135                 $line = 0;
00136                 if (headers_sent($file, $line)) {
00137                         throw new Exception('GyroHeaders: Headers already sent in file "' . $file . '" on line ' . $line);
00138                 }
00139                 $has_remove = function_exists('header_remove');
00140                 foreach(self::$headers as $name => $value) {
00141                         if ($value) {
00142                                 header($name . ': ' . $value);
00143                         }
00144                         else if ($has_remove) {
00145                                 // As of PHP 5.3
00146                                 header_remove($name);
00147                         } 
00148                 }
00149         }
static GyroHeaders::set ( name,
value = false,
override = true  
) [static]

Set a header.

Parameters:
string  $name Name of header or complete header (if $value is false)
string  $value Value of header
bool  If FALSE, header will not be set, if header with same name was already set

Definition at line 27 of file headers.cls.php.

00027                                                                             {
00028                 if ($value === false) {
00029                         $tmp = self::split($name);
00030                         $name = array_shift($tmp);
00031                         $value = array_shift($tmp);
00032                 }
00033                 if ($override || !self::is_set($name)) {
00034                         self::$headers[$name] = $value; 
00035                 }
00036         }
static GyroHeaders::split ( header  )  [static]

Split header into array with name as first element, and value as second.

Returns:
array

Definition at line 156 of file headers.cls.php.

00156                                               {
00157                 $ret = explode(':', $header, 2);
00158                 if (count($ret) == 1) {
00159                         $ret = explode(' ', $header, 2);
00160                 }
00161                 if (count($ret) == 1) {
00162                         $ret[] = '';
00163                 }
00164                 array_walk($ret, 'trim');
00165                 return $ret;
00166         }               
static GyroHeaders::sync (  )  [static]

Read headers send into internal array.

Returns:
void

Definition at line 121 of file headers.cls.php.

00121                                       {
00122                 foreach(headers_list() as $header) {
00123                         self::set($header, false, false);
00124                 }
00125         }
static GyroHeaders::values (  )  [static]

Get all set headers as assoziative array with (lower case) header name as key and value as value.

Returns:
array

Definition at line 88 of file headers.cls.php.

00088                                         {
00089                 $ret = array();
00090                 foreach(self::$headers as $name => $value) {
00091                         $ret[strtolower($name)] = $value;
00092                 }
00093                 return $ret;
00094         }

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