cvs: php-src /pear/PEAR Exception.php
| From: | Tomas V.V.Cox | Date: | Mon, 21 Jun 2004 03:53:39 +0000 |
| Subject: | cvs: php-src /pear/PEAR Exception.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-403@lists.php.net to get a copy of this message | ||
cox Sun Jun 20 23:53:39 2004 EDT
Modified files:
/php-src/pear/PEAR Exception.php
Log:
Some API changes:
- addObserver() params order switched
- signal() -> _signal()
- public:getCauseMessage() -> private:_getCauseMessage()
- some more docs
http://cvs.php.net/diff.php/php-src/pear/PEAR/Exception.php?r1=1.1&r2=1.2&ty=u
Index: php-src/pear/PEAR/Exception.php
diff -u php-src/pear/PEAR/Exception.php:1.1 php-src/pear/PEAR/Exception.php:1.2
--- php-src/pear/PEAR/Exception.php:1.1 Sun Jun 20 15:08:37 2004
+++ php-src/pear/PEAR/Exception.php Sun Jun 20 23:53:39 2004
@@ -17,7 +17,7 @@
// | Hans Lellelid <hans@velum.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Exception.php,v 1.1 2004/06/20 19:08:37 cox Exp $
+// $Id: Exception.php,v 1.2 2004/06/21 03:53:39 cox Exp $
define('PEAR_OBSERVER_PRINT', -2);
define('PEAR_OBSERVER_TRIGGER', -4);
@@ -26,18 +26,18 @@
/**
* Base PEAR_Exception Class
*
- * Features:
+ * 1) Features:
*
* - Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception))
* - Definable triggers, shot when exceptions occur
* - Pretty and informative error messages
* - Added more context info avaible (like class, method or cause)
*
- * Ideas:
+ * 2) Ideas:
*
* - Maybe a way to define a 'template' for the output
*
- * 1) Inherited properties from PHP Exception Class:
+ * 3) Inherited properties from PHP Exception Class:
*
* protected $message
* protected $code
@@ -45,7 +45,7 @@
* protected $file
* private $trace
*
- * 2) Inherited methods from PHP Exception Class:
+ * 4) Inherited methods from PHP Exception Class:
*
* __clone
* __construct
@@ -57,7 +57,7 @@
* getTraceAsString
* __toString
*
- * 3) Usage example
+ * 5) Usage example
*
* <code>
* require_once 'PEAR/Exception.php';
@@ -73,7 +73,7 @@
* }
* // each time a exception is thrown the 'myLogger' will be called
* // (its use is completely optional)
- * PEAR_Exception::addObserver('mylogger', 'myLogger');
+ * PEAR_Exception::addObserver('myLogger');
* $test = new Test;
* try {
* $test->foo();
@@ -84,7 +84,7 @@
*
* @since PHP 5
* @package PEAR
- * @version $Rev:$
+ * @version $Revision: 1.2 $
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Hans Lellelid <hans@velum.net>
*
@@ -124,20 +124,29 @@
$this->method =
$this->error_class.'::'.$this->error_method.'()';
parent::__construct($message, $code);
- $this->signal();
+ $this->_signal();
}
- public static function addObserver($label, $callback)
+ /**
+ * @param mixed $callback - A valid php callback, see php_func is_callable()
+ * - A PEAR_OBSERVER_* constant
+ * - An array(const PEAR_OBSERVER_*,mixed $options)
+ *
+ * @param string $label - The name of the observer. Use this if you want
+ * to remove it later with delObserver()
+ */
+
+ public static function addObserver($callback, $label = 'default')
{
self::$_observers[$label] = $callback;
}
- public static function delObserver($label)
+ public static function delObserver($label = 'default')
{
unset(self::$_observers[$label]);
}
- private function signal()
+ private function _signal()
{
foreach (self::$_observers as $func) {
if (is_callable($func)) {
@@ -164,11 +173,11 @@
}
}
- public function getCauseMessage($obj)
+ private function _getCauseMessage()
{
- $msg = ' ' . $obj->method . " at {$obj->file}
({$obj->line})\n";
- if ($obj->cause instanceof Exception) {
- return $msg.$obj->getCauseMessage($obj->cause);
+ $msg = ' ' . $this->method . " at {$this->file}
({$this->line})\n";
+ if ($this->cause instanceof Exception) {
+ return $msg.$this->cause->_getCauseMessage();
}
return $msg;
}
@@ -199,7 +208,7 @@
' File (Line) : ' . "{$this->file} ({$this->line})\n" .
' Method : ' . $this->method . "\n";
if ($this->cause instanceof Exception) {
- $str .= " Nested Error : \n".$this->getCauseMessage($this);
+ $str .= " Nested Error : \n".$this->_getCauseMessage();
}
if (isset($_SERVER['REQUEST_URI'])) {
return nl2br('<pre>'.htmlentities($str).'</pre>');