From 8037da2703b4c464856fef4bf99381f6c8ffb9ca Mon Sep 17 00:00:00 2001 From: schickwasan Date: Sun, 14 Aug 2011 18:43:23 +0000 Subject: [PATCH] VERSION 2.2.1 Bugfix: PhpWsdl->IsFileInList did not declare the variable $fLen --- class.phpwsdl.php | 78 +--- class.phpwsdlobject.php | 11 +- class.soapdemo.php | 9 +- servers/class.phpwsdl.servers.php | 714 ------------------------------ servers/democlient-http.php | 35 -- servers/democlient-json.php | 22 - servers/democlient-rest.php | 35 -- servers/demoserver.php | 31 -- version.txt | 3 +- 9 files changed, 20 insertions(+), 918 deletions(-) delete mode 100644 servers/class.phpwsdl.servers.php delete mode 100644 servers/democlient-http.php delete mode 100644 servers/democlient-json.php delete mode 100644 servers/democlient-rest.php delete mode 100644 servers/demoserver.php diff --git a/class.phpwsdl.php b/class.phpwsdl.php index a34ec80..6a4d037 100644 --- a/class.phpwsdl.php +++ b/class.phpwsdl.php @@ -50,7 +50,7 @@ * * @author Andreas Zimmermann * @copyright ©2011 Andreas Zimmermann, wan24.de - * @version 2.3 + * @version 2.2.1 */ class PhpWsdl{ /** @@ -58,7 +58,7 @@ class PhpWsdl{ * * @var string */ - public static $VERSION='2.3'; + public static $VERSION='2.2.1'; /** * Set this to TRUE to enable the autorun in quick mode * @@ -508,24 +508,7 @@ public static function CreateInstance( $runServer=false ){ self::Debug('Create new PhpWsdl instance'); - $obj=null; - self::CallHook( - 'BeforeCreateInstanceHook', - Array( - 'server' => &$obj, - 'namespace' => &$nameSpace, - 'endpoint' => &$endPoint, - 'cachefolder' => &$cacheFolder, - 'file' => &$file, - 'name' => &$name, - 'methods' => &$methods, - 'types' => &$types, - 'outputonrequest'=> &$outputOnRequest, - 'runserver' => &$runServer - ) - ); - if(is_null($obj)) - $obj=new PhpWsdl($nameSpace,$endPoint,$cacheFolder,$file,$name,$methods,$types,$outputOnRequest,$runServer); + $obj=new PhpWsdl($nameSpace,$endPoint,$cacheFolder,$file,$name,$methods,$types,$outputOnRequest,$runServer); self::CallHook( 'CreateInstanceHook', Array( @@ -1175,10 +1158,9 @@ public function OutputWsdlOnRequest($andExit=true){ * * @param boolean $withHeaders Send HTML headers? (default: TRUE) * @param boolean $echo Print HTML (default: TRUE) - * @param boolean $cache Cache the result (default: TRUE); * @return string The HTML */ - public function OutputHtml($withHeaders=true,$echo=true,$cache=true){ + public function OutputHtml($withHeaders=true,$echo=true){ self::Debug('Output HTML'); if(sizeof($this->Methods)<1) $this->CreateWsdl(); @@ -1302,17 +1284,6 @@ public function OutputHtml($withHeaders=true,$echo=true,$cache=true){ } $cnt++; $temp['attachment_'.$cnt]=$this->Name.'.soapclient.php:'.((is_null($this->PhpUri))?$this->EndPoint.'?PHPSOAPCLIENT':$this->PhpUri); - self::CallHook( - 'PdfAttachmentHook', - Array( - 'server' => $this, - 'cnt' => &$cnt, - 'param' => &$temp, - 'res' => &$res, - 'methods' => &$methods, - 'types' => &$types - ) - ); } $options=Array(); $keys=array_keys($temp); @@ -1352,8 +1323,7 @@ public function OutputHtml($withHeaders=true,$echo=true,$cache=true){ return; $res=utf8_encode($res); $this->HTML=$res; - if($cache) - $this->WriteWsdlToCache(null,null,null,true); + $this->WriteWsdlToCache(null,null,null,true); if($echo) echo $res; return $res; @@ -1511,10 +1481,9 @@ public function OutputHtmlOnRequest($andExit=true){ * @param boolean $withHeaders Send text headers? (default: TRUE) * @param boolean $echo Print source (default: TRUE) * @param array $options Options array (default: array) - * @param boolean $cache Cache the result (default: TRUE); * @return string PHP source */ - public function OutputPhp($withHeaders=true,$echo=true,$options=Array(),$cache=true){ + public function OutputPhp($withHeaders=true,$echo=true,$options=Array()){ self::Debug('Output PHP'); if(sizeof($this->Methods)<1) $this->CreateWsdl(); @@ -1555,7 +1524,7 @@ public function OutputPhp($withHeaders=true,$echo=true,$options=Array(),$cache=t $res[]=" * ".implode("\n * ",explode("\n",$this->Docs)); $res[]=" *"; } - $res[]=" * @service ".$options['class']; + $res[]=" * @service ".$this->Name; $res[]=" */"; $res[]="class ".$options['class']."{"; $res[]="\t/**"; @@ -1637,8 +1606,7 @@ public function OutputPhp($withHeaders=true,$echo=true,$options=Array(),$cache=t ); $res=utf8_encode(implode("\n",$res)); $this->PHP=$res; - if($cache) - $this->WriteWsdlToCache(null,null,null,true); + $this->WriteWsdlToCache(null,null,null,true); if($echo) echo $res; return $res; @@ -1674,27 +1642,15 @@ public function RunServer($wsdlFile=null,$class=null,$andExit=true,$forceNoWsdl= self::Debug('Run the server'); if($forceNoWsdl) self::Debug('Forced non-WSDL mode'); - if(self::CallHook( - 'BeforeRunServerHook', - Array( - 'server' => $this, - 'wsdlfile' => &$wsdlFile, - 'class' => &$class, - 'andexit' => &$andExit, - 'forcenowsdl' => &$forceNoWsdl - ) - ) - ){ - // WSDL requested? - if($this->OutputWsdlOnRequest($andExit)) - return false; - // PHP requested? - if($this->OutputPhpOnRequest($andExit)) - return false; - // HTML requested? - if($this->OutputHtmlOnRequest($andExit)) - return false; - } + // WSDL requested? + if($this->OutputWsdlOnRequest($andExit)) + return false; + // PHP requested? + if($this->OutputPhpOnRequest($andExit)) + return false; + // HTML requested? + if($this->OutputHtmlOnRequest($andExit)) + return false; // Login $user=null; $password=null; diff --git a/class.phpwsdlobject.php b/class.phpwsdlobject.php index 4c749cd..f010731 100644 --- a/class.phpwsdlobject.php +++ b/class.phpwsdlobject.php @@ -44,12 +44,6 @@ class PhpWsdlObject{ * @var string */ public $Docs=null; - /** - * Other settings - * - * @var array - */ - public $Settings=null; /** * Constructor @@ -61,11 +55,8 @@ public function PhpWsdlObject($name,$settings=null){ $this->GUID=uniqid(); PhpWsdl::Debug('New PhpWsdlObject "'.$name.'" with GUID "'.$this->GUID.'"'); $this->Name=$name; - if(!is_null($settings)){ + if(!is_null($settings)) if(isset($settings['docs'])) $this->Docs=$settings['docs']; - if(isset($settings['settings'])) - $this->Settings=$settings['settings']; - } } } diff --git a/class.soapdemo.php b/class.soapdemo.php index ba98dd8..ca87cc7 100644 --- a/class.soapdemo.php +++ b/class.soapdemo.php @@ -13,7 +13,6 @@ class SoapDemo{ * Get a complex type object * * @return ComplexTypeDemo The object - * @pw_rest GET /GetComplexType This is the REST server path (see the PhpWsdlServers extension) */ public function GetComplexType(){ return new ComplexTypeDemo(); @@ -24,7 +23,6 @@ public function GetComplexType(){ * * @param ComplexTypeDemo $obj The object * @return string The result of print_r - * @pw_rest GET /PrintComplexType/:obj This is the REST server path (see the PhpWsdlServers extension) */ public function PrintComplexType($obj){ return utf8_encode($this->PrintVariable($obj)); @@ -35,7 +33,6 @@ public function PrintComplexType($obj){ * * @param ComplexTypeDemoArray $arr A ComplexTypeDemo array * @return stringArray The results of print_r - * @pw_rest GET /ComplexTypeArrayDemo/:arr This is the REST server path (see the PhpWsdlServers extension) */ public function ComplexTypeArrayDemo($arr){ $res=Array(); @@ -51,10 +48,8 @@ public function ComplexTypeArrayDemo($arr){ * * @param string $name Some name (or an empty string) * @return string Response string - * @pw_rest GET /SayHello/blubber This is the REST server path (see the PhpWsdlServers extension) for telling hello to unknown - * @pw_rest GET /SayHello/:name This is the REST server path (see the PhpWsdlServers extension) */ - public function SayHello($name=null){ + public function SayHello($name){ $name=utf8_decode($name);// Because a string parameter is UTF-8 encoded... if($name=='') $name='unknown'; @@ -63,8 +58,6 @@ public function SayHello($name=null){ /** * This method has no parameters and no return value, but it is visible in WSDL, too - * - * @pw_rest GET /DemoMethod This is the REST server path (see the PhpWsdlServers extension) */ public function DemoMethod(){ } diff --git a/servers/class.phpwsdl.servers.php b/servers/class.phpwsdl.servers.php deleted file mode 100644 index e4ec8f4..0000000 --- a/servers/class.phpwsdl.servers.php +++ /dev/null @@ -1,714 +0,0 @@ -. -*/ - -if(basename($_SERVER['SCRIPT_FILENAME'])==basename(__FILE__)) - exit; - -PhpWsdl::Debug('Servers extension loaded'); - -PhpWsdl::RegisterHook('InterpretKeywordpw_restHook','servers','PhpWsdlServers::InterpretRest'); -PhpWsdl::RegisterHook('BeforeRunServerHook','servers','PhpWsdlServers::BeforeRunServerHook'); -PhpWsdl::RegisterHook('PrepareServerHook','servers','PhpWsdlServers::PrepareServerHook'); -PhpWsdl::RegisterHook('RunServerHook','servers','PhpWsdlServers::RunServerHook'); -PhpWsdl::RegisterHook('BeginCreatePhpHook','servers','PhpWsdlServers::BeginCreatePhpHook'); -PhpWsdl::RegisterHook('OutputPhpHook','servers','PhpWsdlServers::OutputPhpHook'); -PhpWsdl::RegisterHook('CreatePhpCallHook','servers','PhpWsdlServers::CreatePhpCallHook'); -PhpWsdl::RegisterHook('CreateHtmlGeneralHook','servers','PhpWsdlServers::CreateHtmlGeneralHook'); -PhpWsdl::RegisterHook('PdfAttachmentHook','servers','PhpWsdlServers::PdfAttachmentHook'); - -/** - * Some http protocol servers (JSON, http and REST) - * - * @author Andreas Zimmermann, wan24.de - * @version 2.3 - */ -class PhpWsdlServers{ - /** - * The version number - * - * @var string - */ - public static $VERSION='2.3'; - /** - * Disable the client cache? - * - * @var boolean - */ - public static $DisableClientCache=true; - /** - * Enable the JSON server - * - * @var boolean - */ - public static $EnableJson=true; - /** - * Enable the http server - * - * @var boolean - */ - public static $EnableHttp=true; - /** - * Enable the REST server - * - * @var boolean - */ - public static $EnableRest=true; - /** - * The webservice handler class name - * - * @var string - */ - public $ClassName=null; - /** - * The webservice handler object - * - * @var object - */ - public $Object=null; - /** - * The PhpWsdl object - * - * @var PhpWsdl - */ - public $Server=null; - /** - * The URI to the PHP client proxy download - * - * @var string - */ - public $PhpUri=null; - - /** - * Constructor - * - * @param PhpWsdl $server The PhpWsdl object - */ - public function PhpWsdlServers($server){ - $this->Server=$server; - } - - /** - * Determine if the request is a JSON request - * - * @return boolean JSON request? - */ - public static function IsJsonRequest(){ - return self::$EnableJson&&!self::HasParam('call')&&(self::HasParam('json')||self::HasParam('JSON')); - } - - /** - * Determine if the request is a http request - * - * @return boolean http request? - */ - public static function IsHttpRequest(){ - return self::$EnableHttp&&self::HasParam('call'); - } - - /** - * Determine if the request is a REST request - * - * @return boolean REST request? - */ - public static function IsRestRequest(){ - return self::$EnableRest&&isset($_SERVER['PATH_INFO']); - } - - /** - * Determine if the PhpWsdlServers extension can handle this request - * - * @return boolean Can handle? - */ - public static function CanHandleRequest(){ - return self::IsHttpRequest()||self::IsJsonRequest()||self::IsRestRequest(); - } - - /** - * Determine if we can handle the request - * - * @param array $data The event data - * @return boolean Response - */ - public static function BeforeRunServerHook($data){ - return !(self::HasParam('phpjsonclient')||self::HasParam('PHPJSONCLIENT')||self::CanHandleRequest()); - } - - /** - * Create a server object - * - * @param array $data The event data - * @return boolean Response - */ - public static function PrepareServerHook($data){ - if(!self::CanHandleRequest()) - return true; - PhpWsdl::Debug('Prepare a JSON/http/REST server'); - $server=&$data['server']; - $json=new PhpWsdlServers($server); - $data['soapserver']=$json; - $useProxy=&$data['useproxy']; - $class=&$data['class']; - if($useProxy||!is_object($class)){ - $temp=($useProxy)?'PhpWsdlProxy':$class; - if(!is_null($temp)){ - PhpWsdl::Debug('Setting server class '.$temp); - $json->ClassName=$temp; - }else{ - PhpWsdl::Debug('No server class or object'); - } - }else{ - PhpWsdl::Debug('Setting server object '.get_class($class)); - $json->Object=$class; - } - return false; - } - - /** - * Run the server - * - * @param array $data The event data - * @return boolean Response - */ - public static function RunServerHook($data){ - if(self::HasParam('phpjsonclient')||self::HasParam('PHPJSONCLIENT')){ - PhpWsdl::Debug('Create PHP client'); - $data['server']->OutputPhp(true,true,Array(),false); - if($data['andexit']) - exit; - return false; - } - if(!self::CanHandleRequest()) - return true; - if(get_class($data['soapserver'])!='PhpWsdlServers'){ - PhpWsdl::Debug('Not a valid server object'); - return true; - } - PhpWsdl::Debug('Handle the request'); - if(self::IsJsonRequest()) - return $data['soapserver']->HandleJsonRequest(); - if(self::IsHttpRequest()) - return $data['soapserver']->HandleHttpRequest(); - if(self::IsRestRequest()) - return $data['soapserver']->HandleRestRequest(); - throw(new Exception('Could not handle request')); - } - - /** - * Interpret a REST declaration - * - * @param array $data The event data - * @return boolean Response - */ - public static function InterpretRest($data){ - if($data['method']=='') - return true; - PhpWsdl::Debug('Interpret REST "'.$data['keyword'][1].'" for method "'.$data['method'].'"'); - $info=explode(' ',$data['keyword'][1],3); - if(sizeof($info)<2){ - PhpWsdl::Debug('Invalid REST definition'); - return true; - } - $method=$info[0]; - $path=$info[1]; - $docs=null; - if(sizeof($info)>2) - $docs=$info[2]; - $settings=&$data['settings']; - if(!isset($settings['settings'])) - $settings['settings']=Array(); - $settings=&$settings['settings']; - if(!isset($settings['rest'])) - $settings['rest']=Array(); - $settings=&$settings['rest']; - if(!isset($settings[$method])) - $settings[$method]=Array(); - $settings=&$settings[$method]; - $settings[]=Array( - 'path' => $path, - 'docs' => $docs - ); - return false; - } - - /** - * Create PHP properties - * - * @param array $data The event data - * @return boolean Response - */ - public static function BeginCreatePhpHook($data){ - if( - !self::HasParam('phpjsonclient')&& - !self::HasParam('PHPJSONCLIENT') - ) - return true; - $res=&$data['res']; - $server=$data['server']; - $res[]="\t/**"; - $res[]="\t * The endpoint URI"; - $res[]="\t *"; - $res[]="\t * @var string"; - $res[]="\t */"; - $res[]="\tpublic static \$_EndPoint='".$server->EndPoint."';"; - return false; - } - - /** - * Change the class name - * - * @param array $data The event data - * @return boolean Response - */ - public static function OutputPhpHook($data){ - $options=&$data['options']; - $server=&$data['server']; - if(!isset($options['class'])) - $options['class']=$server->Name.'JsonClient'; - return true; - } - - /** - * Create PHP code for a server request - * - * @param array $data The event data - * @return boolean Response - */ - public static function CreatePhpCallHook($data){ - if( - ( - !self::HasParam('phpjsonclient')&& - !self::HasParam('PHPJSONCLIENT') - )|| - !self::$EnableJson - ) - return true; - PhpWsdl::Debug('Create PhpWsdlServers JSON PHP client code'); - $res=&$data['res']; - $res[]="\t\t".'$call=Array('; - $res[]="\t\t\t".'"call"=>$method,'; - $res[]="\t\t\t".'"param"=>$param'; - $res[]="\t\t".');'; - $res[]="\t\t".'return json_decode(file_get_contents($this->EndPoint."?JSON=".urlencode(json_encode($call))'; - return false; - } - - /** - * Extend HTML documentation - * - * @param array $data The event data - * @return boolean Response - */ - public static function CreateHtmlGeneralHook($data){ - if(!self::$EnableJson) - return true; - PhpWsdl::Debug('Append HTML general information with PhpWsdlServers information'); - $res=&$data['res']; - $server=$data['server']; - $url=$server->EndPoint.'?PHPJSONCLIENT'; - $res[]='

PHP JSON client download URI: '.$url.'

'; - return true; - } - - /** - * Attach the PHP client sources - * - * @param array $data The event data - * @return boolean Response - */ - public static function PdfAttachmentHook($data){ - if(!self::$EnableJson) - return true; - $temp=&$data['param']; - $cnt=&$data['cnt']; - $cnt++; - $server=$data['server']; - $temp['attachment_'.$cnt]=$server->Name.'.jsonclient.php:'.$server->EndPoint.'?PHPJSONCLIENT'; - return true; - } - - /** - * Handle a REST request - * - * @return boolean Response - */ - public function HandleRestRequest(){ - // Find the requested method - $path=$_SERVER['PATH_INFO']; - $temp=self::GetParam('method'); - $method=($temp=='')?$_SERVER['REQUEST_METHOD']:$temp; - PhpWsdl::Debug('REST call "'.$method.'" at "'.$path.'"'); - $temp=$this->GetRestMethod($method,$path); - if(is_null($temp)) - throw(new Exception('Method not found')); - list($method,$target)=$temp; - $req=Array( - 'call' => $method->Name, - 'param' => Array() - ); - PhpWsdl::CallHook( - 'RestCallHook', - Array( - 'server' => $this, - 'req' => &$req, - 'path' => &$path, - 'method' => &$method, - 'target' => &$target - ) - ); - // Collect the parameters - if(PhpWsdl::CallHook( - 'RestParametersHook', - Array( - 'server' => $this, - 'req' => &$req, - 'path' => &$path, - 'method' => &$method, - 'target' => &$target - ) - ) - ){ - $pLen=sizeof($method->Param); - if(is_null($target)){ - // Unknown parameter handling - PhpWsdl::Debug('Undefined parameter handling'); - $temp=explode('/',$path); - $tLen=sizeof($temp)-1; - // Collect parameters from the path info - $i=-1; - while(++$i<$pLen){ - $p=$methods->Param[$i]; - if($i>$tLen){ - PhpWsdl::Debug('Collecting parameters stopped at missing "'.$p->Name.'"'); - break; - } - $req['param'][]=urldecode((in_array($p->Type,PhpWsdl::$BasicTypes))?$temp[$i+1]:json_decode($temp[$i+1])); - } - }else{ - // Declared parameter handling - PhpWsdl::Debug('Fixed parameter handling'); - if(strpos($target,':')>-1){ - PhpWsdl::Debug('Method with parameters'); - list($mTemp,$pTemp)=explode(':',$target,2); - }else{ - PhpWsdl::Debug('Method without parameters'); - $mTemp=$target; - $pTemp=false; - } - if($pTemp!==false){ - // Map input parameters to their names - $temp=explode('/',substr($path,strlen($mTemp))); - $tLen=sizeof($temp); - $iMap=explode('/',str_replace(':','',$pTemp)); - $map=Array(); - $i=-1; - $len=sizeof($iMap); - while(++$i<$len) - $map[$iMap[$i]]=$temp[$i]; - // Sort parameters - $temp=Array(); - $i=-1; - $lastValue=-1; - while(++$i<$pLen){ - $p=$method->Param[$i]; - $name=$p->Name; - if(isset($map[$name])){ - $temp[]=(in_array($p->Type,PhpWsdl::$BasicTypes))?urldecode($map[$name]):json_decode(urldecode($map[$name])); - $lastValue=$i; - }else{ - PhpWsdl::Debug('Parameter "'.$p->Name.'" not found'); - $temp[]=null; - } - } - // Remove all parameters that are not present in the request - if($lastValue>-1&&$lastValue<$pLen){ - $i=$lastValue; - $req['param']=array_slice($temp,0,$lastValue+1); - }else{ - $req['param']=$temp; - } - }else{ - $i=-1; - } - } - // Collect the last parameter from the request body - if($i<$pLen&&$pLen>0){ - if(PhpWsdl::CallHook( - 'RestRequestHook', - Array( - 'server' => $this, - 'req' => &$req, - 'path' => &$path, - 'method' => &$method, - 'target' => &$target, - 'index' => $i - ) - ) - ){ - $temp=file_get_contents('php://input'); - if($temp!=''){ - PhpWsdl::Debug('Use request body as parameter #'.($i+1)); - $req['param'][]=json_decode($temp); - } - } - } - } - if(PhpWsdl::$Debugging) - PhpWsdl::Debug('Parameters: '.print_r($req['param'],true)); - // Execute the method and output the response - $temp=$this->HandleRequest($req,$method); - if(is_null($method->Return)) - return false;// No return value -> no output - if(PhpWsdl::CallHook( - 'RestResponseHook', - Array( - 'server' => $this, - 'req' => &$req, - 'res' => &$temp, - 'path' => &$path, - 'method' => &$method, - 'target' => &$target - ) - ) - ){ - ob_start('ob_gzhandler'); - $this->PlainTextHeaders(); - echo (in_array($method->Return->Type,PhpWsdl::$BasicTypes))?$temp:json_encode($temp); - } - return false; - } - - /** - * Handle a JSON request - * - * @return boolean Response - */ - public function HandleJsonRequest(){ - // Decode the JSON request - $json=(self::HasParam('json'))?'json':'JSON'; - $req=json_decode(self::GetParam($json)); - if(is_null($req)||!is_object($req)) - throw(new Exception('Invalid JSON object')); - if(!isset($req->param)) - $req->param=Array(); - if(!isset($req->call)) - throw(new Exception('Invalid JSON request')); - PhpWsdl::Debug('JSON call "'.$req->call.'"'); - if(PhpWsdl::$Debugging) - PhpWsdl::Debug('Parameters: '.print_r($req->param,true)); - $req=Array( - 'call' => $req->call, - 'param' => $req->param - ); - // Find the requested method object - $method=$this->Server->GetMethod($req['call']); - if(is_null($method)) - throw(new Exception('Method "'.$req['call'].'" not exists')); - // Execute the method and output the response - $temp=$this->HandleRequest($req,$method); - ob_start('ob_gzhandler'); - $this->PlainTextHeaders(); - echo json_encode($temp); - return false; - } - - /** - * Handle a http request - * - * @return boolean Response - */ - public function HandleHttpRequest(){ - // Initialize the method call - $req=Array( - 'call' => self::GetParam('call'), - 'param' => Array() - ); - PhpWsdl::Debug('http call "'.$req['call'].'"'); - // Find the requested method object and parameters - $method=$this->Server->GetMethod($req['call']); - if(is_null($method)) - throw(new Exception('Method "'.$req['call'].'" not exists')); - if(PhpWsdl::CallHook( - 'HttpParametersHook', - Array( - 'server' => $this, - 'req' => &$req, - 'method' => &$method - ) - ) - ){ - $i=-1; - $len=sizeof($method->Param); - while(++$i<$len){ - $p=$method->Param[$i]; - if(!self::HasParam($method->Param[$i]->Name)){ - PhpWsdl::Debug('Collecting parameters stopped at missing "'.$method->Param[$i]->Name.'"'); - break; - } - $temp=self::GetParam($method->Param[$i]->Name); - $req['param'][]=(in_array($p->Type,PhpWsdl::$BasicTypes))?$temp:json_decode($temp); - } - } - if(PhpWsdl::$Debugging) - PhpWsdl::Debug('Parameters: '.print_r($req['param'],true)); - // Execute the method and output the response - $temp=$this->HandleRequest($req,$method); - if(is_null($method->Return)) - return false;// No return value -> no output - if(PhpWsdl::CallHook( - 'HttpResponseHook', - Array( - 'server' => $this, - 'req' => &$req, - 'res' => &$temp, - 'method' => &$method - ) - ) - ){ - ob_start('ob_gzhandler'); - $this->PlainTextHeaders(); - echo (in_array($method->Return->Type,PhpWsdl::$BasicTypes))?$temp:json_encode($temp); - } - return false; - } - - /** - * Handle a request - * - * @param array $req The request data - * @param PhpWsdlMethod $method The method object - * @return mixed The response - */ - private function HandleRequest($req,$method){ - // Get the handler object - $res=null; - $obj=$this->Object; - if(is_null($obj)) - if(!is_null($this->ClassName)) - if(class_exists($this->ClassName)) - eval("\$obj=new ".$this->ClassName."();"); - PhpWsdl::Debug('Handler object: '.print_r($obj,true)); - // Prepare the call - $call=($method->IsGlobal) - ?$method->Name - :Array( - $obj, - $method->Name - ); - PhpWsdl::Debug('Call: '.print_r($call,true)); - // Call the method - $pLen=sizeof($req['param']); - if($pLen<1){ - return call_user_func($call); - }else if($pLen<2){ - return call_user_func($call,$req['param'][0]); - }else{ - return call_user_func_array($call,$req['param']); - } - } - - /** - * Output plain text response headers - */ - private function PlainTextHeaders(){ - header('Content-Type: text/plain; encoding=UTF-8'); - if(self::$DisableClientCache) - $this->NoCacheHeaders(); - } - - /** - * Output headers to disable the client cache - */ - private function NoCacheHeaders(){ - header('Expires: Tue, 03 Jul 2001 06:00:00 GMT'); - header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); - header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); - header('Cache-Control: post-check=0, pre-check=0',false); - header('Pragma: no-cache'); - } - - /** - * Get a http parameter - * - * @param string $name The key - * @return string The value - */ - private static function GetParam($name){ - $name=addslashes($name); - if(isset($_GET[$name])) - return stripslashes($_GET[$name]); - if(isset($_POST[$name])) - return stripslashes($_POST[$name]); - return ''; - } - - /** - * Determine if we got a GET/POST parameter - * - * @param string $name - * @return boolean Parameter exists? - */ - private static function HasParam($name){ - return isset($_GET[$name])||isset($_POST[$name]); - } - - /** - * Find the handler method for a REST request - * - * @param string $method The method (GET/POST/...) - * @param string $path The REST server path - * @return array The handler method and the path or NULL, if not found - */ - private function GetRestMethod($method,$path){ - if(substr($path,strlen($path)-1)!='/') - $path.='/'; - // Find a REST method - PhpWsdl::Debug('Find REST method "'.$method.'" at "'.$path.'"'); - $i=-1; - $mLen=sizeof($this->Server->Methods); - while(++$i<$mLen){ - $m=$this->Server->Methods[$i]; - if(is_null($m->Settings)) - continue; - if(!isset($m->Settings['rest'])) - continue; - if(!isset($m->Settings['rest'][$method])) - continue; - $rest=$m->Settings['rest'][$method]; - $j=-1; - $rLen=sizeof($rest); - while(++$j<$rLen){ - $call=$rest[$j]['path']; - if(strpos($call,':')>-1) - list($call,$dummy)=explode(':',$call,2); - if(substr($call,strlen($call)-1)!='/') - $call.='/'; - if(substr($path,0,strlen($call))==$call){ - PhpWsdl::Debug('Method found at index #'.$i); - return Array($m,$rest[$j]['path']); - } - } - } - // Find a method without REST declaration - $temp=explode('/',$path); - $res=$this->Server->GetMethod($temp[1]); - return (is_null($res)) - ?null - :Array($res,null); - } -} diff --git a/servers/democlient-http.php b/servers/democlient-http.php deleted file mode 100644 index 26d753b..0000000 --- a/servers/democlient-http.php +++ /dev/null @@ -1,35 +0,0 @@ - HandleHttpRequest) and -// return FALSE in your handler methods to prevent the default handling. - -// This is the URI to the http server -$endPoint=((isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on')?'https':'http').'://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']).'/demoserver.php'; - -// This will call the method "SayHello" -$param=Array(); -$param['call']='SayHello'; // The method name -$param['name']='you'; // The parameter "name" - -// Encode the parameters for a http request -$temp=Array(); -$i=-1; -$keys=array_keys($param); -$len=sizeof($keys); -while(++$i<$len) - $temp[]=urlencode($keys[$i]).'='.urlencode($param[$keys[$i]]); -$param=implode('&',$temp); - -// Call the webservice -$res=file_get_contents($endPoint.'?'.$param); - -// Display the result and quit -echo htmlentities($res); -exit; diff --git a/servers/democlient-json.php b/servers/democlient-json.php deleted file mode 100644 index 990cbbc..0000000 --- a/servers/democlient-json.php +++ /dev/null @@ -1,22 +0,0 @@ -'SayHello', // The method name to call - 'param'=>Array( // The parameters for the method call - 'you' - ) -); - -// Call the webservice -$res=file_get_contents($endPoint.'?json='.urlencode(json_encode($req))); - -// Display the result and quit -echo htmlentities(json_decode($res)); -exit; diff --git a/servers/democlient-rest.php b/servers/democlient-rest.php deleted file mode 100644 index 8b64c61..0000000 --- a/servers/democlient-rest.php +++ /dev/null @@ -1,35 +0,0 @@ - HandleRestRequest) and -// return FALSE in your handler methods to prevent the default handling. - -// This is the URI to the http server -$endPoint=((isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on')?'https':'http').'://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']).'/demoserver.php'; - -// Call the method "SayHello" -$rest='/SayHello/you';// Note that parameters in the rest path have to be URL encoded! -echo '
';
-echo "SayHello:\n";
-echo htmlentities(file_get_contents($endPoint.$rest))."\n";
-echo "\n";
-
-// Call the method "GetComplexType"
-$rest='/GetComplexType';
-$temp=json_decode(file_get_contents($endPoint.$rest));
-echo "GetComplexType:\n";
-echo htmlentities(print_r($temp,true))."\n";
-echo "\n";
-
-// Call the method "PrintComplexType"
-$rest='/PrintComplexType/'.urlencode(json_encode($temp));
-echo "PrintComplexType:\n";
-echo htmlentities(file_get_contents($endPoint.$rest));
-echo '
'; -exit; diff --git a/servers/demoserver.php b/servers/demoserver.php deleted file mode 100644 index 9aad76f..0000000 --- a/servers/demoserver.php +++ /dev/null @@ -1,31 +0,0 @@ -IsFileInList did not declare the variable $fLen -New: Run JSON, http or REST webservices with the servers extension 2011-08-13: 2.2 Bugfix: Parsing the documentation couldn't be fully disabled