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

Revision 7811, 3.2 KB checked in by alexandrecorreia, 8 years ago (diff)

Ticket #2507 - Criado os resources para o módulo Expresso-Admin

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