2015-05-22 12:36:26 -04:00
|
|
|
<?php
|
2015-06-16 11:11:35 -04:00
|
|
|
/**
|
|
|
|
* Here begins everything!
|
|
|
|
*/
|
2015-05-22 12:36:26 -04:00
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
/**
|
|
|
|
* Joins paths together. Variadic to take an
|
|
|
|
* arbitrary number of arguments
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function _dir() { return implode(DIRECTORY_SEPARATOR, func_get_args()); }
|
|
|
|
|
2015-06-16 11:11:35 -04:00
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
define('ROOT_DIR', __DIR__);
|
|
|
|
define('APP_DIR', _dir(ROOT_DIR, 'app'));
|
|
|
|
define('CONF_DIR', _dir(APP_DIR, 'config'));
|
|
|
|
define('BASE_DIR', _dir(APP_DIR, 'base'));
|
|
|
|
|
2015-06-16 11:11:35 -04:00
|
|
|
/**
|
|
|
|
* Well, whose list is it?
|
|
|
|
*/
|
2015-06-11 16:44:52 -04:00
|
|
|
define('WHOSE', "Tim's");
|
|
|
|
|
|
|
|
// Load config and global functions
|
|
|
|
$config = require _dir(APP_DIR, '/config/config.php');
|
|
|
|
require _dir(BASE_DIR, '/functions.php');
|
|
|
|
|
|
|
|
// Setup autoloaders
|
|
|
|
require _dir(ROOT_DIR, '/vendor/autoload.php');
|
|
|
|
spl_autoload_register(function ($class) {
|
|
|
|
$dirs = ["base", "controllers", "models"];
|
|
|
|
|
|
|
|
foreach($dirs as $dir)
|
|
|
|
{
|
|
|
|
$file = _dir(APP_DIR, $dir, "{$class}.php");
|
|
|
|
if (file_exists($file))
|
|
|
|
{
|
|
|
|
require_once $file;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-05-22 12:36:26 -04:00
|
|
|
|
2015-05-27 09:03:42 -04:00
|
|
|
session_start();
|
|
|
|
|
2015-05-22 12:36:26 -04:00
|
|
|
use \Whoops\Handler\PrettyPageHandler;
|
|
|
|
use \Whoops\Handler\JsonResponseHandler;
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Router
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
$router = new Router();
|
2015-06-11 16:44:52 -04:00
|
|
|
$defaultHandler->addDataTable('route', (array)$router->get_route());
|
2015-05-22 12:36:26 -04:00
|
|
|
$router->dispatch();
|
|
|
|
|
|
|
|
// End of index.php
|