backend/index.php
2024-07-25 16:15:18 +03:00

47 lines
2.2 KiB
PHP

<?php
error_reporting(-1);
ini_set("display_errors", true);
require_once "vendor/autoload.php";
require 'bootstrap.php';
use app\controllers\MainController;
use app\controllers\UserController;
use app\controllers\QuestionController;
use app\controllers\AnswerController;
use app\controllers\PostController;
use app\helpers\Debug;
use Phroute\Phroute\RouteCollector;
$router = new RouteCollector();
$router->get('/', [MainController::class, 'actionIndex']);
$router->get('/example', [MainController::class, 'actionExample']);
$router->group(["prefix" => "admin"], function (RouteCollector $router){
$router->group(["prefix" => "user"], function (RouteCollector $router){
$router->get('/', [\app\controllers\UserController::class, 'actionIndex']);
$router->get('/create', [\app\controllers\UserController::class, 'actionCreate']);
$router->post("/", [\app\controllers\UserController::class, 'actionAdd']);
$router->get('/{id}', [\app\controllers\UserController::class, 'actionView']);
$router->any('/update/{id}', [\app\controllers\UserController::class, 'actionUpdate']);
$router->any("/edit/{id}", [\app\controllers\UserController::class, 'actionEdit']);
$router->get('/delete/{id}', [\app\controllers\UserController::class, 'actionDelete']);
});
$router->group(["prefix" => "post"], function (RouteCollector $router){
$router->get('/', [\app\controllers\PostController::class, 'actionIndex']);
$router->get('/create', [\app\controllers\PostController::class, 'actionCreate']);
$router->post("/", [\app\controllers\PostController::class, 'actionAdd']);
$router->get('/{id}', [\app\controllers\PostController::class, 'actionView']);
$router->any('/update/{id}', [\app\controllers\PostController::class, 'actionUpdate']);
$router->any("/edit/{id}", [\app\controllers\PostController::class, 'actionEdit']);
$router->get('/delete/{id}', [\app\controllers\PostController::class, 'actionDelete']);
});
});
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
// Print out the value returned from the dispatched function
echo $response;