コード例 #1
0
 /**
  * Interpret a WSDL definition
  * 
  * @param string $def WSDL definition
  * @param string $method Method name
  */
 public function InterpretDefinition($def, $method, $keywords, $docs)
 {
     PhpWsdl::Debug('Interpret definition');
     if (!PhpWsdl::CallHook('BeforeInterpretDefinitionHook', array('sender' => $this, 'server' => $this->Server, 'def' => &$def, 'method' => &$method, 'keywords' => &$keywords, 'docs' => &$docs))) {
         return null;
     }
     // Initialize some variables
     $param = array();
     // List ob parameter objects
     $return = null;
     // The return value object
     $elements = array();
     // List of element objects
     $settings = array();
     // Settings hash
     $omit = false;
     // Omit the object
     $type = null;
     // Type identifier
     $buffer = array();
     // Other data
     // Interpret keywords
     $i = -1;
     $len = sizeof($keywords);
     while (++$i < $len) {
         $keyword = $keywords[$i];
         if (PhpWsdl::$Debugging) {
             PhpWsdl::Debug('Interpret keyword ' . print_r($keyword, true));
         }
         // Call the global keyword handler
         if (!PhpWsdl::CallHook('InterpretKeywordHook', array('sender' => $this, 'server' => $this->Server, 'def' => &$def, 'method' => &$method, 'keywords' => &$keywords, 'docs' => &$docs, 'param' => &$param, 'elements' => &$elements, 'return' => &$return, 'settings' => &$settings, 'omit' => &$omit, 'keyword' => &$keyword, 'type' => &$type, 'buffer' => &$buffer, 'newkeyword' => &$newkeyword))) {
             continue;
         }
         if ($omit) {
             return null;
         }
         // Call the keyword handler
         if (!PhpWsdl::CallHook('InterpretKeyword' . $keyword[0] . 'Hook', array('sender' => $this, 'server' => $this->Server, 'def' => &$def, 'method' => &$method, 'keywords' => &$keywords, 'docs' => &$docs, 'param' => &$param, 'elements' => &$elements, 'return' => &$return, 'settings' => &$settings, 'omit' => &$omit, 'keyword' => &$keyword, 'type' => &$type, 'buffer' => &$buffer, 'newkeyword' => &$newkeyword))) {
             continue;
         }
         if ($omit) {
             return null;
         }
         PhpWsdl::Debug('Keyword not handled');
     }
     // Create object
     $obj = null;
     if (!PhpWsdl::CallHook('CreateObjectHook', array('sender' => $this, 'server' => $this->Server, 'def' => &$def, 'method' => &$method, 'keywords' => &$keywords, 'docs' => &$docs, 'param' => &$param, 'elements' => &$elements, 'return' => &$return, 'settings' => &$settings, 'omit' => &$omit, 'type' => &$type, 'buffer' => &$buffer, 'obj' => &$obj))) {
         return null;
     }
     if (!PhpWsdl::CallHook('AfterInterpretDefinitionHook', array('sender' => $this, 'server' => $this->Server, 'def' => &$def, 'method' => &$method, 'keywords' => &$keywords, 'docs' => &$docs, 'param' => &$param, 'elements' => &$elements, 'return' => &$return, 'settings' => &$settings, 'omit' => &$omit, 'type' => &$type, 'buffer' => &$buffer, 'obj' => &$obj))) {
         return null;
     }
     PhpWsdl::Debug('Object ' . (is_null($obj) ? 'not created' : 'created'));
     return $obj;
 }
コード例 #2
0
 /**
  * Create the HTML documentation for a complex type element
  * 
  * @param array $data
  */
 public function CreateElementHtml($data)
 {
     PhpWsdl::Debug('CreateElementHtml for ' . $data['element']->Name);
     $res =& $data['res'];
     $e =& $data['element'];
     if (in_array($e->Type, PhpWsdl::$BasicTypes)) {
         $res[] = '<li><span class="blue">' . $e->Type . '</span> <span class="bold">' . $e->Name . '</span>';
     } else {
         $res[] = '<li><a href="#' . $e->Type . '"><span class="lightBlue">' . $e->Type . '</span></a> <span class="bold">' . $e->Name . '</span>';
     }
     $o = sizeof($res) - 1;
     $temp = array('nillable = <span class="blue">' . ($e->NillAble ? 'true' : 'false') . '</span>', 'minoccurs = <span class="blue">' . $e->MinOccurs . '</span>', 'maxoccurs = <span class="blue">' . $e->MaxOccurs . '</span>');
     $res[$o] .= ' (' . implode(', ', $temp) . ')';
     if (!is_null($e->Docs)) {
         $res[$o] .= '<br><span class="normal">' . nl2br(htmlentities($e->Docs)) . '</span>';
     }
     $res[$o] .= '</li>';
     PhpWsdl::CallHook('CreateElementHtmlHook', $data);
 }
