/ Published in: PHP
PHP Error / Message Stack
Expand |
Embed | Plain Text
<?php /** * * @author MJB * @date 18/01/06 * @desc MessageStack & Message class - Error/Warning handling * @ver 1.6 * * @notes * since the stack only exists for a single request-response * the object never needs to be manually cleared of messages * * smarty frontend * * now does static methods and line numbers */ class MessageStack { var $_msgs; function MessageStack() {} /** * @desc create new message on stack * @params overriden message if error passed from outside (ie Pear) */ function add($source_class, $line_num, $error_code, $message="") { $this->_msgs[] = &new Message($source_class, $line_num, $error_code, $message); } /** * @desc parse Message objects into array for smarty */ function display() { foreach($this->_msgs as $msg) { "code" => $msg->getCode(), "line" => $msg->getLine(), "message" => $msg->getMessage(), "link" => $msg->getLink()); } return $output; } function hasErrors() { } } class Message { var $_classMethod; //source class name & getMessage method var $_line; //erronous line var $_code; //error code translates to a message var $_message; //error message var $_link; //link to solution function Message($source, $line, $code, $msg="") { $this->_line = $line; $this->_code = $code; $this->_link = ""; //use passed msg or attempt to get from calling class $this->_message = $msg; //call getMessage on object statically //parse message & link if given $this->_message = $tmp['text']; $this->_link = $tmp['link']; }else{ $this->_message = $tmp['text']; } }else{ $this->_message = "Undefined error message"; } } function getClass() { return $this->_classMethod[0]; } function getLine() { return (DEBUG) ? $this->_line : ""; } function getCode() { return $this->_code; //code for info/error } function getMessage() { return $this->_message; } function getLink() { return $this->_link; } } ?>
You need to login to post a comment.
