Example #1
0
define('VIEW_DIR', realpath(__DIR__ . '/../views'));
define('CONTROLLER_DIR', realpath(__DIR__ . '/../App/Controller'));
define('MODEL_DIR', realpath(__DIR__ . '/../App/Model'));
/*******************
*  Initialization  *
*******************/
// Handles the PHPSESSID cookie and populates the $_SESSION array with the users data
session_start();
// This is the only require in the project
require __DIR__ . '/../App/Kernel/Autoloader.php';
// Initialize and configure the autoloader
$loader = new Autoloader();
$loader->addNamespace('App', __DIR__ . '/../App');
$loader->register();
// Initialize and configure the dependency injection container
$container = new Container();
// Setting up database DI
require CONTROLLER_DIR . '/dbhandler.php';
$container->bindArguments('App\\Model\\User', ['pdo' => $pdo]);
$container->bindArguments('App\\Model\\Gallery', ['pdo' => $pdo]);
/************
*  Routing  *
************/
$UC = 'App\\Controller\\UserController';
$GC = 'App\\Controller\\GalleryController';
$router = new Router();
$router->addRoute('GET', '/', [$UC, 'showLogin']);
$router->addRoute('GET', '/login', [$UC, 'showLogin']);
$router->addRoute('GET', '/userlist', [$UC, 'getAllUsers']);
$router->addRoute('GET', '/adduser', [$UC, 'showAddUser']);
$router->addRoute('GET', '/gallery', [$GC, 'showGallery']);
Example #2
0
ini_set('display_errors', 1);
// Define some global constants
define('VIEW_DIR', realpath(__DIR__ . '/../views'));
/*******************
*  Initialization  *
*******************/
// Handles the PHPSESSID cookie and populates the $_SESSION array with the users data
session_start();
// This is the only require in the project
require __DIR__ . '/../App/Kernel/Autoloader.php';
// Initialize and configure the autoloader
$loader = new Autoloader();
$loader->addNamespace('App', __DIR__ . '/../App');
$loader->register();
// Initialize and configure the dependency injection container
$container = new Container();
$container->bindArguments('App\\Controller\\QuestionController', ['scoreLimit' => 3]);
/************
*  Routing  *
************/
$router = new Router();
$router->addRoute('GET', '/', ['App\\Controller\\QuestionController', 'showQuestion']);
$router->addRoute('GET', '/score.html', ['App\\Controller\\ScoreController', 'showScore']);
$router->addRoute('POST', '/', ['App\\Controller\\QuestionController', 'answerQuestion']);
// Convert i.e. "/foo%40bar?id=1" to "/foo@bar"
$uri = rawurldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$route = $router->match($_SERVER['REQUEST_METHOD'], $uri);
if ($route === null) {
    $route = ['handle' => ['App\\Controller\\ErrorController', 'error404'], 'arguments' => []];
}
$controller = $container->create($route['handle'][0]);