2015-05-22 12:36:26 -04:00
|
|
|
<?php
|
2015-06-16 11:11:35 -04:00
|
|
|
/**
|
2015-11-16 11:40:01 -05:00
|
|
|
* Hummingbird Anime Client
|
|
|
|
*
|
|
|
|
* An API client for Hummingbird to manage anime and manga watch lists
|
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2015
|
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
|
|
|
* @license MIT
|
2015-06-16 11:11:35 -04:00
|
|
|
*/
|
2015-10-09 14:34:55 -04:00
|
|
|
use Whoops\Handler\PrettyPageHandler;
|
|
|
|
use Whoops\Handler\JsonResponseHandler;
|
|
|
|
|
2015-06-25 17:00:29 -04:00
|
|
|
// Work around the silly timezone error
|
|
|
|
$timezone = ini_get('date.timezone');
|
|
|
|
if ($timezone === '' || $timezone === FALSE)
|
|
|
|
{
|
|
|
|
ini_set('date.timezone', 'GMT');
|
|
|
|
}
|
2015-06-11 16:44:52 -04:00
|
|
|
|
2015-06-29 09:46:49 -04:00
|
|
|
// Define base directories
|
2015-06-11 16:44:52 -04:00
|
|
|
define('ROOT_DIR', __DIR__);
|
2015-06-25 17:00:29 -04:00
|
|
|
define('APP_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'app');
|
2015-09-14 10:54:50 -04:00
|
|
|
define('SRC_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'src');
|
2015-06-25 17:00:29 -04:00
|
|
|
define('CONF_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'config');
|
2015-09-14 10:54:50 -04:00
|
|
|
define('BASE_DIR', SRC_DIR . DIRECTORY_SEPARATOR . 'Base');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Joins paths together. Variadic to take an
|
|
|
|
* arbitrary number of arguments
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function _dir()
|
|
|
|
{
|
|
|
|
return implode(DIRECTORY_SEPARATOR, func_get_args());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up autoloaders
|
|
|
|
*
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-10-06 10:24:48 -04:00
|
|
|
spl_autoload_register(function($class) {
|
2015-09-16 12:25:35 -04:00
|
|
|
$class_parts = explode('\\', $class);
|
|
|
|
$ns_path = SRC_DIR . '/' . implode('/', $class_parts) . ".php";
|
|
|
|
|
|
|
|
if (file_exists($ns_path))
|
|
|
|
{
|
|
|
|
require_once($ns_path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
2015-05-22 12:36:26 -04:00
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
require _dir(ROOT_DIR, '/vendor/autoload.php');
|
2015-10-09 14:34:55 -04:00
|
|
|
require _dir(SRC_DIR, '/functions.php');
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// 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);
|
|
|
|
|
2015-10-09 22:29:59 -04:00
|
|
|
// Register as the error handler
|
|
|
|
$whoops->register();
|
2015-10-09 14:34:55 -04:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Dependency Injection setup
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
require _dir(CONF_DIR, 'base_config.php'); // $base_config
|
|
|
|
require _dir(CONF_DIR, 'config.php'); // $config
|
|
|
|
$config_array = array_merge($base_config, $config);
|
|
|
|
$di = require _dir(APP_DIR, 'bootstrap.php');
|
|
|
|
$container = $di($config_array);
|
|
|
|
$container->set('error-handler', $defaultHandler);
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Dispatch to the current route
|
|
|
|
// -----------------------------------------------------------------------------
|
2015-11-13 16:31:01 -05:00
|
|
|
$container->get('dispatcher')->__invoke();
|
2015-05-22 12:36:26 -04:00
|
|
|
|
|
|
|
// End of index.php
|