From f3ed2b79d8f58a2a516de7dd8b31dc834f30548a Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Wed, 1 Dec 2021 20:27:46 +0000 Subject: [PATCH] Add support for namespaced Application.php, Ajax\Application.php and Api.php Add partial support for namespaced drivers and through this, Portal Blocks --- lib/Horde/Core/Factory/Ajax.php | 5 +++++ lib/Horde/Registry.php | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/Horde/Core/Factory/Ajax.php b/lib/Horde/Core/Factory/Ajax.php index 1ee991186..f5b8af61c 100644 --- a/lib/Horde/Core/Factory/Ajax.php +++ b/lib/Horde/Core/Factory/Ajax.php @@ -38,6 +38,11 @@ class Horde_Core_Factory_Ajax extends Horde_Core_Factory_Base */ public function create($app, $vars, $action = null, $token = null) { + $class = 'Horde\\' . ucfirst($app) . '\\Ajax\\Application'; + + if (class_exists($class)) { + return new $class($app, $vars, $action, $token); + } $class = $app . '_Ajax_Application'; if (class_exists($class)) { diff --git a/lib/Horde/Registry.php b/lib/Horde/Registry.php index ec3fd2152..87475c602 100644 --- a/lib/Horde/Registry.php +++ b/lib/Horde/Registry.php @@ -833,6 +833,16 @@ public function getApiInstance($app, $type) } $cname = Horde_String::ucfirst($type); + // PSR-4 case: Autoloading should already be handled by composer + $classnamePsr4 = 'Horde\\' . Horde_String::ucfirst($app) . '\\' . $cname; + if (class_exists($classnamePsr4)) { + $this->_cache['ob'][$app][$type] = ($type == 'application') + ? new $classnamePsr4($app) + : new $classnamePsr4(); + + return $this->_cache['ob'][$app][$type]; + } + // Continue with unnamespaced version /* Can't autoload here, since the application may not have been * initialized yet. */ @@ -1996,6 +2006,9 @@ public function getView() /** * Returns a list of available drivers for a library that are available * in an application. + * + * @todo support namespaced prefixes with multiple levels + * * * @param string $app The application name. * @param string $prefix The library prefix. @@ -2024,7 +2037,21 @@ public function getAppDrivers($app, $prefix) foreach ($di as $val) { if (!$val->isDir() && !$di->isDot()) { - $class = $app . '_' . $prefix . '_' . basename($val, '.php'); + $class = ucfirst($app) . '_' . $prefix . '_' . basename($val, '.php'); + if (class_exists($class)) { + $classes[] = $class; + } + } + } + } catch (UnexpectedValueException $e) {} + } + if (is_dir($fileroot . '/src/' . $fileprefix)) { + try { + $di = new DirectoryIterator($fileroot . '/src/' . $fileprefix); + + foreach ($di as $val) { + if (!$val->isDir() && !$di->isDot()) { + $class = 'Horde\\' . ucfirst($app) . '\\' . $prefix . '\\' . basename($val, '.php'); if (class_exists($class)) { $classes[] = $class; }