diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php index 4b9fe1b0c..575df2272 100644 --- a/library/Icinga/Application/ApplicationBootstrap.php +++ b/library/Icinga/Application/ApplicationBootstrap.php @@ -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 * diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index 3c754d661..1437f39a0 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -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 {