.

Status Class Reference
[Lib]

Status class. More...

Inheritance diagram for Status:
Message

List of all members.

Public Member Functions

  __construct ($message=false)
  Constructor.
  __get ($name)
  Catch old clients access former public member $message for compatability reason.
  __toString ()
  Convert to string.
  append ($text)
  Append $text to the error message and turns this status into an error.
  clear_messages ()
  Clear all error messages, but retain error status.
  count ()
  Returns number of error messages.
  display ($policy=self::OUTPUT_HTML)
  Print status messages.
  get_messages ()
  Returns messages as array.
  is_empty ()
  Returns true, if there is no message.
  is_error ()
  Returns true, if status is an error.
  is_ok ()
  Indicates if there is an error or not.
  merge ($other)
  Merges with another status.
  persist ()
  Save status into session.
  render ($policy=self::OUTPUT_HTML)
  Render status.
  to_string ($policy=self::OUTPUT_HTML)
  Converts messages to a string.

Static Public Member Functions

static  restore ()
  Restore status from sessiom.

Public Attributes

const  OUTPUT_HTML = 'html'
const  OUTPUT_PLAIN = 'plain'

Protected Attributes

  $isError = false
  $messages = array()

Detailed Description

Status class.

Indicates either success or an error

If a function returns successfull, it can return a status with isError == false, which is equivalent to is_ok() == true. This is obtained using the default contructor. If a function returns an error, it uses the constructor with a message. isError in this case is true, and is_ok() returns false.

Attention:
Status should be used with plain text message only, since its output routines convert everythig to HTML entities. If you for some reason want HTML in you error messages, you must write your own string conversion.
Author:
Gerd Riesselmann

Definition at line 20 of file status.cls.php.


Constructor & Destructor Documentation

Status::__construct ( message = false  ) 

Constructor.

Parameters:
Mixed  If String: The error message, else if left blank : No error

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

00051                                                       {
00052                 if (!empty($message)) {
00053                         $this->append($message);
00054                 } 
00055         }

Member Function Documentation

Status::__get ( name  ) 

Catch old clients access former public member $message for compatability reason.

Definition at line 68 of file status.cls.php.

00068                                  {
00069         if ($name === 'message') {
00070                 return $this->to_string();
00071         }
00072     }
Status::__toString (  ) 

Convert to string.

Definition at line 60 of file status.cls.php.

00060                                      {
00061                 return $this->to_string();
00062         }
Status::append ( text  ) 

Append $text to the error message and turns this status into an error.

Parameters:
String 
Returns:
void

Definition at line 118 of file status.cls.php.

00118                                       {
00119                 if (!empty($text)) {
00120                         $this->messages[] = $text;
00121                         $this->isError = true;
00122                 }
00123         }
Status::clear_messages (  ) 

Clear all error messages, but retain error status.

Definition at line 108 of file status.cls.php.

00108                                          {
00109                 $this->messages = array();
00110         }
Status::count (  ) 

Returns number of error messages.

Returns:
int

Definition at line 181 of file status.cls.php.

00181                                 {
00182                 return count($this->messages);
00183         }
Status::display ( policy = self::OUTPUT_HTML  ) 

Print status messages.

Returns:
void

Definition at line 190 of file status.cls.php.

00190                                                            {
00191                 print $this->render($policy);
00192         }
Status::get_messages (  ) 

Returns messages as array.

Returns:
array

Definition at line 101 of file status.cls.php.

00101                                        {
00102                 return $this->messages;
00103         }
Status::is_empty (  ) 

Returns true, if there is no message.

Returns:
bool

Definition at line 173 of file status.cls.php.

00173                                    {
00174                 return ($this->count() == 0);
00175         }
Status::is_error (  ) 

Returns true, if status is an error.

Returns:
bool

Reimplemented in Message.

Definition at line 164 of file status.cls.php.

00164                                    {
00165                 return ($this->isError == true);
00166         }
Status::is_ok (  ) 

Indicates if there is an error or not.

Returns:
Boolean

Reimplemented in Message.

Definition at line 155 of file status.cls.php.

00155                                 {
00156                 return ($this->isError == false);
00157         }
Status::merge ( other  ) 

Merges with another status.

Messages are added and this status becomes an error if either this or the merged status are errors

Parameters:
Status|Exception|PEAR_Error|string  $other Either Status, Exception, PEAR_Error or a string

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

00133                                       {
00134                 if ($other instanceof Status) {
00135                         foreach($other->get_messages() as $m) {
00136                                 $this->append($m);
00137                         }
00138                 }
00139                 else if ($other instanceof PEAR_Error) {
00140                         $this->append($other->getMessage());
00141                 }
00142                 else if ($other instanceof Exception) {
00143                         $this->append($other->getMessage());
00144                 }
00145                 else if (!empty($other) && is_string($other)){
00146                         $this->append($other);
00147                 }
00148         }  
Status::persist (  ) 

Save status into session.

Returns:
bool True, if status was persisted

Definition at line 212 of file status.cls.php.

00212                                   {
00213                 if (!$this->is_empty()) {
00214                         Session::push('status', $this);
00215                         return true;
00216                 }
00217                 return false;
00218         }
Status::render ( policy = self::OUTPUT_HTML  ) 

Render status.

Returns:
string

Reimplemented in Message.

Definition at line 199 of file status.cls.php.

00199                                                           {
00200                 $ret = $this->to_string($policy);
00201                 if ($ret !== '' && $policy == self::OUTPUT_HTML) {
00202                         $ret = html::error($ret);
00203                 }
00204                 return $ret;
00205         }
static Status::restore (  )  [static]

Restore status from sessiom.

Returns:
Status False if no status was in session

Definition at line 225 of file status.cls.php.

00225                                          {
00226                 $ret = false;
00227                 if (Session::is_started()) {
00228                         $ret = Session::pull('status');
00229                 }
00230                 return $ret;
00231         }  
Status::to_string ( policy = self::OUTPUT_HTML  ) 

Converts messages to a string.

Messages are divided by
for HTML and
for plain text output.

Attention:
For HTML output, messages are escaped, so if your messages contain HTML tags, they will be converted to < etc
Returns:
string

Definition at line 84 of file status.cls.php.

00084                                                              {
00085                 $ret = '';
00086                 if ($policy == self::OUTPUT_PLAIN) {
00087                         $ret .= implode("\n", $this->messages); 
00088                 }
00089                 else {
00090                         $tmp = array_map(array('String', 'escape'), $this->messages);
00091                         $ret .= implode('<br />', $tmp);
00092                 }
00093                 return $ret; 
00094         }

Member Data Documentation

Status::$isError = false [protected]

Definition at line 44 of file status.cls.php.

Status::$messages = array() [protected]

Definition at line 37 of file status.cls.php.

Definition at line 21 of file status.cls.php.

const Status::OUTPUT_PLAIN = 'plain'

Definition at line 22 of file status.cls.php.


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