コード例 #3
0
 /**
  * Create the HTML documentation for a complex type
  * 
  * @param array $data
  */
 public function CreateTypeHtml($data)
 {
     PhpWsdl::Debug('CreateTypeHtml for ' . $data['type']->Name);
     $res =& $data['res'];
     $t =& $data['type'];
     $res[] = '<h3>' . $t->Name . '</h3>';
     $res[] = '<a name="' . $t->Name . '"></a>';
     $eLen = sizeof($t->Elements);
     if ($t->IsArray) {
         // Array type
         $res[] = '<p>This is an array type of <span class="pre">';
         $o = sizeof($res) - 1;
         if (in_array($t->Type, PhpWsdl::$BasicTypes)) {
             $res[$o] .= '<span class="blue">' . $t->Type . '</span>';
         } else {
             $res[$o] .= '<a href="#' . $t->Type . '"><span class="lightBlue">' . $t->Type . '</span></a>';
         }
         $res[$o] .= '</span>.</p>';
         if (!is_null($t->Docs)) {
             $res[] = '<p>' . nl2br(htmlentities($t->Docs)) . '</p>';
         }
     } else {
         if ($eLen > 0) {
             // Complex type with elements
             if (!is_null($t->Docs)) {
                 $res[] = '<p>' . nl2br(htmlentities($t->Docs)) . '</p>';
             }
             $res[] = '<ul class="pre">';
             $j = -1;
             while (++$j < $eLen) {
                 $t->Elements[$j]->CreateElementHtml(array_merge($data, array('element' => $t->Elements[$j])));
             }
             $res[] = '</ul>';
         } else {
             // Complex type without elements
             $res[] = '<p>This type has no elements.</p>';
         }
     }
     PhpWsdl::CallHook('CreateTypeHtmlHook', $data);
 }
コード例 #4
0
 /**
  * Create a NuSOAP soap_server object
  * 
  * @param PhpWsdl $server The PhpWsdl object
  * @return nusoap_server The NuSOAP server object
  */
 public static function CreateServer($server)
 {
     if (!is_null(self::$Server)) {
         return self::$Server;
     }
     // Basic configuration
     self::$Server = new nusoap_server();
     self::$Server->debug_flag = false;
     self::$Server->soap_defencoding = 'UTF-8';
     self::$Server->decode_utf8 = false;
     self::$Server->configureWSDL($server->Name, $server->NameSpace, $server->EndPoint);
     self::$Server->wsdl->schemaTargetNamespace = $server->NameSpace;
     if (!PhpWsdl::CallHook('NuSOAPConfigHook', array('server' => self::$Server))) {
         return self::$Server;
     }
     // Add types
     $i = -1;
     $len = sizeof($server->Types);
     while (++$i < $len) {
         $t = $server->Types[$i];
         PhpWsdl::Debug('Add complex type ' . $t->Name);
         if (!PhpWsdl::CallHook('NuSOAPTypeHook', array_merge($data, array('type' => &$t)))) {
             continue;
         }
         if ($t->IsArray) {
             $type = $t->Type;
             self::$Server->wsdl->addComplexType($t->Name, 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => (in_array($type, PhpWsdl::$BasicTypes) ? 'xsd:' . $type : 'tns:' . $type) . '[]')), in_array($type, PhpWsdl::$BasicTypes) ? 'xsd:' . $type : 'tns:' . $type);
         } else {
             if (get_class($t) == 'PhpWsdlEnum') {
                 self::$Server->wsdl->addSimpleType($t->Name, in_array($t->Type, PhpWsdl::$BasicTypes) ? 'xsd:' . $t->Type : 'tns:' . $t->Type, 'simpleType', 'scalar', $t->Elements);
             } else {
                 $el = array();
                 $j = -1;
                 $eLen = sizeof($t->Elements);
                 while (++$j < $eLen) {
                     $e = $t->Elements[$j];
                     $el[$e->Name] = array('name' => $e->Name, 'type' => in_array($e->Type, PhpWsdl::$BasicTypes) ? 'xsd:' . $e->Type : 'tns:' . $e->Type);
                 }
                 self::$Server->wsdl->addComplexType($t->Name, 'complexType', 'struct', 'sequence', '', $el);
             }
         }
     }
     PhpWsdl::CallHook('NuSOAPTypesHook', $data);
     // Add methods
     $i = -1;
     $len = sizeof($server->Methods);
     while (++$i < $len) {
         $m = $server->Methods[$i];
         PhpWsdl::Debug('Register method ' . $m->Name);
         if (!PhpWsdl::CallHook('NuSOAPMethodHook', array_merge($data, array('method' => &$m)))) {
             continue;
         }
         $param = array();
         $j = -1;
         $pLen = sizeof($m->Param);
         while (++$j < $pLen) {
             $p = $m->Param[$j];
             $param[$p->Name] = in_array($p->Type, PhpWsdl::$BasicTypes) ? 'xsd:' . $p->Type : 'tns:' . $p->Type;
         }
         $r = $m->Return;
         self::$Server->register($m->IsGlobal ? $m->Name : $server->Name . '.' . $m->Name, $param, is_null($r) ? array() : array('return' => in_array($r->Type, PhpWsdl::$BasicTypes) ? 'xsd:' . $r->Type : 'tns:' . $r->Type), $server->NameSpace, $server->NameSpace . $m->Name, 'rpc', 'encoded');
     }
     PhpWsdl::CallHook('NuSOAPMethodsHook', $data);
     return self::$Server;
 }
