10cfd6963SGreg Roach<?php 2*3976b470SGreg Roach 30cfd6963SGreg Roach/** 40cfd6963SGreg Roach * webtrees: online genealogy 50cfd6963SGreg Roach * Copyright (C) 2019 webtrees development team 60cfd6963SGreg Roach * This program is free software: you can redistribute it and/or modify 70cfd6963SGreg Roach * it under the terms of the GNU General Public License as published by 80cfd6963SGreg Roach * the Free Software Foundation, either version 3 of the License, or 90cfd6963SGreg Roach * (at your option) any later version. 100cfd6963SGreg Roach * This program is distributed in the hope that it will be useful, 110cfd6963SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 120cfd6963SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 130cfd6963SGreg Roach * GNU General Public License for more details. 140cfd6963SGreg Roach * You should have received a copy of the GNU General Public License 150cfd6963SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 160cfd6963SGreg Roach */ 170cfd6963SGreg Roachdeclare(strict_types=1); 180cfd6963SGreg Roach 190cfd6963SGreg Roachnamespace Fisharebest\Webtrees\Http\Middleware; 200cfd6963SGreg Roach 210cfd6963SGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface; 220cfd6963SGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface; 230cfd6963SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 246ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 256ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 266ccdf4f0SGreg Roachuse Psr\Http\Server\MiddlewareInterface; 276ccdf4f0SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 28*3976b470SGreg Roach 290cfd6963SGreg Roachuse function method_exists; 300cfd6963SGreg Roach 310cfd6963SGreg Roach/** 320cfd6963SGreg Roach * Middleware to bootstrap the modules. 330cfd6963SGreg Roach */ 340cfd6963SGreg Roachclass BootModules implements MiddlewareInterface 350cfd6963SGreg Roach{ 360cfd6963SGreg Roach /** 376ccdf4f0SGreg Roach * @param ServerRequestInterface $request 386ccdf4f0SGreg Roach * @param RequestHandlerInterface $handler 390cfd6963SGreg Roach * 406ccdf4f0SGreg Roach * @return ResponseInterface 410cfd6963SGreg Roach */ 426ccdf4f0SGreg Roach public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface 430cfd6963SGreg Roach { 440cfd6963SGreg Roach $module_service = app(ModuleService::class); 450cfd6963SGreg Roach $theme = app(ModuleThemeInterface::class); 460cfd6963SGreg Roach 470b5fd0a6SGreg Roach $bootable_modules = $module_service->all()->filter(static function (ModuleInterface $module) { 480cfd6963SGreg Roach return method_exists($module, 'boot'); 490cfd6963SGreg Roach }); 500cfd6963SGreg Roach 510cfd6963SGreg Roach foreach ($bootable_modules as $module) { 520cfd6963SGreg Roach // Only bootstrap the current theme. 530cfd6963SGreg Roach if ($module instanceof ModuleThemeInterface && $module !== $theme) { 540cfd6963SGreg Roach continue; 550cfd6963SGreg Roach } 560cfd6963SGreg Roach 573e4bf26fSGreg Roach app()->dispatch($module, 'boot'); 580cfd6963SGreg Roach } 590cfd6963SGreg Roach 606ccdf4f0SGreg Roach return $handler->handle($request); 610cfd6963SGreg Roach } 620cfd6963SGreg Roach} 63