Changeset 7322


Ignore:
Timestamp:
09/27/12 15:47:32 (7 years ago)
Author:
alexandrecorreia
Message:

Ticket #3093 - Integração da API REST, arquivo dispatch.php.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.4.3-expresso-rest/prototype/rest/dispatch.php

    r6528 r7322  
    11<?php 
    22// load Tonic library 
    3 require_once __DIR__ . '/../library/tonic/lib/tonic.php'; 
    4 require_once __DIR__ . '/../api/controller.php'; 
    5 require_once ROOTPATH . '/rest/oauth/OAuth2StorageUserCredential.php'; 
     3require_once(__DIR__ . '/../library/tonic/lib/tonic.php'); 
     4require_once(__DIR__.'/../library/utils/Errors.php'); 
     5require_once(__DIR__ . '/../api/controller.php'); 
     6require_once(ROOTPATH . '/rest/oauth/OAuth2StorageUserCredential.php'); 
     7 
     8// load adapters 
     9require_once(__DIR__."/../adapters/ExpressoAdapter.php"); 
     10require_once(__DIR__."/../adapters/MailAdapter.php"); 
     11require_once(__DIR__."/../adapters/CatalogAdapter.php"); 
     12require_once(__DIR__."/../adapters/CalendarAdapter.php"); 
     13//require_once(__DIR__."/../adapters/testeAdapter.php"); 
    614 
    715//Retrieveing the mapping of the URIs and his respectives classNames and classPath 
     
    1826$classpath = array(); 
    1927 
    20 foreach( $config as $uri => $classFile ){ 
     28foreach( $config as $uri => $classFile ) 
     29{ 
    2130    foreach( $classFile as $className => $filePath ) 
    2231    { 
    23         $autoload[ $uri ] = $className; 
    24         $classpath[ $className ] = $filePath; 
     32                $autoload[ $uri ] = $className; 
     33                $classpath[ $className ] = $filePath; 
    2534    } 
    2635} 
     
    4958 
    5059} catch (ResponseException $e) { 
    51     switch ($e->getCode()) { 
    52     case Response::UNAUTHORIZED: 
    53         $response = $e->response($request); 
    54         $response->addHeader('WWW-Authenticate', 'Basic realm="Tonic"'); 
    55         break; 
    56     default: 
    57         $response = $e->response($request); 
     60    switch ($e->getCode()) 
     61    { 
     62            case Response::UNAUTHORIZED: 
     63                $response = $e->response($request); 
     64                $response->addHeader('WWW-Authenticate', 'Basic realm="Tonic"'); 
     65                break; 
     66             
     67                default: 
     68                        $response = new Response($request); 
     69                        $response->code = Response::OK; 
     70                        $response->addHeader('content-type', 'application/json'); 
     71                        if($request->id) 
     72                        { 
     73                                $body['id']     = $request->id; 
     74                        } 
     75                        $body['error'] = array("code" => "".$e->getCode(), "message" => $e->getMessage()); 
     76                         
     77                        $response->body = json_encode($body); 
     78                         
     79                        //$response = $e->response($request); 
    5880    } 
    5981} 
     82 
    6083$response->output(); 
    6184 
     85?> 
Note: See TracChangeset for help on using the changeset viewer.