Don't use Horde-specific app assumption in factory.
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 9 Jul 2010 06:25:04 +0000 (00:25 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 9 Jul 2010 07:04:14 +0000 (01:04 -0600)
framework/Crypt/lib/Horde/Crypt.php
framework/Text_Filter/lib/Horde/Text/Filter.php
imp/lib/Injector/Binder/Pgp.php
imp/lib/Injector/Binder/Smime.php

index 2aa6b07..bcafb38 100644 (file)
@@ -23,37 +23,34 @@ class Horde_Crypt
     /**
      * Attempts to return a concrete Horde_Crypt instance based on $driver.
      *
-     * @param mixed $driver  The type of concrete Horde_Crypt subclass to
-     *                       return. If $driver is an array, then we will look
-     *                       in $driver[0]/lib/Crypt/ for the subclass
-     *                       implementation named $driver[1].php.
-     * @param array $params  A hash containing any additional configuration or
-     *                       parameters a subclass might need.
+     * @param string $driver  Either a driver name, or the full class name to
+     *                        use (class must extend Horde_Crypt).
+     * @param array $params   A hash containing any additional configuration
+     *                        or parameters a subclass might need.
      *
-     * @return Horde_Crypt  The newly created concrete Horde_Crypt instance.
+     * @return Horde_Crypt  The newly created concrete instance.
      * @throws Horde_Exception
      */
     static public function factory($driver, $params = array())
     {
-        if (is_array($driver)) {
-            list($app, $driv_name) = $driver;
-            $driver = basename($driv_name);
-        } else {
-            $driver = basename($driver);
-        }
-
         /* Return a base Horde_Crypt object if no driver is specified. */
         if (empty($driver) || (strcasecmp($driver, 'none') == 0)) {
             return new Horde_Crypt();
         }
 
-        $class = (empty($app) ? 'Horde' : $app) . '_Crypt_' . ucfirst($driver);
+        /* Base drivers (in Crypt/ directory). */
+        $class = __CLASS__ . '_' . ucfirst(basename($driver));
+        if (class_exists($class)) {
+            return new $class($params);
+        }
 
+        /* Explicit class name, */
+        $class = $driver;
         if (class_exists($class)) {
             return new $class($params);
         }
 
-        throw new Horde_Exception('Class definition of ' . $class . ' not found.');
+        throw new Horde_Exception(__CLASS__ . ': Class definition of ' . $driver . ' not found.');
     }
 
     /**
index 5caab00..9dc0aa4 100644 (file)
@@ -16,32 +16,29 @@ class Horde_Text_Filter
     /**
      * Attempts to return a concrete instance based on $driver.
      *
-     * @param mixed $driver  The type of concrete subclass to return.
-     *                       This is based on the filter driver ($driver). The
-     *                       code is dynamically included. If $driver is an
-     *                       array, then we will look in $driver[0] for the
-     *                       subclass implementation named $driver[1].php.
-     * @param array $params  A hash containing any additional configuration
-     *                       parameters a subclass might need.
+     * @param string $driver  Either a driver name, or the full class name to
+     *                        use (class must extend Horde_Text_Filter_Base).
+     * @param array $params   A hash containing any additional configuration
+     *                        parameters a subclass might need.
      *
-     * @return Text_Filter  The newly created concrete instance.
+     * @return Horde_Text_Filter_Base  The newly created concrete instance.
      * @throws Horde_Exception
      */
     static public function factory($driver, $params = array())
     {
-        if (is_array($driver)) {
-            list($app, $driv_name) = $driver;
-            $driver = basename($driv_name);
-        } else {
-            $driver = basename($driver);
+        /* Base drivers (in Filter/ directory). */
+        $class = __CLASS__ . '_' . ucfirst(basename($driver));
+        if (class_exists($class)) {
+            return new $class($params);
         }
 
-        $class = (empty($app) ? 'Horde' : $app) . '_Text_Filter_' . ucfirst($driver);
+        /* Explicit class name, */
+        $class = $driver;
         if (class_exists($class)) {
             return new $class($params);
         }
 
-        throw new Horde_Exception('Class definition of ' . $class . ' not found.');
+        throw new Horde_Exception(__CLASS__ . ': Class definition of ' . $driver . ' not found.');
     }
 
     /**
index 51675ea..da94bbc 100644 (file)
@@ -30,7 +30,7 @@ class IMP_Injector_Binder_Pgp implements Horde_Injector_Binder
             }
         }
 
-        return Horde_Crypt::factory(array('IMP', 'Pgp'), $params);
+        return Horde_Crypt::factory('IMP_Crypt_Pgp', $params);
     }
 
     /**
index e762c0e..9166cc0 100644 (file)
@@ -18,7 +18,7 @@ class IMP_Injector_Binder_Smime implements Horde_Injector_Binder
      */
     public function create(Horde_Injector $injector)
     {
-        return Horde_Crypt::factory(array('IMP', 'Smime'), array(
+        return Horde_Crypt::factory('IMP_Crypt_Smime', array(
             'temp' => Horde::getTempDir()
         ));
     }