addressbook/public/index.php

79 lines
2.7 KiB
PHP

<?php
/*
* Copyright (c) 2022. Micha Espey <tracer@24unix.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
ini_set(option: 'display_errors', value: 1);
ini_set(option: 'display_startup_errors', value: 1);
// no one sane should ignore deprecations
error_reporting(error_level: E_ALL);
session_start();
require dirname(path: __DIR__) . '/src/bootstrap.php';
use App\Controller\AddressBookAdminController;
use App\Controller\AddressBookController;
use App\Controller\SecurityController;
use App\Service\Container;
use App\Service\Router;
$container = new Container();
$router = $container->get(className: Router::class);
$security = $container->get(className: SecurityController::class);
$addressBook = $container->get(className: AddressBookController::class);
$addressBookAdmin = $container->get(className: AddressBookAdminController::class);
// TODO maybe refactor route adding to the controllers?
// I currently think that makes sense.
$router->addRoute(name: 'app_login', route: '/login', callback: function () use ($security) {
$security->login();
});
$router->addRoute(name: 'app_logout', route: '/logout', callback: function () use ($security) {
$security->logout();
});
$router->addRoute(name: 'app_main', route: '/', callback: function () use ($addressBook) {
$addressBook->main();
});
$router->addRoute(name: 'app_admin', route: '/admin', callback: function () use ($addressBookAdmin) {
$addressBookAdmin->admin();
});
$router->addRoute(name: 'app_admin_users', route: '/admin/users', callback: function () use ($addressBookAdmin) {
$addressBookAdmin->adminUser();
});
$router->addRoute(name: 'app_admin_users_edit', route: '/admin/users/{nick}', callback: function (array $parameters) use ($addressBookAdmin) {
$addressBookAdmin->adminUserEdit(parameters: $parameters);
});
$router->addRoute(name: 'app_admin_users_add', route: '/admin/users/add', callback: function () use ($addressBookAdmin) {
$addressBookAdmin->adminUserAdd();
});
$router->addRoute(name: 'app_admin_users_delete', route: '/admin/users/delete/{nick}', callback: function (array $parameters) use ($addressBookAdmin) {
$addressBookAdmin->adminUserDelete(parameters: $parameters);
});
$router->addRoute(name: 'address_add', route: '/address/add', callback: function () use ($addressBook) {
$addressBook->addAddress();
});
$router->addRoute(name: 'address_add', route: '/address/update', callback: function () use ($addressBook) {
$addressBook->updateAddress();
});
$router->addRoute(name: 'address_add', route: '/address/delete', callback: function () use ($addressBook) {
$addressBook->deleteAddress();
});
$router->handleRouting();