Merge pull request #3114 from Icinga/feature/support-phar-3113

Modules, Bootstrap: play nice with PHARs
This commit is contained in:
lippserd 2017-11-27 09:15:34 +01:00 committed by GitHub
commit 5aa83ea0d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 6 deletions

View File

@ -9,10 +9,8 @@ use LogicException;
use Icinga\Application\Modules\Manager as ModuleManager;
use Icinga\Authentication\User\UserBackend;
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\NotReadableError;
use Icinga\Application\Logger;
use Icinga\Util\Translator;
use Icinga\Exception\IcingaException;
@ -141,7 +139,11 @@ abstract class ApplicationBootstrap
$this->baseDir = $baseDir;
$this->appDir = $baseDir . '/application';
$this->vendorDir = $baseDir . '/library/vendor';
$this->libDir = realpath(__DIR__ . '/../..');
if (substr(__DIR__, 0, 8) === 'phar:///') {
$this->libDir = dirname(dirname(__DIR__));
} else {
$this->libDir = realpath(__DIR__ . '/../..');
}
$this->setupAutoloader();
@ -403,14 +405,37 @@ abstract class ApplicationBootstrap
*/
protected function setupModuleManager()
{
$paths = $this->getAvailableModulePaths();
$this->moduleManager = new ModuleManager(
$this,
$this->configDir . '/enabledModules',
explode(':', $this->config->get('global', 'module_path', $this->baseDir . '/modules'))
$paths
);
return $this;
}
protected function getAvailableModulePaths()
{
$paths = array();
$configured = $this->config->get('global', 'module_path', $this->baseDir . '/modules');
$nextIsPhar = false;
foreach (explode(':', $configured) as $path) {
if ($path === 'phar') {
$nextIsPhar = true;
continue;
}
if ($nextIsPhar) {
$nextIsPhar = false;
$paths[] = 'phar:' . $path;
} else {
$paths[] = $path;
}
}
return $paths;
}
/**
* Load all enabled modules
*

View File

@ -141,6 +141,7 @@ class Manager
);
}
if (($dh = opendir($this->enableDir)) !== false) {
$isPhar = substr($this->enableDir, 0, 8) === 'phar:///';
$this->enabledDirs = array();
while (($file = readdir($dh)) !== false) {
if ($file[0] === '.' || $file === 'README') {
@ -148,7 +149,7 @@ class Manager
}
$link = $this->enableDir . DIRECTORY_SEPARATOR . $file;
if (! is_link($link)) {
if (! $isPhar && ! is_link($link)) {
Logger::warning(
'Found invalid module in enabledModule directory "%s": "%s" is not a symlink',
$this->enableDir,
@ -157,7 +158,7 @@ class Manager
continue;
}
$dir = realpath($link);
$dir = $isPhar ? $link : realpath($link);
if ($dir !== false && is_dir($dir)) {
$this->enabledDirs[$file] = $dir;
} else {