Skip to content

Commit

Permalink
Add support for namespaced Application.php, Ajax\Application.php and …
Browse files Browse the repository at this point in the history
…Api.php

Add partial support for namespaced drivers and through this, Portal Blocks
  • Loading branch information
ralflang committed Dec 1, 2021
1 parent 049f581 commit f3ed2b7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/Horde/Core/Factory/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
29 changes: 28 additions & 1 deletion lib/Horde/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f3ed2b7

Please sign in to comment.