Beispiel #1
0
// 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']);
$router->addRoute('GET', '/upload', [$GC, 'showUpload']);
$router->AddRoute('GET', '/logout', [$UC, 'logout']);
$router->AddRoute('GET', '/delete', [$UC, 'showDelete']);
$router->AddRoute('GET', '/edit', [$UC, 'showEdit']);
$router->AddRoute('POST', '/login', [$UC, 'login']);
$router->AddRoute('POST', '/createUser', [$UC, 'createUser']);
$router->AddRoute('POST', '/deleteUser', [$UC, 'deleteUser']);
$router->AddRoute('POST', '/editUser', [$UC, 'editUser']);
$router->AddRoute('POST', '/uploadImage', [$GC, 'uploadImage']);
$router->AddRoute('POST', '/deleteImage', [$GC, 'deleteImage']);
Beispiel #2
0
// 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]);
$container->call([$controller, $route['handle'][1]], $route['arguments']);