source: branches/2.4/prototype/rest/availableServers/AvailableServersResource.php @ 7442

Revision 7442, 1.2 KB checked in by eduardow, 12 years ago (diff)

Ticket #3093 - Integrando API Rest (CELEPAR) - commit para o branches.

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * @uri /AvailableServers
4 */
5class AvailableServersResource extends Resource {
6
7        function post($request){
8                return $this->get($request);
9        }
10       
11        function get($request){
12                $error = null;         
13                parse_str($request->data, &$data);
14                               
15                if( file_exists(__DIR__ . '/../../config/REST.ini') )
16                {
17                        $restServers = parse_ini_file( __DIR__ . '/../../config/REST.ini', true );
18                       
19                        foreach( $restServers as $key => $value)
20                        {
21                                if(substr( $key, 0, 11 ) == "ServersRest")
22                                {
23                                        $servers[] = $value;
24                                }
25                        }
26                }
27                else{
28                        $error = array("code" => "001", "message" => "The servers list was not found.");
29                }
30
31                function cmp($a, $b)
32                {
33                        return strcmp(strtolower($a["serverName"]), strtolower($b["serverName"]));
34                }
35       
36                if(count($servers) > 0){
37                        usort($servers, "cmp");
38                }
39
40                $response = new Response($request);
41                $response->code = Response::OK;
42                $response->addHeader('content-type', 'application/json');
43                               
44                $body = array();
45               
46                if($data['id']){
47                        $body['id'] = $data['id'];
48                }
49                if($servers){
50                        $body['result'] = array( "servers" => $servers);
51                }
52                elseif($error){
53                        $body['error'] = $error;
54                }
55                else{
56                        $body['error'] = "OBJETO SEM RESULT E SEM ERRO REPORTADO.";
57                }
58                                               
59                $response->body = json_encode($body);
60                       
61                return $response;
62        }               
63
64}
Note: See TracBrowser for help on using the repository browser.