source: sandbox/2.4.1-3/prototype/rest/dispatch.php @ 6351

Revision 6351, 1.7 KB checked in by gustavo, 12 years ago (diff)

Ticket #2768 - Melhorias na inserção de destinatários na criacao de mensagem

  • Property svn:executable set to *
Line 
1<?php
2// load Tonic library
3require_once __DIR__ . '/../library/tonic/lib/tonic.php';
4require_once __DIR__ . '/../api/controller.php';
5require_once ROOTPATH . '/rest/oauth/OAuth2StorageUserCredential.php';
6
7
8//Retrieveing the mapping of the URIs and his respectives classNames and classPath
9$config = parse_ini_file( __DIR__ . '/../config/Tonic.srv', true );
10
11//looping through the mapping to create 2 separated maps:
12// First indexed by the uri that carry the classNames,
13// that its used by Tonic to autoload them when routed by him accordingly;
14// Second indexed by the className that carry the classPaths,
15// used by the autoload register to find the correct path of the class that's going to
16// be loaded;
17
18$autoload = array();
19$classpath = array();
20
21foreach( $config as $uri => $classFile ){
22    foreach( $classFile as $className => $filePath )
23    {
24        $autoload[ $uri ] = $className;
25        $classpath[ $className ] = $filePath;
26    }
27}
28
29//The autoload function that's called by the PHP when Tonic routes a class not declared previously
30function __autoload($class) {
31
32        global $classpath;
33
34        require_once(__DIR__ . $classpath[ $class ] );
35}
36
37// handle request, passing the current env baseUri and autoload mapping;
38$request = new Request(array(
39        'baseUri'=> '/tezza/expressoDFD/rest',
40        'autoload' => $autoload,
41));
42
43try {
44    $resource = $request->loadResource();
45    $response = $resource->exec($request);
46
47} catch (ResponseException $e) {
48    switch ($e->getCode()) {
49    case Response::UNAUTHORIZED:
50        $response = $e->response($request);
51        $response->addHeader('WWW-Authenticate', 'Basic realm="Tonic"');
52        break;
53    default:
54        $response = $e->response($request);
55    }
56}
57$response->output();
58
Note: See TracBrowser for help on using the repository browser.