Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move to namespaces

  • Loading branch information...
commit f56c5e38a917e70e00f32bb453a02c5b239c0907 1 parent 15764a5
@cellog cellog authored
Showing with 101 additions and 27 deletions.
  1. +4 −4 README
  2. +9 −8 package.xml
  3. +72 −0 package_compatible.xml
  4. +16 −15 src/Exception.php
View
8 README
@@ -1,10 +1,10 @@
-PEAR2_Exception is the standard exception class for PEAR2.
+pear2\Exception is the standard exception class for PEAR2.
In addition to supporting the default signature of the built-in
-Exception class, PEAR2_Exception also supports passing a
+Exception class, pear2\Exception also supports passing a
cause of an exception, which can be another exception object
or a PEAR2_MultiErrors object. The error messages of the causes
are used when constructing the error message displayed when
-converting PEAR2_Exception to a string.
+converting pear2\Exception to a string.
-PEAR2_Exception should always be extended by your own custom exception
+pear2\Exception should always be extended by your own custom exception
class for the package.
View
17 package.xml
@@ -2,16 +2,16 @@
<package version="2.1" xmlns="http://pear.php.net/dtd/package-2.1" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.1 http://pear.php.net/dtd/package-2.1.xsd">
<name>PEAR2_Exception</name>
<channel>pear2.php.net</channel>
- <summary>PEAR2_Exception is the standard exception class for PEAR2.
+ <summary>pear2\Exception is the standard exception class for PEAR2.
</summary>
<description>In addition to supporting the default signature of the built-in
-Exception class, PEAR2_Exception also supports passing a
+Exception class, pear2\Exception also supports passing a
cause of an exception, which can be another exception object
or a PEAR2_MultiErrors object. The error messages of the causes
are used when constructing the error message displayed when
-converting PEAR2_Exception to a string.
+converting pear2\Exception to a string.
-PEAR2_Exception should always be extended by your own custom exception
+pear2\Exception should always be extended by your own custom exception
class for the package.</description>
<lead>
<name>Gregory Beaver</name>
@@ -37,20 +37,21 @@ class for the package.</description>
<email>hans@velum.net</email>
<active>no</active>
</developer>
- <date>2007-10-05</date>
+ <date>2009-07-07</date>
+ <time>22:57:54</time>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
</version>
<stability>
- <release>devel</release>
+ <release>alpha</release>
<api>alpha</api>
</stability>
<license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD License</license>
<notes>Initial Release</notes>
<contents>
<dir name="/">
- <dir name="src" baseinstalldir="PEAR2">
+ <dir name="src" baseinstalldir="pear2">
<file role="php" name="Exception.php"/>
</dir>
</dir>
@@ -65,5 +66,5 @@ class for the package.</description>
</pearinstaller>
</required>
</dependencies>
- <phprelease></phprelease>
+ <phprelease/>
</package>
View
72 package_compatible.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package version="2.1" xmlns="http://pear.php.net/dtd/package-2.1" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.1 http://pear.php.net/dtd/package-2.1.xsd">
+ <name>PEAR2_Exception</name>
+ <channel>pear2.php.net</channel>
+ <summary>pear2\Exception is the standard exception class for PEAR2.
+</summary>
+ <description>In addition to supporting the default signature of the built-in
+Exception class, pear2\Exception also supports passing a
+cause of an exception, which can be another exception object
+or a PEAR2_MultiErrors object. The error messages of the causes
+are used when constructing the error message displayed when
+converting pear2\Exception to a string.
+
+pear2\Exception should always be extended by your own custom exception
+class for the package.</description>
+ <lead>
+ <name>Gregory Beaver</name>
+ <user>cellog</user>
+ <email>cellog@php.net</email>
+ <active>yes</active>
+ </lead>
+ <lead>
+ <name>Tomas V.V. Cox</name>
+ <user>cox</user>
+ <email>cox@idecnet.com</email>
+ <active>no</active>
+ </lead>
+ <lead>
+ <name>Bertrand Mansion</name>
+ <user>mansion</user>
+ <email>bmansion@mamasam.com</email>
+ <active>no</active>
+ </lead>
+ <developer>
+ <name>Hans Lellelid</name>
+ <user>hlellelid</user>
+ <email>hans@velum.net</email>
+ <active>no</active>
+ </developer>
+ <date>2009-07-07</date>
+ <time>22:57:54</time>
+ <version>
+ <release>0.1.0</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD License</license>
+ <notes>Initial Release</notes>
+ <contents>
+ <dir name="/">
+ <file role="php" name="php/pear2/Exception.php"/>
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.2.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.8</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease>
+ <filelist>
+ <install name="php/pear2/Exception.php" as="pear2/Exception.php"/>
+ </filelist>
+ </phprelease>
+</package>
View
31 src/Exception.php
@@ -35,7 +35,7 @@
* - Pretty and informative error messages
* - Added more context info available (like class, method or cause)
* - cause can be a PEAR2_Exception or an array of mixed
- * PEAR2_Exceptions or a PEAR2_MultiErrors
+ * PEAR2_Exceptions or a \pear2\MultiErrors
* - callbacks for specific exception classes and their children
*
* 2) Ideas:
@@ -101,7 +101,8 @@
* @since Class available since Release 0.1.0
*
*/
-abstract class PEAR2_Exception extends Exception
+namespace pear2;
+abstract class Exception extends \Exception
{
public static $htmlError = false;
const OBSERVER_PRINT = -2;
@@ -118,12 +119,12 @@
* - PEAR2_Exception(string $message, int $code);
* - PEAR2_Exception(string $message, Exception $cause);
* - PEAR2_Exception(string $message, Exception $cause, int $code);
- * - PEAR2_Exception(string $message, PEAR2_MultiErrors $cause);
- * - PEAR2_Exception(string $message, PEAR2_MultiErrors $cause, int $code);
+ * - PEAR2_Exception(string $message, \pear2\MultiErrors $cause);
+ * - PEAR2_Exception(string $message, \pear2\MultiErrors $cause, int $code);
* - PEAR2_Exception(string $message, array $causes);
* - PEAR2_Exception(string $message, array $causes, int $code);
* @param string exception message
- * @param int|Exception|PEAR2_MultiErrors|array|null exception cause
+ * @param int|Exception|\pear2\MultiErrors|array|null exception cause
* @param int|null exception code or null
*/
public function __construct($message, $p2 = null, $p3 = null)
@@ -132,10 +133,10 @@ public function __construct($message, $p2 = null, $p3 = null)
$code = $p2;
$this->cause = null;
} elseif (is_object($p2) || is_array($p2)) {
- if (!is_array($p2) && !($p2 instanceof Exception)) {
- if (!($p2 instanceof PEAR2_MultiErrors)) {
- throw new Exception('exception cause must be Exception, ' .
- 'array, or PEAR2_MultiErrors');
+ if (!is_array($p2) && !($p2 instanceof \Exception)) {
+ if (!($p2 instanceof \pear2\MultiErrors)) {
+ throw new \Exception('exception cause must be Exception, ' .
+ 'array, or \pear2\MultiErrors');
}
}
$code = $p3;
@@ -145,7 +146,7 @@ public function __construct($message, $p2 = null, $p3 = null)
$this->cause = null;
}
if (!is_string($message)) {
- throw new Exception('exception message must be a string, was ' . gettype($message));
+ throw new \Exception('exception message must be a string, was ' . gettype($message));
}
parent::__construct($message, $code);
$this->signal();
@@ -232,18 +233,18 @@ public function getCauseMessage(&$causes)
}
}
$causes[] = $cause;
- if ($this->cause instanceof PEAR2_Exception) {
+ if ($this->cause instanceof self) {
$this->cause->getCauseMessage($causes);
- } elseif ($this->cause instanceof Exception) {
+ } elseif ($this->cause instanceof \Exception) {
$causes[] = array('class' => get_class($this->cause),
'message' => $this->cause->getMessage(),
'file' => $this->cause->getFile(),
'line' => $this->cause->getLine());
- } elseif ($this->cause instanceof PEAR2_MultiErrors || is_array($this->cause)) {
+ } elseif ($this->cause instanceof \pear2\MultiErrors || is_array($this->cause)) {
foreach ($this->cause as $cause) {
- if ($cause instanceof PEAR2_Exception) {
+ if ($cause instanceof self) {
$cause->getCauseMessage($causes);
- } elseif ($cause instanceof Exception) {
+ } elseif ($cause instanceof \Exception) {
$causes[] = array('class' => get_class($cause),
'message' => $cause->getMessage(),
'file' => $cause->getFile(),
Please sign in to comment.
Something went wrong with that request. Please try again.