Changeset 5341 for trunk/prototype/REST.php
- Timestamp:
- 01/10/12 11:25:51 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/REST.php
r5136 r5341 1 1 <?php 2 //TODO:Arrumar isso 3 // define( 'ROOTPATH' , '/home/natan/expresso2.4' ); 2 4 3 5 $REST = $_GET['q']; unset( $_GET['q'] ); … … 8 10 if( !(count($REST) % 2) ) 9 11 $id = array_pop($REST); 12 else 13 $id = false; 10 14 11 15 $concept = array_pop($REST); 16 17 $parents = array(); 12 18 13 19 while( $REST ) 14 20 $parents[ array_shift($REST) ] = array_shift($REST); 15 21 16 require_once 'app/controller.php'; 17 $controller = Controller::newInstance( $concept, $id, $parents ); 22 $accept = $_SERVER["HTTP_ACCEPT"]; 23 24 $args = array(); 18 25 19 26 if( $_SERVER["REQUEST_METHOD"] === "GET" ) 20 27 { 21 $attr = $_GET["attr"]; 28 if( isset( $_GET["attr"] ) ) 29 { 30 $args = $_GET["attr"]; 22 31 unset( $_GET["attr"] ); 32 } 23 33 24 echo $controller->find( $attr, $_GET ); 25 return; 34 $method = $id ? "read" : "find"; 26 35 } 36 else 37 { 38 parse_str( file_get_contents('php://input'), $args ); 27 39 28 $accept = $_SERVER["HTTP_ACCEPT"]; 29 30 parse_str( file_get_contents('php://input'), $args ); 31 32 switch( $_SERVER["REQUEST_METHOD"] ) 33 { 34 case "DELETE": 40 switch( $_SERVER["REQUEST_METHOD"] ) 35 41 { 36 echo $controller->delete( $args, $_GET ); 42 case "DELETE": 43 $method = $id ? "delete" : "deleteAll"; 37 44 break; 38 }39 45 case "PUT": 40 { 41 echo $controller->update( $args, $_GET ); 46 $method = $id ? "update" : "replace"; 42 47 break; 43 }44 48 case "POST": 45 { 46 echo $controller->create( $args, $_GET ); 49 $method = "create"; 47 50 break; 48 51 } 49 52 } 50 53 54 require_once 'app/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 51 64 ?>
Note: See TracChangeset
for help on using the changeset viewer.