diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:43:12 +0000 |
commit | cd989f9c3aff968e19a3aeabc4eb9085787a6673 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/Application/DependencyChecker.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.tar.xz icingaweb2-module-director-cd989f9c3aff968e19a3aeabc4eb9085787a6673.zip |
Adding upstream version 1.10.2.upstream/1.10.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Application/DependencyChecker.php')
-rw-r--r-- | library/Director/Application/DependencyChecker.php | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/library/Director/Application/DependencyChecker.php b/library/Director/Application/DependencyChecker.php new file mode 100644 index 0000000..d726b0b --- /dev/null +++ b/library/Director/Application/DependencyChecker.php @@ -0,0 +1,73 @@ +<?php + +namespace Icinga\Module\Director\Application; + +use Icinga\Application\ApplicationBootstrap; +use Icinga\Application\Modules\Module; +use Icinga\Application\Version; + +class DependencyChecker +{ + /** @var ApplicationBootstrap */ + protected $app; + + /** @var \Icinga\Application\Modules\Manager */ + protected $modules; + + public function __construct(ApplicationBootstrap $app) + { + $this->app = $app; + $this->modules = $app->getModuleManager(); + } + + /** + * @param Module $module + * @return Dependency[] + */ + public function getDependencies(Module $module) + { + $dependencies = []; + $isV290 = version_compare(Version::VERSION, '2.9.0', '>='); + foreach ($module->getDependencies() as $moduleName => $required) { + if ($isV290 && in_array($moduleName, ['ipl', 'reactbundle'], true)) { + continue; + } + $dependency = new Dependency($moduleName, $required); + $dependency->setEnabled($this->modules->hasEnabled($moduleName)); + if ($this->modules->hasInstalled($moduleName)) { + $dependency->setInstalledVersion($this->modules->getModule($moduleName, false)->getVersion()); + } + $dependencies[] = $dependency; + } + if ($isV290) { + $libs = $this->app->getLibraries(); + foreach ($module->getRequiredLibraries() as $libraryName => $required) { + $dependency = new Dependency($libraryName, $required); + if ($libs->has($libraryName)) { + $dependency->setInstalledVersion($libs->get($libraryName)->getVersion()); + $dependency->setEnabled(); + } + $dependencies[] = $dependency; + } + } + + return $dependencies; + } + + // if (version_compare(Version::VERSION, '2.9.0', 'ge')) { + // } + /** + * @param Module $module + * @return bool + */ + public function satisfiesDependencies(Module $module) + { + foreach ($this->getDependencies($module) as $dependency) { + if (! $dependency->isSatisfied()) { + return false; + } + } + + return true; + } +} |