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

Revision 6338, 2.2 KB checked in by asaikawa, 8 years ago (diff)

Ticket #2507 - Implementacao do recurso SendResource? para envio de email

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