コード例 #5
0
 /**
  * Write WSDL to cache
  * 
  * @param string $wsdl The UTF-8 encoded WSDL string (default: NULL)
  * @param string $wsdluri The SOAP WSDL URI or NULL to use the default (default: NULL)
  * @param string $file The target filename or NULL to use the default (default: NULL)
  * @param boolean $force Force refresh (default: FALSE)
  * @return boolean Succeed?
  */
 public function WriteWsdlToCache($wsdl = null, $wsdluri = null, $file = null, $force = false)
 {
     PhpWsdl::Debug('Write WSDL to the cache');
     if (is_null($wsdluri)) {
         $wsdluri = $this->WsdlUri;
     }
     if ($wsdluri == $this->WsdlUri && !is_null($wsdl)) {
         $this->WSDL = $wsdl;
     }
     if (is_null($wsdl)) {
         if (is_null($this->WSDL)) {
             PhpWsdl::Debug('No WSDL');
             return false;
             // WSDL not defined
         }
         $wsdl = $this->WSDL;
     }
     if (is_null($file)) {
         $file = $this->GetCacheFileName($wsdluri);
         if (is_null($file)) {
             PhpWsdl::Debug('No cache file');
             return false;
             // No cache file
         }
     }
     $temp = substr($file, 0, 1);
     if ($temp != '/' && $temp != '.') {
         if (is_null(PhpWsdl::$CacheFolder)) {
             PhpWsdl::Debug('No cache folder');
             return false;
             // No cache folder
         }
         $file = PhpWsdl::$CacheFolder . '/' . $file;
     }
     if (!$force) {
         if ($this->IsCacheValid($file)) {
             PhpWsdl::Debug('Cache is still valid');
             return true;
             // Existing cache is still valid
         }
     }
     PhpWsdl::Debug('Write to ' . $file);
     if (file_put_contents($file, $wsdl) === false) {
         PhpWsdl::Debug('Could not write to cache');
         return false;
         // Error writing to cache
     }
     if (file_put_contents($file . '.cache', time()) === false) {
         PhpWsdl::Debug('Could not write cache time file');
         return false;
         // Error writing to cache
     }
     $data = array('version' => self::$VERSION, 'servicename' => $this->ServiceName, 'endpoint' => $this->EndPoint, 'namespace' => $this->NameSpace);
     PhpWsdl::CallHook('ClientWriteCacheHook', array('client' => $this, 'data' => &$data));
     if (file_put_contents($file . '.obj', serialize($data)) === false) {
         PhpWsdl::Debug('Could not write serialized cache');
         return false;
     }
     return true;
 }
