.

TracedArray Class Reference
[Lib]

This class traces access on its members. More...

List of all members.

Public Member Functions

  __construct ($arr)
  Conctructor.
  contains ($key)
  Returns true, if array contains item with given key.
  count ()
  Returns numbers of elements in array.
  get_array ()
  Returns original array.
  get_item ($key, $default_value= '')
  Returns item from array, default value if item is missing.
  has_unused ()
  Returns true, if this array contains elements that gave not been accessed by get_item.
  mark_all_as_used ()
  Marks all array items as read.
  redirect_unused ($permanent=false)
  Redirects to a page containing only unused items as query parameters.
  redirect_used ($permanent=false)
  Redirects to a page containing only used items as query parameters.

Detailed Description

This class traces access on its members.

Author:
Gerd Riesselmann

Definition at line 8 of file tracedarray.cls.php.


Constructor & Destructor Documentation

TracedArray::__construct ( arr  ) 

Conctructor.

Parameters:
array  $arr

Definition at line 17 of file tracedarray.cls.php.

00017                                           {
00018                 $this->arr = (array)$arr;
00019         }

Member Function Documentation

TracedArray::contains ( key  ) 

Returns true, if array contains item with given key.

Parameters:
string  $key
Returns:
bool

Definition at line 57 of file tracedarray.cls.php.

00057                                        {
00058                 return array_key_exists($key, $this->arr);
00059         }
TracedArray::count (  ) 

Returns numbers of elements in array.

Returns:
int

Definition at line 38 of file tracedarray.cls.php.

00038                                 {
00039                 return count($this->arr);
00040         }
TracedArray::get_array (  ) 

Returns original array.

Returns:
array

Definition at line 47 of file tracedarray.cls.php.

00047                                     {
00048                 return $this->arr;              
00049         }
TracedArray::get_item ( key,
default_value = ''  
)

Returns item from array, default value if item is missing.

Parameters:
string  $key
mixed  $default_value
Returns:
mixed

Definition at line 28 of file tracedarray.cls.php.

00028                                                              {
00029                 $this->trace[$key] = true;
00030                 return Arr::get_item($this->arr, $key, $default_value); 
00031         }
TracedArray::has_unused (  ) 

Returns true, if this array contains elements that gave not been accessed by get_item.

Returns:
bool

Definition at line 66 of file tracedarray.cls.php.

00066                                      {
00067                 foreach($this->arr as $key => $value) {
00068                         if (!array_key_exists($key, $this->trace)) {
00069                                 return true;            
00070                         }                       
00071                 }
00072                 return false;           
00073         }
TracedArray::mark_all_as_used (  ) 

Marks all array items as read.

Definition at line 78 of file tracedarray.cls.php.

00078                                            {
00079                 foreach($this->arr as $key => $value) {
00080                         $this->get_item($key);
00081                 }
00082                 
00083         }
TracedArray::redirect_unused ( permanent = false  ) 

Redirects to a page containing only unused items as query parameters.

Parameters:
bool  $permanent if true redierct is 301, else it is 302

Definition at line 90 of file tracedarray.cls.php.

00090                                                             {
00091                 $url = Url::current()->clear_query();
00092                 foreach($this->arr as $key => $value) {
00093                         if (!array_key_exists($key, $this->trace)) {
00094                                 $url->replace_query_parameter($key, $value);            
00095                         }                       
00096                 }
00097                 $url->redirect($permanent ? Url::PERMANENT : Url::TEMPORARY);
00098                 exit();
00099         }
TracedArray::redirect_used ( permanent = false  ) 

Redirects to a page containing only used items as query parameters.

Parameters:
bool  $permanent if true redierct is 301, else it is 302

Definition at line 106 of file tracedarray.cls.php.

00106                                                           {
00107                 $url = Url::current()->clear_query();
00108                 foreach($this->arr as $key => $value) {
00109                         if (array_key_exists($key, $this->trace)) {
00110                                 $url->replace_query_parameter($key, $value);            
00111                         }                       
00112                 }
00113                 $url->redirect($permanent ? Url::PERMANENT : Url::TEMPORARY);
00114                 exit();
00115         }                

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