-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
64 lines (45 loc) · 1.43 KB
/
index.php
File metadata and controls
64 lines (45 loc) · 1.43 KB
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
<?php
require './vendor/autoload.php';
error_reporting(E_ALL);
ini_set("display_errors", 1);
use Phroute\Phroute\RouteCollector;
use Phroute\Phroute\RouteParser;
use Phroute\Phroute\Dispatcher;
echo 'aqui';
function processInput($uri){
$uri = implode('/',
array_slice(
explode('/', $_SERVER['REQUEST_URI']), 3));
print_r($uri);
return $uri;
}
function processOutput($response){
echo json_encode($response);
}
$collector = new RouteCollector(new RouteParser);
$collector->get('/', function(){
//$u = new User;
//$u->getUsers();
return 'Home Page.';
});
$collector->post('products', function(){
return 'Create Product';
});
$collector->get('/tio', function(){
return 'Amend Item ';
});
$dispatcher = new Dispatcher($collector->getData());
//echo $dispatcher->dispatch('GET', '/'), "\n"; // Home Page
//echo $dispatcher->dispatch('GET', '/tio'), "\n"; // Home Page
//echo $dispatcher->dispatch('POST', '/products'), "\n"; // Create Product
print_r($_SERVER);
try {
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], processInput($_SERVER['REQUEST_URI']));
} catch (Phroute\Exception\HttpRouteNotFoundException $e) {
var_dump($e);
die();
} catch (Phroute\Exception\HttpMethodNotAllowedException $e) {
var_dump($e);
die();
}
processOutput($response);