--- /dev/null
+<?php
+/**
+ * Horde exception class that converts PEAR errors to exceptions.
+ *
+ * Copyright 2008-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Horde_Exception
+ */
+class Horde_Exception_Pear extends Horde_Exception
+{
+ /**
+ * The class name for generated exceptions.
+ *
+ * @var string
+ */
+ static protected $_class = __CLASS__;
+
+ /**
+ * The original PEAR error.
+ *
+ * @var PEAR_Error
+ */
+ private $_error;
+
+ /**
+ * Exception constructor.
+ *
+ * @param PEAR_Error $error The PEAR error.
+ */
+ public function __construct(PEAR_Error $error)
+ {
+ parent::__construct(
+ $error->getMessage() . $this->_getPearTrace(),
+ $error->getCode()
+ );
+ }
+
+ /**
+ * Return a trace for the PEAR error.
+ *
+ * @param PEAR_Error $error The PEAR error.
+ *
+ * @return string The backtrace as a string.
+ */
+ private function _getPearTrace(PEAR_Error $error)
+ {
+ $backtrace = $error->getBacktrace();
+ if (!empty($backtrace)) {
+ $pear_error .= "\n\n" . 'PEAR Error:' . "\n";
+ foreach ($backtrace as $frame) {
+ $pear_error .= ' ' . $frame['class'] . '->'
+ . $frame['function'] . ' ' . $frame['file']
+ . ':' . $frame['line'] . "\n";
+ }
+ $pear_error .= "\n";
+ return $pear_error;
+ }
+ return '';
+ }
+
+ /**
+ * Exception handling.
+ *
+ * @param mixed $result The result to be checked for a PEAR_Error.
+ *
+ * @return mixed Returns the original result if it was no PEAR_Error.
+ *
+ * @throws Horde_Exception_Pear In case the result was a PEAR_Error.
+ */
+ static public function catchError($result)
+ {
+ if ($result instanceOf PEAR_Error) {
+ throw new self::$_class($result);
+ }
+ return $result;
+ }
+}
<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.9.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" 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.0 http://pear.php.net/dtd/package-2.0.xsd">
+<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" 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.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>Exception</name>
<channel>pear.horde.org</channel>
<summary>Horde Exception Handler</summary>
<email>slusarz@horde.org</email>
<active>yes</active>
</developer>
- <date>2010-10-22</date>
- <time>19:03:02</time>
+ <date>2010-10-26</date>
+ <time>08:24:18</time>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
<dir name="Exception">
<file name="LastError.php" role="php" />
<file name="NotFound.php" role="php" />
+ <file name="Pear.php" role="php" />
<file name="PermissionDenied.php" role="php" />
<file name="Prior.php" role="php" />
<file name="Translation.php" role="php">
<install as="Horde/Exception.php" name="lib/Horde/Exception.php" />
<install as="Horde/Exception/LastError.php" name="lib/Horde/Exception/LastError.php" />
<install as="Horde/Exception/NotFound.php" name="lib/Horde/Exception/NotFound.php" />
+ <install as="Horde/Exception/Pear.php" name="lib/Horde/Exception/Pear.php" />
<install as="Horde/Exception/PermissionDenied.php" name="lib/Horde/Exception/PermissionDenied.php" />
<install as="Horde/Exception/Prior.php" name="lib/Horde/Exception/Prior.php" />
<install as="Horde/Exception/Translation.php" name="lib/Horde/Exception/Translation.php" />
<release>beta</release>
<api>beta</api>
</stability>
- <date>2010-10-22</date>
+ <date>2010-10-26</date>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
<notes>
* Initial package.