source:
trunk/prototype/REST.php
@
5399
Revision 5399, 1.1 KB checked in by cristiano, 13 years ago (diff) |
---|
Rev | Line | |
---|---|---|
[5136] | 1 | <?php |
[5341] | 2 | //TODO:Arrumar isso |
3 | // define( 'ROOTPATH' , '/home/natan/expresso2.4' ); | |
[5136] | 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); | |
[5341] | 12 | else |
13 | $id = false; | |
[5136] | 14 | |
15 | $concept = array_pop($REST); | |
16 | ||
[5341] | 17 | $parents = array(); |
18 | ||
[5136] | 19 | while( $REST ) |
20 | $parents[ array_shift($REST) ] = array_shift($REST); | |
21 | ||
[5341] | 22 | $accept = $_SERVER["HTTP_ACCEPT"]; |
[5136] | 23 | |
[5341] | 24 | $args = array(); |
25 | ||
[5136] | 26 | if( $_SERVER["REQUEST_METHOD"] === "GET" ) |
27 | { | |
[5341] | 28 | if( isset( $_GET["attr"] ) ) |
29 | { | |
30 | $args = $_GET["attr"]; | |
[5136] | 31 | unset( $_GET["attr"] ); |
[5341] | 32 | } |
[5136] | 33 | |
[5341] | 34 | $method = $id ? "read" : "find"; |
[5136] | 35 | } |
[5341] | 36 | else |
37 | { | |
38 | parse_str( file_get_contents('php://input'), $args ); | |
[5136] | 39 | |
[5341] | 40 | switch( $_SERVER["REQUEST_METHOD"] ) |
[5136] | 41 | { |
[5341] | 42 | case "DELETE": |
43 | $method = $id ? "delete" : "deleteAll"; | |
[5136] | 44 | break; |
45 | case "PUT": | |
[5341] | 46 | $method = $id ? "update" : "replace"; |
[5136] | 47 | break; |
48 | case "POST": | |
[5341] | 49 | $method = "create"; |
[5136] | 50 | break; |
51 | } | |
52 | } | |
53 | ||
[5399] | 54 | require_once 'api/controller.php'; |
[5341] | 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 | ||
[5136] | 64 | ?> |
Note: See TracBrowser
for help on using the repository browser.