source: trunk/prototype/REST.php @ 5136

Revision 5136, 928 bytes checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo prototype.

Line 
1<?php
2
3$REST = $_GET['q']; unset( $_GET['q'] );
4
5if( !($REST = (isset($REST)) ? explode('/', $REST) : false) )
6    return;
7
8if( !(count($REST) % 2) )
9    $id = array_pop($REST);
10
11$concept = array_pop($REST);
12
13while( $REST )
14    $parents[ array_shift($REST) ] = array_shift($REST);
15
16require_once 'app/controller.php';
17$controller = Controller::newInstance( $concept, $id, $parents );
18
19if( $_SERVER["REQUEST_METHOD"] === "GET" )
20{
21    $attr = $_GET["attr"];
22    unset( $_GET["attr"] );
23
24    echo $controller->find( $attr, $_GET );
25    return;
26}
27
28$accept = $_SERVER["HTTP_ACCEPT"];
29
30parse_str( file_get_contents('php://input'), $args );
31
32switch( $_SERVER["REQUEST_METHOD"] )
33{
34    case "DELETE":
35    {
36        echo $controller->delete( $args, $_GET );
37        break;
38    }
39    case "PUT":
40    {
41        echo $controller->update( $args, $_GET );
42        break;
43    }
44    case "POST":
45    {
46        echo $controller->create( $args, $_GET );
47        break;
48    }
49}
50
51?>
Note: See TracBrowser for help on using the repository browser.