Use the improved PEAR Error handling.
authorGunnar Wrobel <p@rdus.de>
Tue, 26 Oct 2010 08:12:49 +0000 (10:12 +0200)
committerGunnar Wrobel <p@rdus.de>
Tue, 26 Oct 2010 08:12:49 +0000 (10:12 +0200)
components/lib/Components/Exception.php
components/lib/Components/Exception/Pear.php [new file with mode: 0644]
components/lib/Components/Pear/Factory.php
components/lib/Components/Pear/InstallLocation.php
components/lib/Components/Pear/Package.php
components/package.xml

index f0a1043..9fa466c 100644 (file)
@@ -28,6 +28,6 @@
  * @link     http://pear.horde.org/index.php?package=Components
  */
 class Components_Exception
-extends Exception
+extends Horde_Exception
 {
 }
diff --git a/components/lib/Components/Exception/Pear.php b/components/lib/Components/Exception/Pear.php
new file mode 100644 (file)
index 0000000..800d39a
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+/**
+ * This class converts PEAR errors into exceptions for the Components package.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Components
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Components
+ */
+
+/**
+ * This class converts PEAR errors into exceptions for the Components package.
+ *
+ * Copyright 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  Components
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Components
+ */
+class Components_Exception_Pear
+extends Horde_Exception_Pear
+{
+    /**
+     * 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)
+    {
+        self::$_class = __CLASS__;
+        return parent::catchError($result);
+    }
+}
index f0c7e11..36cbcca 100644 (file)
@@ -165,11 +165,9 @@ class Components_Pear_Factory
     )
     {
         $pkg = new PEAR_PackageFile($environment->getPearConfig());
-        $package_file = $pkg->fromPackageFile($package_xml_path, PEAR_VALIDATE_NORMAL);
-        if ($package_file instanceOf PEAR_Error) {
-            throw new Components_Exception($package_file->getMessage());
-        }
-        return $package_file;
+        return Components_Exception_Pear::catchError(
+            $pkg->fromPackageFile($package_xml_path, PEAR_VALIDATE_NORMAL)
+        );
     }
 
     /**
@@ -214,12 +212,10 @@ class Components_Pear_Factory
         $pkg->setPearinstallerDep('1.9.0');
         $pkg->setPackageType('php');
         new PEAR_Validate();
-        $package_file = $pkg->getDefaultGenerator()
-            ->toPackageFile($package_xml_dir, 0);
-        if ($package_file instanceOf PEAR_Error) {
-            throw new Components_Exception($package_file->getMessage());
-        };
-        return $package_file;
+        return Components_Exception_Pear::catchError(
+            $pkg->getDefaultGenerator()
+            ->toPackageFile($package_xml_dir, 0)
+        );
     }
 
     /**
@@ -246,32 +242,32 @@ class Components_Pear_Factory
             );
         }
 
-        $package_rw_file = PEAR_PackageFileManager2::importOptions(
-            $package_xml_path,
-            array(
-                'packagedirectory' => dirname($package_xml_path),
-                'filelistgenerator' => 'file',
-                'clearcontents' => false,
-                'clearchangelog' => false,
-                'simpleoutput' => true,
-                'ignore' => array('*~', 'conf.php', 'CVS/*'),
-                'include' => '*',
-                'dir_roles' =>
+        return Components_Exception_Pear::catchError(
+            PEAR_PackageFileManager2::importOptions(
+                $package_xml_path,
                 array(
-                    'doc'       => 'doc',
-                    'example'   => 'doc',
-                    'js'        => 'horde',
-                    'lib'       => 'php',
-                    'migration' => 'data',
-                    'script'    => 'script',
-                    'test'      => 'test',
-                ),
+                    'packagedirectory' => dirname($package_xml_path),
+                    'filelistgenerator' => 'file',
+                    'clearcontents' => false,
+                    'clearchangelog' => false,
+                    'simpleoutput' => true,
+                    'ignore' => array('*~', 'conf.php', 'CVS/*'),
+                    'include' => '*',
+                    'dir_roles' =>
+                    array(
+                        'bin'       => 'script',
+                        'script'    => 'script',
+                        'doc'       => 'doc',
+                        'example'   => 'doc',
+                        'js'        => 'horde',
+                        'horde'     => 'horde',
+                        'lib'       => 'php',
+                        'migration' => 'data',
+                        'scripts'   => 'data',
+                        'test'      => 'test',
+                    ),
+                )
             )
         );
-
-        if ($package_rw_file instanceOf PEAR_Error) {
-            throw new Components_Exception($package_rw_file->getMessage());
-        }
-        return $package_rw_file;
     }
 }
\ No newline at end of file
index a2e0fe7..eb7f2fb 100644 (file)
@@ -201,11 +201,9 @@ class Components_Pear_InstallLocation
         if (!file_exists($this->_config_file)) {
             $this->createPearConfig();
         }
-        $config = PEAR_Config::singleton($this->_config_file);
-        if ($config instanceOf PEAR_Error) {
-            throw new Components_Exception($config->getMessage());
-        }
-        return $config;
+        return Components_Exception_Pear::catchError(
+            PEAR_Config::singleton($this->_config_file)
+        );
     }
 
     /**
@@ -245,7 +243,9 @@ class Components_Pear_InstallLocation
             . $channel . '.channel.xml';
         if (file_exists($static)) {
             ob_start();
-            $channel_handler->doAdd('channel-add', array(), array($static));
+            Components_Exception_Pear::catchError(
+                $channel_handler->doAdd('channel-add', array(), array($static))
+            );
             $this->_output->pear(ob_get_clean());
         } else {
             $this->_output->warn(
@@ -255,7 +255,9 @@ class Components_Pear_InstallLocation
                 )
             );
             ob_start();
-            $channel_handler->doDiscover('channel-discover', array(), array($channel));
+            Components_Exception_Pear::catchError(
+                $channel_handler->doDiscover('channel-discover', array(), array($channel))
+            );
             $this->_output->pear(ob_get_clean());
         }
         $this->_output->ok(
index 6de68a6..0eb12c7 100644 (file)
@@ -251,10 +251,6 @@ class Components_Pear_Package
             }
         }
 
-        /**
-         * @todo: Looks like this throws away any <replace /> tags we have in
-         * the content list. Needs to be fixed.
-         */
         $package->generateContents();
 
         $updated = $package->getContents();
@@ -332,6 +328,7 @@ class Components_Pear_Package
                 );
             break;
             case 'js':
