.
*/
if(basename($_SERVER['SCRIPT_FILENAME'])==basename(__FILE__))
exit;
PhpWsdl::RegisterHook('InterpretKeywordpw_complexHook','internal','PhpWsdlComplex::InterpretComplex');
PhpWsdl::RegisterHook('CreateObjectHook','internalcomplex','PhpWsdlComplex::CreateComplexTypeObject');
/**
* This class creates complex types (classes or arrays)
*
* @author Andreas Zimmermann, wan24.de
*/
class PhpWsdlComplex extends PhpWsdlObject{
/**
* The array type
*
* @var string
*/
public $Type=null;
/**
* A list of elements, if this type is a class
*
* @var PhpWsdlElement[]
*/
public $Elements;
/**
* Is this type an array?
*
* @var boolean
*/
public $IsArray;
/**
* Disable definition of arrays with the "Array" postfix in the type name?
*
* @var boolean
*/
public static $DisableArrayPostfix=false;
/**
* Constructor
*
* @param string $name The name
* @param PhpWsdlElement[] $el Optional a list of elements
* @param array $settings Optional the settings hash array (default: NULL)
*/
public function PhpWsdlComplex($name,$el=Array(),$settings=null){
self::__construct($name, $el, $settings);
}
public function __construct($name,$el=Array(),$settings=null){
PhpWsdl::Debug('New complex type '.$name);
parent::__construct($name,$settings);
if(!self::$DisableArrayPostfix){
$this->IsArray=substr($name,strlen($name)-5,5)=='Array';
if($this->IsArray)
$this->Type=substr($this->Name,0,strlen($this->Name)-5);
}
$this->Elements=$el;
if(!is_null($settings))
if(isset($settings['isarray']))
$this->IsArray=$settings['isarray'];
}
/**
* Create WSDL for the type
*
* @param PhpWsdl $pw The PhpWsdl object
* @return string The WSDL
*/
public function CreateType($pw){
$res=Array();
$res[]='
This is an array type of '; $o=sizeof($res)-1; if(in_array($t->Type,PhpWsdl::$BasicTypes)){ $res[$o].=''.$t->Type.''; }else{ $res[$o].=''.$t->Type.''; } $res[$o].='.
'; if(!is_null($t->Docs)) $res[]=''.nl2br(htmlentities($t->Docs)).'
'; }else if($eLen>0){ // Complex type with elements if(!is_null($t->Docs)) $res[]=''.nl2br(htmlentities($t->Docs)).'
'; $res[]='This type has no elements.
'; } PhpWsdl::CallHook( 'CreateTypeHtmlHook', $data ); } /** * Create type PHP code * * @param array $data The event data */ public function CreateTypePhp($data){ if($this->IsArray) return; $server=$data['server']; $res=&$data['res']; $res[]="/**"; if(!is_null($this->Docs)){ $res[]=" * ".implode("\n * ",explode("\n",$this->Docs)); $res[]=" *"; } $i=-1; $eLen=sizeof($this->Elements); while(++$i<$eLen){ $e=$this->Elements[$i]; $res[]=" * @pw_element ".$e->Type." \$".$e->Name.((!is_null($e->Docs))?" ".implode("\n\t * ",explode("\n",$e->Docs)):""); } $res[]=" * @pw_complex ".$this->Name; $res[]=" */"; $res[]="class ".$this->Name."{"; $i=-1; while(++$i<$eLen){ $e=$this->Elements[$i]; $res[]="\t/**"; if(!is_null($e->Docs)){ $res[]="\t * ".implode("\n\t * ",explode("\n",$e->Docs)); $res[]="\t *"; } $res[]="\t * @var ".$e->Type; $res[]="\t */"; $res[]="\tpublic \$".$this->Elements[$i]->Name.";"; } $res[]="}"; } /** * Interpret a complex type * * @param array $data The parser data * @return boolean Response */ public static function InterpretComplex($data){ $info=explode(' ',$data['keyword'][1],3); if(sizeof($info)<1) return true; $server=$data['server']; $name=$info[0]; PhpWsdl::Debug('Interpret complex type "'.$name.'"'); $type=null; $docs=null; if(strpos($name,'[]')>-1){ if(sizeof($info)<2){ PhpWsdl::Debug('WARNING: Invalid array definition!'); return true; } $name=substr($name,0,strlen($name)-2); if(!is_null($server->GetType($name))){ PhpWsdl::Debug('WARNING: Double type detected!'); return true; } $type=$info[1]; if($server->ParseDocs) if(sizeof($info)>2) $docs=$info[2]; PhpWsdl::Debug('Array "'.$name.'" type of "'.$type.'" definition'); }else{ if(!is_null($server->GetType($name))){ PhpWsdl::Debug('WARNING: Double type detected!'); return true; } if(!self::$DisableArrayPostfix&&substr($name,strlen($name)-5)=='Array'){ $type=substr($name,0,strlen($name)-5); PhpWsdl::Debug('Array "'.$name.'" type of "'.$type.'" definition'); }else{ PhpWsdl::Debug('Complex type definition'); } if($server->ParseDocs){ $temp=sizeof($info); if($temp>1) $docs=($temp>2)?$info[1].' '.$info[2]:$info[1]; } } $data['type']=Array( 'id' => 'complex', 'name' => $name, 'type' => $type, 'docs' => $docs ); return false; } /** * Create complex type object * * @param array $data The parser data * @return boolean Response */ public static function CreateComplexTypeObject($data){ if($data['method']!='') return true; if(!is_null($data['obj'])) return true; if(!is_array($data['type'])) return true; if(!isset($data['type']['id'])) return true; if($data['type']['id']!='complex') return true; if(!is_null($data['docs'])){ $data['settings']['docs']=$data['docs']; }else{ $data['settings']['docs']=$data['type']['docs']; } PhpWsdl::Debug('Add complex type '.$data['type']['name']); $data['settings']['isarray']=!is_null($data['type']['type']); $data['obj']=new PhpWsdlComplex($data['type']['name'],$data['elements'],$data['settings']); $data['obj']->Type=$data['type']['type']; $data['settings']=Array(); $data['server']->Types[]=$data['obj']; return true; } }