HummingBirdAnimeClient/app/bootstrap.php

72 lines
2.1 KiB
PHP
Raw Normal View History

2015-06-29 09:46:49 -04:00
<?php
/**
* Bootstrap / Dependency Injection
*/
2015-06-29 09:46:49 -04:00
2015-09-14 19:54:34 -04:00
namespace Aviat\AnimeClient;
2015-06-29 09:46:49 -04:00
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 Base\Container();
2015-06-29 09:46:49 -04:00
// -----------------------------------------------------------------------------
// 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);
2015-06-29 09:46:49 -04:00
// -----------------------------------------------------------------------------
// Injected Objects
// -----------------------------------------------------------------------------
// Create Config Object
$config = new Base\Config();
$container->set('config', $config);
2015-06-29 09:46:49 -04:00
// Create Aura Router Object
$router_factory = new RouterFactory();
$aura_router = $router_factory->newInstance();
$container->set('aura-router', $aura_router);
2015-06-29 09:46:49 -04:00
// 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());
2015-06-29 09:46:49 -04:00
// -----------------------------------------------------------------------------
// Router
// -----------------------------------------------------------------------------
2015-09-14 15:49:20 -04:00
$container->set('url-generator', new Base\UrlGenerator($container));
$router = new Base\Router($container);
2015-06-29 09:46:49 -04:00
$router->dispatch();
// End of bootstrap.php