+            case 'horde':
                 $horde_role = true;
             case 'locale':
                 $package->addInstallAs(
@@ -465,12 +462,11 @@ class Components_Pear_Package
         $pkg->setDate(date('Y-m-d'));
         $pkg->setTime(date('H:i:s'));
         ob_start();
-        $result = $pkg->getDefaultGenerator()
-            ->toTgz(new PEAR_Common());
+        $result = Components_Exception_Pear::catchError(
+            $pkg->getDefaultGenerator()
+            ->toTgz(new PEAR_Common())
+        );
         $this->_output->pear(ob_get_clean());
-        if ($result instanceOf PEAR_Error) {
-            throw new Components_Exception($result->getMessage());
-        }
         $this->_output->ok('Generated snapshot ' . $result);
         return $result;
     }
index 459ec00..18e9ef5 100644 (file)
@@ -24,8 +24,8 @@
   <email>jan@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2010-10-23</date>
- <time>00:04:23</time>
+ <date>2010-10-26</date>
+ <time>10:08:57</time>
  <version>
   <release>0.0.1</release>
   <api>0.0.1</api>
@@ -60,6 +60,9 @@
      <dir name="Dependencies">
       <file name="Injector.php" role="php" />
      </dir> <!-- /lib/Components/Dependencies -->
+     <dir name="Exception">
+      <file name="Pear.php" role="php" />
+     </dir> <!-- /lib/Components/Exception -->
      <dir name="Helper">
       <dir name="Tree">
        <file name="Element.php" role="php" />
    <install as="Components/Config/Application.php" name="lib/Components/Config/Application.php" />
    <install as="Components/Config/Cli.php" name="lib/Components/Config/Cli.php" />
    <install as="Components/Dependencies/Injector.php" name="lib/Components/Dependencies/Injector.php" />
+   <install as="Components/Exception/Pear.php" name="lib/Components/Exception/Pear.php" />
    <install as="Components/Helper/InstallationRun.php" name="lib/Components/Helper/InstallationRun.php" />
    <install as="Components/Helper/ListRun.php" name="lib/Components/Helper/ListRun.php" />
    <install as="Components/Helper/Tree.php" name="lib/Components/Helper/Tree.php" />
     <release>alpha</release>
     <api>alpha</api>
    </stability>
-   <date>2010-10-23</date>
+   <date>2010-10-26</date>
    <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
    <notes>
 * Initial release