-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
41 lines (26 loc) · 1.17 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
<?php
require_once 'vendor/autoload.php';
use mvc\Controllers;
use mvc\tim\Barcelona;
use mvc\tim\RealMadrid;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use mvc\Controller\ArticleController;
use mvc\Controller\IndexController;
use Phroute\RouteCollector;
use Phroute\Dispatcher;
$request = Request::createFromGlobals();
$loader = new Twig_Loader_Filesystem(__DIR__.'/app/views');
$twig = new Twig_Environment($loader);
$articleController = new ArticleController($twig);
$indexController = new IndexController($twig);
$router = new RouteCollector();
$router->get('/', [$indexController,'indexAction']);
$router->get('/articles/{id}', [$articleController,'getArticleAction']);
$router->put('/articles/{id}', [$articleController,'getArticleAction']);
$router->post('/articles/{id}', [$articleController,'getArticleAction']);
$router->delete('/articles/{id}', [$articleController,'getArticleAction']);
$router->get('/articles', [$articleController,'getArticlesAction']);
$dispatcher = new Dispatcher($router);
$response = $dispatcher->dispatch($request->getMethod(), parse_url($request->getPathInfo(), PHP_URL_PATH));
$response->send();