From d1c70514b002b1d0ce4783353bac7c9042c60140 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 9 Jul 2010 00:25:04 -0600 Subject: [PATCH] Don't use Horde-specific app assumption in factory. --- framework/Crypt/lib/Horde/Crypt.php | 29 +++++++++++-------------- framework/Text_Filter/lib/Horde/Text/Filter.php | 27 ++++++++++------------- imp/lib/Injector/Binder/Pgp.php | 2 +- imp/lib/Injector/Binder/Smime.php | 2 +- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/framework/Crypt/lib/Horde/Crypt.php b/framework/Crypt/lib/Horde/Crypt.php index 2aa6b071c..bcafb38ff 100644 --- a/framework/Crypt/lib/Horde/Crypt.php +++ b/framework/Crypt/lib/Horde/Crypt.php @@ -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.'); } /** diff --git a/framework/Text_Filter/lib/Horde/Text/Filter.php b/framework/Text_Filter/lib/Horde/Text/Filter.php index 5caab0020..9dc0aa435 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter.php @@ -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.'); } /** diff --git a/imp/lib/Injector/Binder/Pgp.php b/imp/lib/Injector/Binder/Pgp.php index 51675eab7..da94bbc3d 100644 --- a/imp/lib/Injector/Binder/Pgp.php +++ b/imp/lib/Injector/Binder/Pgp.php @@ -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); } /** diff --git a/imp/lib/Injector/Binder/Smime.php b/imp/lib/Injector/Binder/Smime.php index e762c0ebb..9166cc013 100644 --- a/imp/lib/Injector/Binder/Smime.php +++ b/imp/lib/Injector/Binder/Smime.php @@ -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() )); } -- 2.11.0