25 #require_once "Zend/Soap/Wsdl/Strategy/Interface.php"; 30 #require_once "Zend/Soap/Wsdl/Strategy/Abstract.php"; 33 #require_once "Zend/Xml/Security.php"; 61 private $_schema =
null;
68 private $_includedTypes = array();
85 if ($uri instanceof Zend_Uri_Http) {
86 $uri = $uri->getUri();
94 $wsdl =
"<?xml version='1.0' ?> 95 <definitions name='$name' targetNamespace='$uri' 96 xmlns='http://schemas.xmlsoap.org/wsdl/' 98 xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 99 xmlns:xsd='http://www.w3.org/2001/XMLSchema' 100 xmlns:soap-enc='http://schemas.xmlsoap.org/soap/encoding/' 101 xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'></definitions>";
102 $this->_dom =
new DOMDocument();
104 #require_once 'Zend/Server/Exception.php'; 107 $this->_wsdl = $this->_dom->documentElement;
120 if ($uri instanceof Zend_Uri_Http) {
121 $uri = $uri->getUri();
123 $oldUri = $this->_uri;
126 if($this->_dom !==
null) {
128 $xml = $this->_dom->saveXML();
129 $xml = str_replace($oldUri, $uri, $xml);
130 $this->_dom =
new DOMDocument();
146 if($strategy ===
true) {
147 #require_once "Zend/Soap/Wsdl/Strategy/DefaultComplexType.php"; 149 }
else if($strategy ===
false) {
150 #require_once "Zend/Soap/Wsdl/Strategy/AnyType.php"; 152 }
else if(is_string($strategy)) {
154 $strategy =
new $strategy();
156 #require_once "Zend/Soap/Wsdl/Exception.php"; 158 sprintf(
"Strategy with name '%s does not exist.", $strategy
164 #require_once "Zend/Soap/Wsdl/Exception.php"; 167 $this->_strategy = $strategy;
193 $message = $this->_dom->createElement(
'message');
197 if (
sizeof($parts) > 0) {
199 $part = $this->_dom->createElement(
'part');
200 $part->setAttribute(
'name',
$name);
201 if (is_array(
$type)) {
203 $part->setAttribute($key,
$value);
206 $part->setAttribute(
'type',
$type);
212 $this->_wsdl->appendChild(
$message);
225 $portType = $this->_dom->createElement(
'portType');
226 $portType->setAttribute(
'name',
$name);
227 $this->_wsdl->appendChild($portType);
244 $operation = $this->_dom->createElement(
'operation');
245 $operation->setAttribute(
'name',
$name);
247 if (is_string($input) && (strlen(trim($input)) >= 1)) {
248 $node = $this->_dom->createElement(
'input');
249 $node->setAttribute(
'message', $input);
250 $operation->appendChild($node);
253 $node= $this->_dom->createElement(
'output');
254 $node->setAttribute(
'message',
$output);
255 $operation->appendChild($node);
257 if (is_string($fault) && (strlen(trim($fault)) >= 1)) {
258 $node = $this->_dom->createElement(
'fault');
259 $node->setAttribute(
'message', $fault);
260 $operation->appendChild($node);
263 $portType->appendChild($operation);
277 $binding = $this->_dom->createElement(
'binding');
278 $binding->setAttribute(
'name',
$name);
279 $binding->setAttribute(
'type', $portType);
281 $this->_wsdl->appendChild($binding);
297 $operation = $this->_dom->createElement(
'operation');
298 $operation->setAttribute(
'name',
$name);
300 if (is_array($input)) {
301 $node = $this->_dom->createElement(
'input');
302 $soap_node = $this->_dom->createElement(
'soap:body');
306 $node->appendChild($soap_node);
307 $operation->appendChild($node);
311 $node = $this->_dom->createElement(
'output');
312 $soap_node = $this->_dom->createElement(
'soap:body');
316 $node->appendChild($soap_node);
317 $operation->appendChild($node);
320 if (is_array($fault)) {
321 $node = $this->_dom->createElement(
'fault');
327 if (isset($fault[
'name'])) {
328 $node->setAttribute(
'name', $fault[
'name']);
331 $soap_node = $this->_dom->createElement(
'soap:fault');
335 $node->appendChild($soap_node);
336 $operation->appendChild($node);
339 $binding->appendChild($operation);
352 public function addSoapBinding($binding, $style =
'document', $transport =
'http://schemas.xmlsoap.org/soap/http')
354 $soap_binding = $this->_dom->createElement(
'soap:binding');
355 $soap_binding->setAttribute(
'style', $style);
356 $soap_binding->setAttribute(
'transport', $transport);
358 $binding->appendChild($soap_binding);
360 return $soap_binding;
372 if ($soap_action instanceof Zend_Uri_Http) {
373 $soap_action = $soap_action->getUri();
375 $soap_operation = $this->_dom->createElement(
'soap:operation');
376 $soap_operation->setAttribute(
'soapAction', $soap_action);
378 $binding->insertBefore($soap_operation, $binding->firstChild);
380 return $soap_operation;
394 if ($location instanceof Zend_Uri_Http) {
395 $location = $location->getUri();
397 $service = $this->_dom->createElement(
'service');
400 $port = $this->_dom->createElement(
'port');
401 $port->setAttribute(
'name', $port_name);
402 $port->setAttribute(
'binding', $binding);
404 $soap_address = $this->_dom->createElement(
'soap:address');
405 $soap_address->setAttribute(
'location', $location);
407 $port->appendChild($soap_address);
410 $this->_wsdl->appendChild(
$service);
428 if ($input_node === $this) {
429 $node = $this->_dom->documentElement;
434 $doc = $this->_dom->createElement(
'documentation');
435 $doc_cdata = $this->_dom->createTextNode(str_replace(array(
"\r\n",
"\r"),
"\n", $documentation));
436 $doc->appendChild($doc_cdata);
438 if($node->hasChildNodes()) {
439 $node->insertBefore($doc, $node->firstChild);
441 $node->appendChild($doc);
454 if ($types instanceof DomDocument) {
455 $dom = $this->_dom->importNode($types->documentElement);
456 $this->_wsdl->appendChild($types->documentElement);
457 }
elseif ($types instanceof DomNode || $types instanceof DomElement || $types instanceof DomDocumentFragment ) {
458 $dom = $this->_dom->importNode($types);
459 $this->_wsdl->appendChild($dom);
471 if(!in_array(
$type, $this->_includedTypes)) {
472 $this->_includedTypes[] =
$type;
484 return $this->_includedTypes;
494 if($this->_schema ==
null) {
498 return $this->_schema;
508 return $this->_dom->saveXML();
526 public function dump($filename =
false)
544 switch (strtolower(
$type)) {
559 return 'xsd:boolean';
561 return 'soap-enc:Array';
565 return 'xsd:anyType';
581 if ($this->_schema ===
null) {
582 $this->_schema = $this->_dom->createElement(
'xsd:schema');
583 $this->_schema->setAttribute(
'targetNamespace', $this->_uri);
584 $types = $this->_dom->createElement(
'types');
585 $types->appendChild($this->_schema);
586 $this->_wsdl->appendChild($types);
605 $strategy->setContext($this);
607 return $strategy->addComplexType(
$type);
616 private function _parseElement(
$element)
619 #require_once "Zend/Soap/Wsdl/Exception.php"; 623 $elementXml = $this->_dom->createElement(
'xsd:element');
625 if (in_array($key, array(
'sequence',
'all',
'choice'))) {
627 $complexType = $this->_dom->createElement(
'xsd:complexType');
629 $container = $this->_dom->createElement(
'xsd:' . $key);
630 foreach (
$value as $subelement) {
631 $subelementXml = $this->_parseElement($subelement);
632 $container->appendChild($subelementXml);
634 $complexType->appendChild($container);
636 $elementXml->appendChild($complexType);
639 $elementXml->setAttribute($key,
$value);
666 $elementXml = $this->_parseElement(
$element);
667 $schema->appendChild($elementXml);
addService($name, $port_name, $binding, $location)
elseif(isset( $params[ 'redirect_parent']))
__construct($name, $uri, $strategy=true)
static scan($xml, DOMDocument $dom=null)
addSoapOperation($binding, $soap_action)
addBindingOperation($binding, $name, $input=false, $output=false, $fault=false)
addSoapBinding($binding, $style='document', $transport='http://schemas.xmlsoap.org/soap/http')
addDocumentation($input_node, $documentation)
addPortOperation($portType, $name, $input=false, $output=false, $fault=false)
addBinding($name, $portType)
setComplexTypeStrategy($strategy)
addMessage($name, $parts)
if(!isset($_GET['name'])) $name