コード例 #6
0
 /**
  * Create a Zend soap_server object
  * 
  * @param PhpWsdl $server The PhpWsdl object
  * @param array $data Hook data (default: NULL)
  * @return Zend_Soap_Server The Zend server object
  */
 public static function CreateServer($server, $data = null)
 {
     if (!is_null(self::$Server)) {
         return self::$Server;
     }
     self::$Server = new Zend_Soap_Server(!is_null($server->WsdlUri) ? $server->WsdlUri : $server->EndPoint . '?WSDL', array_merge(self::$Options, array('actor' => $server->EndPoint, 'wsdl' => $server->CreateWsdl(), 'uri' => $server->NameSpace)));
     if (!is_null($data)) {
         if (PhpWsdl::CallHook('ZendConfigHook', $data)) {
             if (is_object($data['class'])) {
                 $this->Server->setObject($data['class']);
             } else {
                 $this->Server->setClass($data['class']);
             }
         }
     }
 }
コード例 #7
0
 /**
  * Create return value HTML documentation
  * 
  * @param array $data Some data
  */
 public function CreateReturnHtml($data)
 {
     PhpWsdl::Debug('CreateReturnHtml for ' . $data['method']->Return->Name);
     $res =& $data['res'];
     $m =& $data['method'];
     $res[] = '<p>Return value <span class="pre">';
     $o = sizeof($res) - 1;
     $type = $m->Return->Type;
     if (in_array($type, PhpWsdl::$BasicTypes)) {
         $res[$o] .= '<span class="blue">' . $type . '</span>';
     } else {
         $res[$o] .= '<a href="#' . $type . '"><span class="lightBlue">' . $type . '</span></a>';
     }
     $res[$o] .= '</span>' . (!is_null($m->Return->Docs) ? ': ' . nl2br(htmlentities($m->Return->Docs)) : '') . '</p>';
     PhpWsdl::CallHook('CreateReturnHtmlHook', $data);
 }
コード例 #8
0
 /**
  * Decode a parameter or a return value
  * 
  * @param string $type The type name
  * @param mixed $value The value to be decoded
  * @param boolean $parameter Is this a parameter value? (default: FALSE)
  * @return mixed The decoded value
  */
 public static function DecodeType($type, $value, $parameter = false)
 {
     $res = null;
     $data = array('type' => &$type, 'value' => &$value, 'parameter' => &$parameter, 'res' => &$res);
     if (!PhpWsdl::CallHook('DecodeTypeHook', $data)) {
         return $res;
     }
     if (!PhpWsdl::CallHook('DecodeType' . ($parameter ? 'Parameter' : 'Return') . 'Hook', $data)) {
         return $res;
     }
     if (in_array($type, PhpWsdl::$BasicTypes)) {
         return $value;
     }
     $t = self::$UseServer->Server->GetType($type);
     if (is_null($t)) {
         throw new Exception('Could not decode type "' . $type . '"');
     }
     if (get_class($t) == 'PhpWsdlEnum') {
         $type = $t->Type;
     }
     return in_array($type, PhpWsdl::$BasicTypes) ? $value : json_decode($value);
 }
 /**
  * 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}";
 }
コード例 #10
0
 /**
  * Create the HTML documentation for an enumeration
  * 
  * @param array $data
  */
 public function CreateTypeHtml($data)
 {
     PhpWsdl::Debug('CreateTypeHtml for enumeration ' . $data['type']->Name);
     $res =& $data['res'];
     $t =& $data['type'];
     $res[] = '<h3>' . $t->Name . '</h3>';
     $res[] = '<a name="' . $t->Name . '"></a>';
     if (!is_null($t->Docs)) {
         $res[] = '<p>' . nl2br(htmlentities($t->Docs)) . '</p>';
     }
     $res[] = '<p>Possible ';
     $o = sizeof($res) - 1;
     if (in_array($t->Type, PhpWsdl::$BasicTypes)) {
         $res[$o] .= '<span class="blue">' . $t->Type . '</span>';
     } else {
         $res[$o] .= '<a href="#' . $t->Type . '"><span class="lightBlue">' . $t->Type . '</span></a>';
     }
     $res[$o] .= ' values:</p>';
     $res[] = '<ul class="pre">';
     $j = -1;
     $eLen = sizeof($t->Elements);
     while (++$j < $eLen) {
         $res[] = '<li>' . nl2br(htmlentities($this->Elements[$j])) . '</li>';
     }
     $res[] = '</ul>';
     PhpWsdl::CallHook('CreateTypeHtmlHook', $data);
 }