diff --git a/src/Core/ModuleManager.php b/src/Core/ModuleManager.php index 19b775489b..9ddf9030e2 100644 --- a/src/Core/ModuleManager.php +++ b/src/Core/ModuleManager.php @@ -1,7 +1,6 @@ . - // }}} /** @@ -36,10 +34,22 @@ namespace App\Core; use App\Util\Formatting; + +use AppendIterator; +use FilesystemIterator; use Functional as F; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; class ModuleManager { + public function __construct() + { + if (!defined('CACHE_FILE')) { + define('CACHE_FILE', INSTALLDIR . '/var/cache/module_manager.php'); + } + } + protected static $loader; public static function setLoader($l) { @@ -72,6 +82,23 @@ class ModuleManager } } + public static function process() + { + $module_paths = array_merge(glob(INSTALLDIR . '/components/*/*.php'), glob(INSTALLDIR . '/plugins/*/*.php')); + $module_manager = new self(); + foreach ($module_paths as $path) { + // 'modules' and 'plugins' have the same length + $type = ucfirst(preg_replace('%' . INSTALLDIR . '/(component|plugin)s/.*%', '\1', $path)); + $module = basename(dirname($path)); + $fqcn = "\\{$type}\\{$module}\\{$module}"; + $module_manager->add($fqcn, $path); + } + + $module_manager->preRegisterEvents(); + + file_put_contents(CACHE_FILE, "append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(INSTALLDIR . '/components', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS))); + $rdi->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(INSTALLDIR . '/plugins', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS))); + $time = file_exists(CACHE_FILE) ? filemtime(CACHE_FILE) : 0; + + if (F\some($rdi, function ($e) use ($time) { return $e->getMTime() > $time; })) { + self::process(); + } + } + + $obj = require CACHE_FILE; + foreach ($obj->events as $event => $callables) { foreach ($callables as $callable) { Event::addHandler($event, $callable); diff --git a/src/DependencyInjection/Compiler/ModuleManagerPass.php b/src/DependencyInjection/Compiler/ModuleManagerPass.php index a071484990..c27998276e 100644 --- a/src/DependencyInjection/Compiler/ModuleManagerPass.php +++ b/src/DependencyInjection/Compiler/ModuleManagerPass.php @@ -41,18 +41,6 @@ class ModuleManagerPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { - $module_paths = array_merge(glob(INSTALLDIR . '/components/*/*.php'), glob(INSTALLDIR . '/plugins/*/*.php')); - $module_manager = new ModuleManager(); - foreach ($module_paths as $path) { - // 'modules' and 'plugins' have the same length - $type = ucfirst(preg_replace('%' . INSTALLDIR . '/(component|plugin)s/.*%', '\1', $path)); - $module = basename(dirname($path)); - $fqcn = "\\{$type}\\{$module}\\{$module}"; - $module_manager->add($fqcn, $path); - } - - $module_manager->preRegisterEvents(); - - file_put_contents(INSTALLDIR . '/var/cache/module_manager.php', "