Perhaps an extra method to Zend would be helpful - Zend::loadComponent
(). It would allow you to assemble the name of a class with a prefix,
use Zend::loadClass to ensure it exists and returns either a
formatted class name or false.
E.g. If I have a $dbtype with 'PDO_MYSQL', 'pdoMysql' or 'pdo_mysql'
as the adapter, I could call:-
$adapter = Zend::loadComponent($dbtype, 'Zend_Db');
$db = new $adapter($config);
I don't see it as any more bloat than existing factory methods and
provides the convenience of preserving the underscore convention of
classes without imposing overly-tight restrictions on your data/config.
Quick example:-
static public function loadComponent($class, $prefix = null)
{
$class = self::formatClassName($prefix . '_' . $class);
self::loadClass($class);
return $class;
}
static public function formatClassName($class)
{
$class = preg_replace('/([a-z])([A-Z])/', "$1_$2", $class);
$class = trim(ucwords(str_replace('_', ' ', strtolower($class))));
$class = str_replace(' ', '_', $class);
return $class;
}
--
Simon Mundy | Director | PEPTOLAB
""" " "" """""" "" "" """"""" " "" """"" " """"" " """""" "" "
202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654
4124
http://www.peptolab.com