svn: /pear2/Exception/trunk/ RELEASE-0.2.0 RELEASE-0.3.0 src/Exception.php

[email protected] (Helgi Þormar Þorbjörnsson) Thu, 03 Mar 2011 23:14:58 +0000
Newsgroups php.pear.cvs,php.pear.core
Message-ID <[email protected]>
dufuz                                    Thu, 03 Mar 2011 23:14:58 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=308912

Log:
- Removed addObserver() / removeObserver() as people can achieve that
  with their own observer function / classes via set_exception_handler
- Removed getTraceSafe() as it was falling back on debug_backtrace()
  when getTrace() was empty, which only happens when an Exception is
  thrown outside of a class/function scope.

Changed paths:
    U   pear2/Exception/trunk/RELEASE-0.2.0
    A   pear2/Exception/trunk/RELEASE-0.3.0
    U   pear2/Exception/trunk/src/Exception.php

Modified: pear2/Exception/trunk/RELEASE-0.2.0
===================================================================
--- pear2/Exception/trunk/RELEASE-0.2.0	2011-03-03 22:28:45 UTC (rev 308911)
+++ pear2/Exception/trunk/RELEASE-0.2.0	2011-03-03 23:14:58 UTC (rev 308912)
@@ -17,12 +17,12 @@
         var_dump($cause);
     }

-    And combine that with getTraceSafe() or getTraceAsString() if needed.
+And combine that with getTraceSafe() or getTraceAsString() if needed.

-    Put all that in a function and use set_exception_handler('exceptionHandler'); or similar to process
-    all Exceptions.
+Put all that in a function and use set_exception_handler('exceptionHandler'); or similar to process
+all Exceptions.

-    Example code or see the removed code at http://svn.php.net/viewvc/pear2/Exception/trunk/src/Exception.php?r1=295348&r2=295352 :
+Example code or see the removed code at http://svn.php.net/viewvc/pear2/Exception/trunk/src/Exception.php?r1=295348&r2=295352 :

     function exceptionHandler($e)
     {

Added: pear2/Exception/trunk/RELEASE-0.3.0
===================================================================
--- pear2/Exception/trunk/RELEASE-0.3.0	                        (rev 0)
+++ pear2/Exception/trunk/RELEASE-0.3.0	2011-03-03 23:14:58 UTC (rev 308912)
@@ -0,0 +1,5 @@
+- Removed addObserver() / removeObserver() as people can achieve that
+  with their own observer function / classes via set_exception_handler
+- Removed getTraceSafe() as it was falling back on debug_backtrace()
+  when getTrace() was empty, which only happens when an Exception is
+  thrown outside of a class/function scope.
\ No newline at end of file

Modified: pear2/Exception/trunk/src/Exception.php
===================================================================
--- pear2/Exception/trunk/src/Exception.php	2011-03-03 22:28:45 UTC (rev 308911)
+++ pear2/Exception/trunk/src/Exception.php	2011-03-03 23:14:58 UTC (rev 308912)
@@ -30,36 +30,6 @@
  *   PEAR2_Exceptions or a \PEAR2\MultiErrors
  * - callbacks for specific exception classes and their children
  *
- * 2) Usage example
- *
- * <code>
- * namespace PEAR2;
- * class PEAR2_MyPackage_Exception extends Exception {}
- *
- * class Test
- * {
- *     function foo()
- *     {
- *         throw new PEAR2_MyPackage_Exception('Error Message', 4);
- *     }
- * }
- *
- * function myLogger($exception)
- * {
- *     echo 'Logger: ' . $exception->getMessage() . "\n";
- * }
- *
- * // each time a exception is thrown the 'myLogger' will be called
- * // (its use is completely optional)
- * Exception::addObserver('\PEAR2\myLogger');
- * $test = new Test;
- * try {
- *     $test->foo();
- * } catch (\Exception $e) {
- *     print $e;
- * }
- * </code>
- *
  * @category   pear
  * @package    PEAR
  * @author     Tomas V.V.Cox <[email protected]>
@@ -76,9 +46,6 @@
 namespace PEAR2;
 abstract class Exception extends \Exception
 {
-    private static $_observers = array();
-    private $_trace;
-
     /**
      * Supported signatures:
      *  - PEAR2_Exception(string $message);
@@ -110,39 +77,15 @@
         }

         parent::__construct($message, $code, $cause);
-
-        foreach (self::$_observers as $func) {
-            if (is_callable($func)) {
-                call_user_func($func, $this);
-            }
-        }
     }

     /**
-     * @param mixed $callback  - A valid php callback, see php func is_callable()
-     *                         - A PEAR2_Exception::OBSERVER_* constant
-     *                         - An array(const PEAR2_Exception::OBSERVER_*,
-     *                           mixed $options)
-     * @param string $label    The name of the observer. Use this if you want
-     *                         to remove it later with removeObserver()
-     */
-    public static function addObserver($callback, $label = 'default')
-    {
-        self::$_observers[$label] = $callback;
-    }
-
-    public static function removeObserver($label = 'default')
-    {
-        unset(self::$_observers[$label]);
-    }
-
-    /**
      * Function must be public to call on caused exceptions
      * @param array
      */
     public function getCauseMessage(array &$causes)
     {
-        $trace = $this->getTraceSafe();
+        $trace = $this->getTrace();
         $cause = array(
             'class'   => get_class($this),
             'message' => $this->message,
@@ -180,17 +123,4 @@
             );
         }
     }
-
-    public function getTraceSafe()
-    {
-        if (!isset($this->_trace)) {
-            $this->_trace = $this->getTrace();
-            if (empty($this->_trace)) {
-                $backtrace = debug_backtrace();
-                $this->_trace = array($backtrace[count($backtrace)-1]);
-            }
-        }
-
-        return $this->_trace;
-    }
 }
\ No newline at end of file