* @license PHP License * @package Wombat * @subpackage base */ /** * Exception * * WBException allows sophisticated exception codes. * While Exception only allows numbers, WBException * supports namespaces for code. * * $e = new WBException('my custom message', 7, __CLASS__); * * Use namespaces to keep track on your exception codes, using the constant __CLASS__ * may help you in case you are in need for names * * One can also use standardized WBClass-creation function: * * $eData = array( * 'msg' => 'my custom message' * 'code' => '7' * 'class' => __CLASS__ * ); * $e = WBClass::create('WBException', $eData); * * @version 1.0.0 * @package Wombat * @subpackage base */ class WBException extends Exception { /** * Exception code using namespace * @var string */ protected $code = null; /** * Optional data * @var mixed */ private $data = null; /** * Constructor * * First parameter msg can also have code and class. * * @param array|string $msg exception message * @param int $code integer * @param string $clazz name of calling class * @see Exception */ public function __construct($msg, $code = 0, $clazz = '') { if (is_array($msg)) { $args = array( 'msg' => '', 'code' => 0, 'class' => '', ); $args = array_merge($args, $msg); $msg = $args['msg']; $code = $args['code']; $clazz = $args['class']; } $this->message = $msg; $this->code = $clazz . '.' . $code; if (!class_exists('WBLog', false)) { return; } $log = WBLog::start(__CLASS__); $message = array( 'msg' => $msg, 'code' => $code, 'class' => $clazz ); $log->err($message); } /** * Set Optional Data * * @param mixed $data */ public function setData($data) { $this->data = $data; } /** * Get Optional Data * * @return mixed */ public function getData() { return $this->data; } }