Ignore:
Timestamp:
01/10/12 11:25:51 (12 years ago)
Author:
wmerlotto
Message:

Ticket #2434 - Commit inicial do novo módulo de agenda do Expresso - expressoCalendar

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/REST.php

    r5136 r5341  
    11<?php 
     2//TODO:Arrumar isso  
     3// define( 'ROOTPATH' , '/home/natan/expresso2.4' ); 
    24 
    35$REST = $_GET['q']; unset( $_GET['q'] ); 
     
    810if( !(count($REST) % 2) ) 
    911    $id = array_pop($REST); 
     12else 
     13    $id = false; 
    1014 
    1115$concept = array_pop($REST); 
     16 
     17$parents = array(); 
    1218 
    1319while( $REST ) 
    1420    $parents[ array_shift($REST) ] = array_shift($REST); 
    1521 
    16 require_once 'app/controller.php'; 
    17 $controller = Controller::newInstance( $concept, $id, $parents ); 
     22$accept = $_SERVER["HTTP_ACCEPT"]; 
     23 
     24$args = array(); 
    1825 
    1926if( $_SERVER["REQUEST_METHOD"] === "GET" ) 
    2027{ 
    21     $attr = $_GET["attr"]; 
     28    if( isset( $_GET["attr"] ) ) 
     29    { 
     30        $args = $_GET["attr"]; 
    2231    unset( $_GET["attr"] ); 
     32    } 
    2333 
    24     echo $controller->find( $attr, $_GET ); 
    25     return; 
     34    $method = $id ? "read" : "find"; 
    2635} 
     36else 
     37{ 
     38    parse_str( file_get_contents('php://input'), $args ); 
    2739 
    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"] ) 
    3541    { 
    36         echo $controller->delete( $args, $_GET ); 
     42        case "DELETE": 
     43            $method = $id ? "delete" : "deleteAll"; 
    3744        break; 
    38     } 
    3945    case "PUT": 
    40     { 
    41         echo $controller->update( $args, $_GET ); 
     46            $method = $id ? "update" : "replace"; 
    4247        break; 
    43     } 
    4448    case "POST": 
    45     { 
    46         echo $controller->create( $args, $_GET ); 
     49            $method = "create"; 
    4750        break; 
    4851    } 
    4952} 
    5053 
     54require_once 'app/controller.php'; 
     55 
     56$URI = Controller::URI( $concept, $id ); 
     57 
     58$args = array_merge( $args, array('context'=>$parents)); 
     59 
     60echo json_encode( Controller::call( $method, $URI, $args, $_GET ) ); 
     61 
     62Controller::closeAll(); 
     63 
    5164?> 
Note: See TracChangeset for help on using the changeset viewer.