Revision 5399,
1.1 KB
checked in by cristiano, 13 years ago
(diff) |
Ticket #2434 - Alteração da estrutura de diretórios da nova API
|
Line | |
---|
1 | <?php |
---|
2 | //TODO:Arrumar isso |
---|
3 | // define( 'ROOTPATH' , '/home/natan/expresso2.4' ); |
---|
4 | |
---|
5 | $REST = $_GET['q']; unset( $_GET['q'] ); |
---|
6 | |
---|
7 | if( !($REST = (isset($REST)) ? explode('/', $REST) : false) ) |
---|
8 | return; |
---|
9 | |
---|
10 | if( !(count($REST) % 2) ) |
---|
11 | $id = array_pop($REST); |
---|
12 | else |
---|
13 | $id = false; |
---|
14 | |
---|
15 | $concept = array_pop($REST); |
---|
16 | |
---|
17 | $parents = array(); |
---|
18 | |
---|
19 | while( $REST ) |
---|
20 | $parents[ array_shift($REST) ] = array_shift($REST); |
---|
21 | |
---|
22 | $accept = $_SERVER["HTTP_ACCEPT"]; |
---|
23 | |
---|
24 | $args = array(); |
---|
25 | |
---|
26 | if( $_SERVER["REQUEST_METHOD"] === "GET" ) |
---|
27 | { |
---|
28 | if( isset( $_GET["attr"] ) ) |
---|
29 | { |
---|
30 | $args = $_GET["attr"]; |
---|
31 | unset( $_GET["attr"] ); |
---|
32 | } |
---|
33 | |
---|
34 | $method = $id ? "read" : "find"; |
---|
35 | } |
---|
36 | else |
---|
37 | { |
---|
38 | parse_str( file_get_contents('php://input'), $args ); |
---|
39 | |
---|
40 | switch( $_SERVER["REQUEST_METHOD"] ) |
---|
41 | { |
---|
42 | case "DELETE": |
---|
43 | $method = $id ? "delete" : "deleteAll"; |
---|
44 | break; |
---|
45 | case "PUT": |
---|
46 | $method = $id ? "update" : "replace"; |
---|
47 | break; |
---|
48 | case "POST": |
---|
49 | $method = "create"; |
---|
50 | break; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | require_once 'api/controller.php'; |
---|
55 | |
---|
56 | $URI = Controller::URI( $concept, $id ); |
---|
57 | |
---|
58 | $args = array_merge( $args, array('context'=>$parents)); |
---|
59 | |
---|
60 | echo json_encode( Controller::call( $method, $URI, $args, $_GET ) ); |
---|
61 | |
---|
62 | Controller::closeAll(); |
---|
63 | |
---|
64 | ?> |
---|
Note: See
TracBrowser
for help on using the repository browser.