1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18use Fisharebest\Webtrees\DebugBar; 19use Fisharebest\Webtrees\Http\Middleware\BootModules; 20use Fisharebest\Webtrees\Http\Middleware\CheckCsrf; 21use Fisharebest\Webtrees\Http\Middleware\CheckForMaintenanceMode; 22use Fisharebest\Webtrees\Http\Middleware\DebugBarData; 23use Fisharebest\Webtrees\Http\Middleware\Emitter; 24use Fisharebest\Webtrees\Http\Middleware\ExceptionHandler; 25use Fisharebest\Webtrees\Http\Middleware\Housekeeping; 26use Fisharebest\Webtrees\Http\Middleware\ModuleMiddleware; 27use Fisharebest\Webtrees\Http\Middleware\RequestRouter; 28use Fisharebest\Webtrees\Http\Middleware\UpdateDatabaseSchema; 29use Fisharebest\Webtrees\Http\Middleware\UseCache; 30use Fisharebest\Webtrees\Http\Middleware\UseDatabase; 31use Fisharebest\Webtrees\Http\Middleware\UseFilesystem; 32use Fisharebest\Webtrees\Http\Middleware\UseLocale; 33use Fisharebest\Webtrees\Http\Middleware\UseSession; 34use Fisharebest\Webtrees\Http\Middleware\UseTheme; 35use Fisharebest\Webtrees\Http\Middleware\UseTransaction; 36use Fisharebest\Webtrees\Http\Middleware\UseTree; 37use Fisharebest\Webtrees\Http\Request as SymfonyRequest; 38use Fisharebest\Webtrees\Webtrees; 39use Middleland\Dispatcher; 40use Nyholm\Psr7\Factory\Psr17Factory; 41use Nyholm\Psr7Server\ServerRequestCreator; 42use Psr\Http\Message\ResponseFactoryInterface; 43use Psr\Http\Message\ServerRequestFactoryInterface; 44use Psr\Http\Message\StreamFactoryInterface; 45use Psr\Http\Message\UploadedFileFactoryInterface; 46use Psr\Http\Message\UriFactoryInterface; 47 48require __DIR__ . '/vendor/autoload.php'; 49 50const WT_ROOT = __DIR__ . DIRECTORY_SEPARATOR; 51 52Webtrees::init(); 53 54// Use nyholm/psr7 for our PSR7 messages and PSR17 factory. 55app()->bind(ResponseFactoryInterface::class, Psr17Factory::class); 56app()->bind(ServerRequestFactoryInterface::class, Psr17Factory::class); 57app()->bind(StreamFactoryInterface::class, Psr17Factory::class); 58app()->bind(UploadedFileFactoryInterface::class, Psr17Factory::class); 59app()->bind(UriFactoryInterface::class, Psr17Factory::class); 60 61// Use nyholm/psr7-server to create a request from the PHP environment. 62$server_request_creator = new ServerRequestCreator( 63 app(ServerRequestFactoryInterface::class), 64 app(UriFactoryInterface::class), 65 app(UploadedFileFactoryInterface::class), 66 app(StreamFactoryInterface::class) 67); 68 69// Create a PSR-7 request 70$request = $server_request_creator->fromGlobals(); 71 72// Initialise the DebugBar for development. 73// Use `composer install --dev` on a development build to enable. 74// Note that you may need to increase the size of the fcgi buffers on nginx. 75// e.g. add these lines to your fastcgi_params file: 76// fastcgi_buffers 16 16m; 77// fastcgi_buffer_size 32m; 78DebugBar::init(class_exists('\\DebugBar\\StandardDebugBar')); 79 80// Until all the code is rewritten to use PSR-7 requests, we still need our hybrid request. 81$request = SymfonyRequest::createFromGlobals(); 82 83// Calculate the base URL, so we can generate absolute URLs. 84// Remove any PHP script name and parameters. 85define('WT_BASE_URL', preg_replace('/[^\/]+\.php(\?.*)?$/', '', $request->getUri())); 86 87$middleware = [ 88 Emitter::class, 89 ExceptionHandler::class, 90 CheckForMaintenanceMode::class, 91 UseDatabase::class, 92 DebugBarData::class, 93 UpdateDatabaseSchema::class, 94 UseCache::class, 95 UseFilesystem::class, 96 UseSession::class, 97 UseTree::class, 98 UseLocale::class, 99 UseTheme::class, 100 Housekeeping::class, 101 CheckCsrf::class, 102 UseTransaction::class, 103 BootModules::class, 104 ModuleMiddleware::class, 105 RequestRouter::class, 106]; 107 108$dispatcher = new Dispatcher($middleware, app()); 109 110$dispatcher->dispatch($request); 111