source: sandbox/webservice/api/rest/dispatch.php @ 7577

Revision 7577, 2.7 KB checked in by pereira.jair, 8 years ago (diff)

Ticket #2507 - Correção da varíavel global DIR que estava incorreta.

  • Property svn:executable set to *
Line 
1<?php
2
3$dir = $_SERVER['DOCUMENT_ROOT'];
4
5if (substr($dir,strlen($dir)-1,strlen($dir)) != "/") {
6        $dir = $dir . "/";
7}
8
9define(apiDirectory,$dir . "api/rest");
10
11// load libraries
12require_once(apiDirectory.'/../library/tonic/lib/tonic.php');
13require_once(apiDirectory.'/../library/utils/Errors.php');
14
15// load adapters
16require_once(apiDirectory."/../adapters/ExpressoAdapter.php");
17require_once(apiDirectory."/../adapters/MailAdapter.php");
18require_once(apiDirectory."/../adapters/CatalogAdapter.php");
19require_once(apiDirectory."/../adapters/CalendarAdapter.php");
20
21// Load all resources
22require_once(apiDirectory."/availableServers/AvailableServersResource.php");
23require_once(apiDirectory."/core/ExpressoVersionResource.php");
24require_once(apiDirectory."/core/LoginResource.php");
25require_once(apiDirectory."/core/LogoutResource.php");
26require_once(apiDirectory."/mail/FoldersResource.php");
27require_once(apiDirectory."/mail/MessagesResource.php");
28require_once(apiDirectory."/mail/AddFolderResource.php");
29require_once(apiDirectory."/mail/DelFolderResource.php");
30require_once(apiDirectory."/mail/DelMessageResource.php");
31require_once(apiDirectory."/mail/RenameFolderResource.php");
32require_once(apiDirectory."/mail/CleanTrashResource.php");
33require_once(apiDirectory."/mail/AttachmentResource.php");
34require_once(apiDirectory."/mail/SendResource.php");
35require_once(apiDirectory."/mail/SendSupportFeedbackResource.php");
36require_once(apiDirectory."/catalog/ContactsResource.php");
37require_once(apiDirectory."/catalog/ContactPictureResource.php");
38require_once(apiDirectory."/calendar/EventsResource.php");
39
40//Retrieveing the mapping of the URIs and his respectives classNames and classPath
41$config = parse_ini_file( apiDirectory . '/../config/Tonic.srv', true );
42$autoload = array();
43$classpath = array();
44
45foreach( $config as $uri => $classFile )
46{
47        foreach( $classFile as $className => $filePath )
48        {
49                $autoload[ $uri ] = $className;
50                $classpath[ $className ] = $filePath;
51        }
52
53        $request = new Request(array(
54                        'baseUri' => dirname($_SERVER['SCRIPT_NAME']),
55                        'autoload' => $autoload
56        ));
57}
58       
59try {
60
61        $resource = $request->loadResource();
62        $response = $resource->exec($request);
63       
64} catch (ResponseException $e) {
65       
66        switch ($e->getCode()) {
67               
68                case Response::UNAUTHORIZED:
69                        $response = $e->response($request);
70                        $response->addHeader('WWW-Authenticate', 'Basic realm="Tonic"');
71                        break;
72                default:
73                       
74                        $response = new Response($request);
75                        $response->code = Response::OK;
76                        $response->addHeader('content-type', 'application/json');
77                        if($request->id)
78                                $body['id']     = $request->id;
79                       
80                        $body['error'] = array("code" => "".$e->getCode(), "message" => $e->getMessage());
81                        $response->body = json_encode($body);
82        }
83}
84
85$response->output();
86
87?>
Note: See TracBrowser for help on using the repository browser.