Allow apps to have their own autoloader

This will allow apps to also have a proper classmap and authorative
autoloader.

Currently if a file: <appdir>/composer/autoload.php exists we will use
it. Else we keep the current behavior.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-10-17 11:49:32 +02:00
parent cd0d27e46d
commit 3a9c24c04f
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 12 additions and 4 deletions

View File

@ -200,17 +200,25 @@ class OC_App {
if(isset(self::$alreadyRegistered[$key])) {
return;
}
self::$alreadyRegistered[$key] = true;
// Register on PSR-4 composer autoloader
$appNamespace = \OC\AppFramework\App::buildAppNamespace($app);
\OC::$server->registerNamespace($app, $appNamespace);
\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
if (file_exists($path . '/composer/autoload.php')) {
require_once $path . '/composer/autoload.php';
} else {
\OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);
// Register on legacy autoloader
\OC::$loader->addValidRoot($path);
}
// Register Test namespace only when testing
if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) {
\OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true);
}
// Register on legacy autoloader
\OC::$loader->addValidRoot($path);
}
/**