Пример #1
0
<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
use Pimple\Container;
$app = new Container();
Facade::setApp($app);
(new Error\Handler())->error(function (HttpRouteNotFoundException $e) {
    echo "404";
})->error(function (HttpMethodNotAllowedException $e) {
    echo "405";
})->error(function (Exception $e) {
    throw $e;
});
$app['paths'] = array('app' => __DIR__, 'config' => __DIR__ . '/config', 'public' => __DIR__ . '/../public');
$app['config'] = function (Pimple $app) {
    return new Config\Repository(new Config\FileLoader($app['paths']['config']));
};
$app['request'] = function () {
    return Request::createFromGlobals();
};
$app['router'] = new Phroute\Phroute\RouteCollector(new Phroute\Phroute\RouteParser());
include __DIR__ . '/routes.php';
$dispatcher = new Phroute\Phroute\Dispatcher($app['router']->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], processInput($_SERVER['REQUEST_URI']));
$response instanceof Response or $response = Response::create($response);
$response->send();
function processInput($uri)
{