Status Class Reference
[Lib]
Status class. More...

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. |
|
| 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.
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 111 of file status.cls.php.
| Status::count | ( | ) |
Returns number of error messages.
- Returns:
- int
Definition at line 174 of file status.cls.php.
00174 { 00175 return count($this->messages); 00176 }
| Status::display | ( | $ | policy =
self::OUTPUT_HTML |
) |
Print status messages.
- Returns:
- void
Definition at line 183 of file status.cls.php.
00183 { 00184 print $this->render($policy); 00185 }
| Status::get_messages | ( | ) |
| Status::is_empty | ( | ) |
Returns true, if there is no message.
- Returns:
- bool
Definition at line 166 of file status.cls.php.
00166 { 00167 return ($this->count() == 0); 00168 }
| Status::is_error | ( | ) |
Returns true, if status is an error.
- Returns:
- bool
Reimplemented in Message.
Definition at line 157 of file status.cls.php.
| Status::is_ok | ( | ) |
Indicates if there is an error or not.
- Returns:
- Boolean
Reimplemented in Message.
Definition at line 148 of file status.cls.php.
| 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 126 of file status.cls.php.
00126 { 00127 if ($other instanceof Status) { 00128 foreach($other->get_messages() as $m) { 00129 $this->append($m); 00130 } 00131 } 00132 else if ($other instanceof PEAR_Error) { 00133 $this->append($other->getMessage()); 00134 } 00135 else if ($other instanceof Exception) { 00136 $this->append($other->getMessage()); 00137 } 00138 else if (!empty($other) && is_string($other)){ 00139 $this->append($other); 00140 } 00141 }
| Status::persist | ( | ) |
Save status into session.
- Returns:
- bool True, if status was persisted
Definition at line 205 of file status.cls.php.
00205 { 00206 if (!$this->is_empty()) { 00207 Session::push('status', $this); 00208 return true; 00209 } 00210 return false; 00211 }
| Status::render | ( | $ | policy =
self::OUTPUT_HTML |
) |
Render status.
- Returns:
- string
Reimplemented in Message.
Definition at line 192 of file status.cls.php.
00192 { 00193 $ret = $this->to_string($policy); 00194 if ($ret !== '' && $policy == self::OUTPUT_HTML) { 00195 $ret = html::error($ret); 00196 } 00197 return $ret; 00198 }
| static Status::restore | ( | ) | [static] |
Restore status from sessiom.
- Returns:
- Status False if no status was in session
Definition at line 218 of file status.cls.php.
00218 { 00219 $ret = false; 00220 if (Session::is_started()) { 00221 $ret = Session::pull('status'); 00222 } 00223 return $ret; 00224 }
| 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.
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.
| const Status::OUTPUT_HTML = 'html' |
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:
- gyro/core/lib/helpers/status.cls.php
