HummingBirdAnimeClient/app/bootstrap.php

72 lines
2.1 KiB
PHP

<?php
/**
* Bootstrap / Dependency Injection
*/
namespace Aviat\AnimeClient;
use \Whoops\Handler\PrettyPageHandler;
use \Whoops\Handler\JsonResponseHandler;
use \Aura\Web\WebFactory;
use \Aura\Router\RouterFactory;
use \Aura\Di\Container as DiContainer;
use \Aura\Di\Factory as DiFactory;
require _dir(SRC_DIR, '/functions.php');
// -----------------------------------------------------------------------------
// Setup DI container
// -----------------------------------------------------------------------------
$container = new Container();
// -----------------------------------------------------------------------------
// Setup error handling
// -----------------------------------------------------------------------------
$whoops = new \Whoops\Run();
// Set up default handler for general errors
$defaultHandler = new PrettyPageHandler();
$whoops->pushHandler($defaultHandler);
// Set up json handler for ajax errors
$jsonHandler = new JsonResponseHandler();
$jsonHandler->onlyForAjaxRequests(true);
$whoops->pushHandler($jsonHandler);
$whoops->register();
$container->set('error-handler', $defaultHandler);
// -----------------------------------------------------------------------------
// Injected Objects
// -----------------------------------------------------------------------------
// Create Config Object
$config = new Config();
$container->set('config', $config);
// Create Aura Router Object
$router_factory = new RouterFactory();
$aura_router = $router_factory->newInstance();
$container->set('aura-router', $aura_router);
// Create Request/Response Objects
$web_factory = new WebFactory([
'_GET' => $_GET,
'_POST' => $_POST,
'_COOKIE' => $_COOKIE,
'_SERVER' => $_SERVER,
'_FILES' => $_FILES
]);
$container->set('request', $web_factory->newRequest());
$container->set('response', $web_factory->newResponse());
// -----------------------------------------------------------------------------
// Router
// -----------------------------------------------------------------------------
$container->set('url-generator', new UrlGenerator($container));
$router = new Router($container);
$router->dispatch();
// End of bootstrap.php