-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
executable file
·64 lines (45 loc) · 1.69 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
use Phroute\Phroute\Dispatcher;
use Phroute\Phroute\RouteParser;
use Phroute\Phroute\RouteCollector;
use App\Controllers\Frontend\CartController;
use App\Controllers\Frontend\HomeController;
use App\Controllers\Backend\ProductController;
use App\Controllers\Backend\CategoryController;
use App\Controllers\Backend\CheckoutController;
use App\Controllers\Backend\DashboardController;
use Illuminate\Database\Capsule\Manager as Capsule;
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
require_once 'config.php';
define('BASE_URL', __DIR__);
session_start();
// PHROUTE
$router = new RouteCollector(new RouteParser);
$router->controller('/', HomeController::class);
$router->controller('/cart', CartController::class);
$router->filter('auth', function() {
if(!isset($_SESSION['login'])) {
header('Location: /login');
return false;
}
});
$router->group(['before' => 'auth'], function(RouteCollector $router){
$router->controller('/checkout', CheckoutController::class);
});
$router->group(['prefix' => 'dashboard', 'before' => 'auth'], function(RouteCollector $router){
$router->controller('/', DashboardController::class);
$router->controller('/categories', CategoryController::class);
$router->controller('/products', ProductController::class);
});
$dispatcher = new Dispatcher($router->getData());
try {
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
} catch (HttpRouteNotFoundException $e) {
echo $e->getMessage();
die();
} catch (HttpMethodNotAllowedException $e) {
echo $e->getMessage();
die();
}
echo $response;