Skip to content

Commit

Permalink
More intelligent way to search for classnames in factories
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jan 28, 2014
1 parent 37f442b commit e02ef35
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions framework/Core/lib/Horde/Core/Factory/Base.php
Expand Up @@ -58,13 +58,28 @@ public function __construct(Horde_Injector $injector)
*/
protected function _getDriverName($driver, $base)
{
$class = $base . '_' . Horde_String::ucfirst($driver);
if (class_exists($class)) {
return $class;
}
/* Intelligent loading... if we see at least one separator character
* in the driver name, guess that this is a full classname so try that
* option first. */
$search = (strpbrk($driver, '\\_') === false)
? array('driver', 'class')
: array('class', 'driver');

foreach ($search as $val) {
switch ($val) {
case 'class':
if (class_exists($driver)) {
return $driver;
}
break;

if (class_exists($driver)) {
return $driver;
case 'driver':
$class = $base . '_' . Horde_String::ucfirst($driver);
if (class_exists($class)) {
return $class;
}
break;
}
}

throw new Horde_Exception('"' . $driver . '" driver (for ' . $base . ' not found).');
Expand Down

0 comments on commit e02ef35

Please sign in to comment.