[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Horde_RPC_rest class provides a REST implementation of the Horde RPC 4 * system. 5 * 6 * $Horde: framework/RPC/RPC/rest.php,v 1.6.2.2 2006/05/04 12:24:14 jan Exp $ 7 * 8 * Copyright Rafael Varela Pet <rafael.varela.pet@usc.es> 9 * 10 * See the enclosed file COPYING for license information (LGPL). If you did 11 * not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 12 * 13 * @author Rafael Varela <rafael.varela.pet@usc.es> 14 * @since Horde 3.1 15 * @package Horde_RPC 16 */ 17 class Horde_RPC_rest extends Horde_RPC { 18 19 /** 20 * @var string 21 */ 22 var $_contentType = 'text/html'; 23 24 /** 25 * Check authentication. Different backends may handle 26 * authentication in different ways. The base class implementation 27 * checks for HTTP Authentication against the Horde auth setup. 28 * 29 * @return boolean Returns true if authentication is successful. 30 * Should send appropriate "not authorized" headers 31 * or other response codes/body if auth fails, 32 * and take care of exiting. 33 */ 34 function authorize() 35 { 36 if (!$this->_authorize) { 37 return true; 38 } 39 40 if (Auth::getAuth()) { 41 return true; 42 } 43 44 return parent::authorize(); 45 } 46 47 /** 48 * Get. all the GET input data. The 'call' param is extracted from the 49 * array and treated separately. 50 * 51 * @return array (method name, array of parameters) 52 * 53 * TODO: deserializing of complex data types. 54 */ 55 function getInput() 56 { 57 $this->_contentType = Util::getGet('restContentType', 'text/html'); 58 59 $getData = Util::dispelMagicQuotes($_GET); 60 unset($getData['restCall']); 61 unset($getData['restContentType']); 62 63 return array('method' => Util::getGet('restCall'), 64 'params' => $getData); 65 } 66 67 /** 68 * Sends an RPC request to the server and returns the result. 69 * 70 * @param string The raw request string. 71 * 72 * @return mixed The response from the server or an PEAR error object on 73 * failure. 74 */ 75 function getResponse($request) 76 { 77 global $registry; 78 79 $method = str_replace('.', '/', $request['method']); 80 81 if (!$registry->hasMethod($method)) { 82 return PEAR::raiseError(sprintf(_("Method not defined. Called method: %s"), $method)); 83 } 84 85 /* Look at the method signature so that parameters are assigned by 86 * name, instead of relying on the order of GET parameters to match 87 * the order defined in the API method. */ 88 $signature = $registry->getSignature($method); 89 $params = array(); 90 foreach (array_keys($signature[0]) as $param) { 91 $params[$param] = isset($request['params'][$param]) ? $request['params'][$param] : null; 92 } 93 94 $result = $registry->call($method, $params); 95 if (is_a($result, 'PEAR_Error')) { 96 return $result; 97 } 98 99 /* The result is returned depending on the requested content type. */ 100 if ($this->_contentType == 'text/html') { 101 return '<html><body>' . print_r($result, true) . '</body></html>'; 102 } elseif ($this->_contentType == 'text/plain') { 103 return print_r($result, true); 104 } elseif ($this->_contentType == 'application/x-httpd-php') { 105 return serialize($result); 106 } else { 107 return $result; 108 } 109 } 110 111 /** 112 * Get the Content-Type of the response. 113 * 114 * @return string The MIME Content-Type of the RPC response. 115 */ 116 function getResponseContentType() 117 { 118 switch ($this->_contentType) { 119 case 'application/x-httpd-php': 120 return 'text/plain'; 121 default: 122 return $this->_contentType; 123 } 124 } 125 126 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |