. */ if(basename($_SERVER['SCRIPT_FILENAME'])==basename(__FILE__)) exit; PhpWsdl::RegisterHook('InterpretKeywordpw_omitfncHook','internal','PhpWsdlMethod::InterpretOmit'); PhpWsdl::RegisterHook('InterpretKeywordignoreHook','internal','PhpWsdlMethod::InterpretOmit'); PhpWsdl::RegisterHook('InterpretKeywordpw_setHook','internal','PhpWsdlMethod::InterpretSetting'); PhpWsdl::RegisterHook('CreateObjectHook','internalmethod','PhpWsdlMethod::CreateMethodObject'); /** * A method definition object * * @author Andreas Zimmermann, wan24.de */ class PhpWsdlMethod extends PhpWsdlObject{ /** * A list of parameters * * @var PhpWsdlParam[] */ public $Param=Array(); /** * The return value * * @var PhpWsdlParam */ public $Return=null; /** * A global method? * * @var boolean */ public $IsGlobal=false; /** * A new method is global per default? * * @var boolean */ public static $IsGlobalDefault=false; /** * Constructor * * @param string $name The name * @param PhpWsdlParam[] $param Optional the list of parameters (default: NULL) * @param PhpWsdlParam $return Optional the return value (default: NULL) * @param array $settings Optional the settings hash array (default: NULL) */ public function PhpWsdlMethod($name,$param=null,$return=null,$settings=null){ self::__construct($name, $param, $return, $settings); } public function __construct($name,$param=null,$return=null,$settings=null){ PhpWsdl::Debug('New method '.$name); parent::__construct($name,$settings); if(!is_null($param)) $this->Param=$param; $this->Return=$return; $this->IsGlobal=self::$IsGlobalDefault; if(!is_null($settings)) if(isset($settings['global'])) $this->IsGlobal=$settings['global']=='true'||$settings['global']=='1'; } /** * Create the port type WSDL * * @param PhpWsdl $pw The PhpWsdl object * @return string The WSDL */ public function CreatePortType($pw){ PhpWsdl::Debug('Create WSDL port type for method '.$this->Name); $res=Array(); $res[]='Param); if($pLen>1){ $temp=Array(); $i=-1; while(++$i<$pLen) $temp[]=$this->Param[$i]->Name; $res[$o].=' parameterOrder="'.implode(' ',$temp).'"'; } $res[$o].='>'; if($pw->IncludeDocs&&!$pw->Optimize&&!is_null($this->Docs)) $res[]='Docs.']]>'; $res[]=''; $res[]=''; $res[]=''; return implode('',$res); } /** * Create the binding WSDL * * @param PhpWsdl $pw The PhpWsdl object * @return string The WSDL */ public function CreateBinding($pw){ PhpWsdl::Debug('Create WSDL binding for method '.$this->Name); $res=Array(); $res[]=''; $res[]=''; $res[]=''; $res[]='Param); if($pLen>0){ $temp=Array(); $i=-1; while(++$i<$pLen) $temp[]=$this->Param[$i]->Name; $res[sizeof($res)-1].=' parts="'.implode(' ',$temp).'"'; } $res[sizeof($res)-1].=' />'; $res[]=''; $res[]=''; $res[]='Return)) $res[sizeof($res)-1].=' parts="'.$this->Return->Name.'"'; $res[sizeof($res)-1].=' />'; $res[]=''; $res[]=''; return implode('',$res); } /** * Create the input/output messages WSDL * * @param PhpWsdl $pw The PhpWsdl object * @return string The WSDL */ public function CreateMessages($pw){ PhpWsdl::Debug('Create WSDL message for method '.$this->Name); $pLen=sizeof($this->Param); $res=Array(); // Request if($pLen<1){ $res[]=''; }else{ $res[]=''; $i=-1; while(++$i<$pLen) $res[]=$this->Param[$i]->CreatePart($pw); $res[]=''; } // Response if(is_null($this->Return)){ $res[]=''; }else{ $res[]=''; $res[]=$this->Return->CreatePart($pw); $res[]=''; } return implode('',$res); } /** * Find a parameter of this method * * @param string $name The parameter name * @return PhpWsdlParam The parameter or NULL, if not found */ public function GetParam($name){ PhpWsdl::Debug('Find parameter '.$name); $i=-1; $len=sizeof($this->Param); while(++$i<$len) if($this->Param[$i]->Name==$name){ PhpWsdl::Debug('Found parameter at index '.$i); return $this->Param[$i]; } return null; } /** * Create HTML docs * * @param array $data Some data */ public function CreateMethodHtml($data){ PhpWsdl::Debug('CreateMethodHtml for '.$data['method']->Name); $res=&$data['res']; $m=&$data['method']; $res[]='

'.$m->Name.'

'; $res[]=''; $res[]='

'; $o=sizeof($res)-1; if(!is_null($m->Return)){ $type=$m->Return->Type; if(in_array($type,PhpWsdl::$BasicTypes)){ $res[$o].=''.$type.''; }else{ $res[$o].=''.$type.''; } }else{ $res[$o].='void'; } $res[$o].=' '.$m->Name.' ('; $pLen=sizeof($m->Param); $spacer=''; if($pLen>1){ $res[$o].='
'; $spacer='    '; } $hasDocs=false; if($pLen>0){ $j=-1; while(++$j<$pLen){ $p=$m->Param[$j]; if(in_array($p->Type,PhpWsdl::$BasicTypes)){ $res[]=$spacer.''.$p->Type.' '.$p->Name.''; }else{ $res[]=$spacer.''.$p->Type.' '.$p->Name.''; } $o=sizeof($res)-1; if($j<$pLen-1) $res[$o].=', '; if($pLen>1) $res[$o].='
'; if(!$hasDocs) if(!is_null($p->Docs)) $hasDocs=true; } } $res[].=')

'; // Method documentation if(!is_null($m->Docs)) $res[]='

'.nl2br(htmlentities($m->Docs)).'

'; // Parameters documentation if($hasDocs){ $res[]=''; } // Return value documentation if(!is_null($m->Return)&&!is_null($m->Return->Docs)) $m->Return->CreateReturnHtml($data); PhpWsdl::CallHook( 'CreateMethodHtmlHook', $data ); } /** * Create method PHP * * @param array $data The event data */ public function CreateMethodPhp($data){ $server=$data['server']; $res=&$data['res']; $res[]="\t/**"; if(!is_null($this->Docs)){ $res[]="\t * ".implode("\n\t * ",explode("\n",$this->Docs)); $res[]="\t *"; } $param=Array(); $i=-1; $pLen=sizeof($this->Param); while(++$i<$pLen){ $p=$this->Param[$i]; $param[]='$'.$p->Name; $res[]="\t * @param ".$p->Type." \$".$p->Name.((!is_null($p->Docs))?" ".implode("\n\t * ",explode("\n",$p->Docs)):""); } if(!is_null($this->Return)){ $res[]="\t * @return ".$this->Return->Type.((!is_null($this->Return->Docs))?" ".implode("\n\t * ",explode("\n",$this->Return->Docs)):""); } $res[]="\t */"; $res[]="\tpublic function ".$this->Name."(".implode(',',$param)."){"; if(PhpWsdl::CallHook( 'CreateMethodPhpHook', array_merge( $data, Array( 'method' => $this ) ) ) ){ $res[]="\t\treturn self::_Call('".$this->Name."',Array("; if($pLen>0) $res[]="\t\t\t".implode(",\n\t\t\t",$param); $res[]="\t\t));"; } $res[]="\t}"; } /** * Interpret a setting * * @param array $data The parser data * @return boolean Response */ public static function InterpretSetting($data){ $info=explode(' ',$data['keyword'][1],2); if(sizeof($info)<1) return true; PhpWsdl::Debug('Interpret setting '.$info[0]); $info=explode('=',$info[0],2); if(sizeof($info)>1){ $data['settings'][$info[0]]=$info[1]; }else if(isset($data['settings'][$info[0]])){ unset($data['settings'][$info[0]]); } return false; } /** * Interpret omit keyword * * @param array $data The parser data * @return boolean Response */ public static function InterpretOmit($data){ PhpWsdl::Debug('Interpret omitfnc/ignore'); $data['omit']=true; return true; } /** * Create method object * * @param array $data The parser data * @return boolean Response */ public static function CreateMethodObject($data){ if(!is_null($data['obj'])) return true; if($data['method']=='') return true; if(!is_null($data['type'])) return true; PhpWsdl::Debug('Add method '.$data['method']); $server=$data['server']; if(!is_null($server->GetMethod($data['method']))){ PhpWsdl::Debug('WARNING: Double method detected!'); return true; } if($server->ParseDocs) if(!is_null($data['docs'])) $data['settings']['docs']=$data['docs']; $data['obj']=new PhpWsdlMethod($data['method'],$data['param'],$data['return'],$data['settings']); $data['settings']=Array(); $server->Methods[]=$data['obj']; return true; } }