. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fisharebest\Webtrees\Module\ModuleInterface; use Fisharebest\Webtrees\Module\ModuleThemeInterface; use Fisharebest\Webtrees\Services\ModuleService; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use function method_exists; /** * Middleware to bootstrap the modules. */ class BootModules implements MiddlewareInterface { /** * @param ServerRequestInterface $request * @param RequestHandlerInterface $handler * * @return ResponseInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $module_service = app(ModuleService::class); $theme = app(ModuleThemeInterface::class); $bootable_modules = $module_service->all()->filter(static function (ModuleInterface $module) { return method_exists($module, 'boot'); }); foreach ($bootable_modules as $module) { // Only bootstrap the current theme. if ($module instanceof ModuleThemeInterface && $module !== $theme) { continue; } app()->dispatch($module, 'boot'); } return $handler->handle($request); } }