| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4 // +----------------------------------------------------------------------+ 5 // | Akelos Framework - http://www.akelos.org | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez | 8 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 9 // +----------------------------------------------------------------------+ 10 11 /** 12 * @package ActionWebservice 13 * @subpackage Server 14 * @author Bermi Ferrer <bermi a.t akelos c.om> 15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 17 */ 18 19 class AkXmlRpcServer extends AkObject 20 { 21 var $_ActionWebServiceServer; 22 var $options = array(); 23 24 function AkXmlRpcServer(&$ActionWebServiceServer) 25 { 26 $this->_ActionWebServiceServer =& $ActionWebServiceServer; 27 } 28 29 function init($options = array()) 30 { 31 $default_options = array( 32 'dynamic_server_class_name' => 'AkDynamicXmlRpcServer' 33 ); 34 35 $this->options = array_merge($default_options, $options); 36 37 if(!empty($this->_ActionWebServiceServer->_services)){ 38 foreach (array_keys($this->_ActionWebServiceServer->_services) as $name_space){ 39 $this->_addWebService($name_space, $this->_ActionWebServiceServer->_services[$name_space]); 40 } 41 } 42 } 43 44 function _addWebService($service_name, &$WebService) 45 { 46 $Apis =& $WebService->getApis(); 47 48 foreach (array_keys($Apis) as $k){ 49 $api_methods =& $Apis[$k]->getApiMethods(); 50 foreach (array_keys($api_methods) as $k){ 51 $api_method =& $api_methods[$k]; 52 $public_name = AkInflector::variablize($api_method->public_name); 53 $signatures = var_export(array_merge($api_method->returns, $api_method->expects), true); 54 $documentation = var_export($this->_getDocumentationForMethod($api_method), true); 55 56 $this->_callbacks[] = " 57 58 \$this->addCallback( 59 '$service_name.$public_name', 60 'this:_{$service_name}_{$api_method->name}_call', 61 $signatures, 62 $documentation 63 ); 64 "; 65 66 $this->_methods[] = " 67 68 function _{$service_name}_{$api_method->name}_call() 69 { 70 \$args = func_get_args(); 71 return call_user_func_array(array(&\$this->_{$service_name}, '".$api_method->name."'), (array)\$args[0]); 72 } 73 "; 74 75 } 76 } 77 } 78 79 function _getDocumentationForMethod($ApiMethod) 80 { 81 82 $doc = !empty($ApiMethod->documentation)? $ApiMethod->documentation."\n" : ''; 83 foreach (array('expects', 'returns') as $expects_or_returns){ 84 if(!empty($ApiMethod->{$expects_or_returns})){ 85 foreach ($ApiMethod->{$expects_or_returns} as $k=>$type){ 86 $doc .= "\n".( 87 $expects_or_returns == 'expects' ? 88 Ak::t(AkInflector::ordinalize($k+1)).' parameter as' : 'Returns' 89 )." $type:"; 90 if(!empty($ApiMethod->{$expects_or_returns.'_documentation'}[$k])){ 91 $doc .= ' '.$ApiMethod->{$expects_or_returns.'_documentation'}[$k]; 92 } 93 } 94 } 95 } 96 return $doc; 97 98 } 99 100 101 function _generateServerClassCode() 102 { 103 $this->_serverClassCode = "<?php 104 class {$this->options['dynamic_server_class_name']} extends AkIxrInstrospectionServer 105 { 106 function {$this->options['dynamic_server_class_name']}() 107 { 108 \$this->IXR_IntrospectionServer(); 109 } 110 "; 111 112 $this->_serverClassCode .= join("\n", $this->_methods); 113 114 $this->_serverClassCode .= ' 115 function init() 116 { 117 '. join("\n", $this->_callbacks).' 118 119 $this->serve(); 120 } 121 122 } 123 124 ?>'; 125 126 127 } 128 129 function serve() 130 { 131 $this->_generateServerClassCode(); 132 eval('?>'.$this->_serverClassCode.'<?php '); 133 $Server =& new $this->options['dynamic_server_class_name']; 134 $this->_linkWebServicesToServer($Server); 135 $Server->init(); 136 } 137 138 function _linkWebServicesToServer(&$Server) 139 { 140 if(!empty($this->_ActionWebServiceServer->_services)){ 141 foreach (array_keys($this->_ActionWebServiceServer->_services) as $name_space){ 142 $Server->{'_'.$name_space} =& $this->_ActionWebServiceServer->_services[$name_space]; 143 } 144 } 145 } 146 147 } 148 149 require_once(AK_VENDOR_DIR.DS.'incutio'.DS.'IXR_Library.inc.php'); 150 151 class AkIxrInstrospectionServer extends IXR_IntrospectionServer 152 { 153 var $_services = array(); 154 155 function output($xml) 156 { 157 $xml = '<?xml version="1.0"?>'."\n".$xml; 158 $length = strlen($xml); 159 header('Connection: close'); 160 header('Content-Length: '.$length); 161 header('Content-Type: text/xml'); 162 header('Date: '.date('r')); 163 echo $xml; 164 exit; 165 } 166 167 function _addService($service_name, &$ServiceInstance) 168 { 169 $this->_services[$service_name] =& $ServiceInstance; 170 } 171 } 172 173 174 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |