flarum/index.php

61 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2015-08-26 07:43:18 +00:00
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Flarum\Core;
2015-08-26 07:43:18 +00:00
use Flarum\Forum\Middleware\HandleErrors;
use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware;
use Zend\Diactoros\Server;
use Zend\Stratigility\MiddlewarePipe;
2015-08-13 00:43:08 +00:00
$app = require __DIR__.'/flarum/bootstrap.php';
2015-08-26 07:43:18 +00:00
// If Flarum's configuration exists, then we can assume that installation has
// been completed. We will set up a middleware pipe to route the request through
// to one of the main forum actions.
if (Core::isInstalled()) {
2015-08-17 04:42:52 +00:00
$app->register('Flarum\Forum\ForumServiceProvider');
$flarum = new MiddlewarePipe();
$flarum->pipe($app->make('Flarum\Forum\Middleware\LoginWithCookie'));
$flarum->pipe($app->make('Flarum\Api\Middleware\ReadJsonParameters'));
2015-08-26 22:48:54 +00:00
$basePath = parse_url(Core::url(), PHP_URL_PATH);
2015-08-26 07:43:18 +00:00
$router = $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.forum.routes')]);
$flarum->pipe($basePath, $router);
2015-08-17 04:42:52 +00:00
if (Core::inDebugMode()) {
2015-08-26 07:43:18 +00:00
$flarum->pipe(new WhoopsMiddleware());
2015-08-17 04:42:52 +00:00
} else {
2015-08-26 07:43:18 +00:00
$flarum->pipe(new HandleErrors(base_path('error')));
2015-08-17 04:42:52 +00:00
}
} else {
2015-08-17 04:42:52 +00:00
$app->register('Flarum\Install\InstallServiceProvider');
$flarum = new MiddlewarePipe();
2015-08-17 05:02:14 +00:00
$basePath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
2015-08-26 07:43:18 +00:00
$router = $app->make('Flarum\Http\RouterMiddleware', ['routes' => $app->make('flarum.install.routes')]);
$flarum->pipe($basePath, $router);
$flarum->pipe(new WhoopsMiddleware());
}
$server = Server::createServer(
2015-08-26 07:43:18 +00:00
$flarum,
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);
$server->listen();