Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Soap_Wsdl Class Reference

Public Member Functions

 __construct ($name, $uri, $strategy=true)
 
 setUri ($uri)
 
 setComplexTypeStrategy ($strategy)
 
 getComplexTypeStrategy ()
 
 addMessage ($name, $parts)
 
 addPortType ($name)
 
 addPortOperation ($portType, $name, $input=false, $output=false, $fault=false)
 
 addBinding ($name, $portType)
 
 addBindingOperation ($binding, $name, $input=false, $output=false, $fault=false)
 
 addSoapBinding ($binding, $style='document', $transport='http://schemas.xmlsoap.org/soap/http')
 
 addSoapOperation ($binding, $soap_action)
 
 addService ($name, $port_name, $binding, $location)
 
 addDocumentation ($input_node, $documentation)
 
 addTypes ($types)
 
 addType ($type)
 
 getTypes ()
 
 getSchema ()
 
 toXML ()
 
 toDomDocument ()
 
 dump ($filename=false)
 
 getType ($type)
 
 addSchemaTypeSection ()
 
 addComplexType ($type)
 
 addElement ($element)
 

Protected Attributes

 $_strategy = null
 

Detailed Description

Definition at line 41 of file Wsdl.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $name,
  $uri,
  $strategy = true 
)

Constructor

Parameters
string$nameName of the Web Service being Described
string$uriURI where the WSDL will be available
boolean | string | Zend_Soap_Wsdl_Strategy_Interface$strategy
Todo:
change DomDocument object creation from cparsing to construxting using API It also should authomatically escape $name and $uri values if necessary

Definition at line 83 of file Wsdl.php.

84  {
85  if ($uri instanceof Zend_Uri_Http) {
86  $uri = $uri->getUri();
87  }
88  $this->_uri = $uri;
89 
94  $wsdl = "<?xml version='1.0' ?>
95  <definitions name='$name' targetNamespace='$uri'
96  xmlns='http://schemas.xmlsoap.org/wsdl/'
97  xmlns:tns='$uri'
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();
103  if (!$this->_dom = Zend_Xml_Security::scan($wsdl, $this->_dom)) {
104  #require_once 'Zend/Server/Exception.php';
105  throw new Zend_Server_Exception('Unable to create DomDocument');
106  }
107  $this->_wsdl = $this->_dom->documentElement;
108 
109  $this->setComplexTypeStrategy($strategy);
110  }
static scan($xml, DOMDocument $dom=null)
Definition: Security.php:71
setComplexTypeStrategy($strategy)
Definition: Wsdl.php:144

Member Function Documentation

◆ addBinding()

addBinding (   $name,
  $portType 
)

Add a binding element to WSDL

Parameters
string$nameName of the Binding
string$typename of the portType to bind
Returns
object The new binding's XML_Tree_Node for use with addBindingOperation and addDocumentation

Definition at line 275 of file Wsdl.php.

276  {
277  $binding = $this->_dom->createElement('binding');
278  $binding->setAttribute('name', $name);
279  $binding->setAttribute('type', $portType);
280 
281  $this->_wsdl->appendChild($binding);
282 
283  return $binding;
284  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addBindingOperation()

addBindingOperation (   $binding,
  $name,
  $input = false,
  $output = false,
  $fault = false 
)

Add an operation to a binding element

Parameters
object$bindingA binding XML_Tree_Node returned by addBinding
array$inputAn array of attributes for the input element, allowed keys are: 'use', 'namespace', 'encodingStyle'. More Information
array$outputAn array of attributes for the output element, allowed keys are: 'use', 'namespace', 'encodingStyle'. More Information
array$faultAn array of attributes for the fault element, allowed keys are: 'name', 'use', 'namespace', 'encodingStyle'. More Information
Returns
object The new Operation's XML_Tree_Node for use with addSoapOperation and addDocumentation

Note. Do we really need name attribute to be also set at wsdl:fault node??? W3C standard doesn't mention it (http://www.w3.org/TR/wsdl#_soap:fault) But some real world WSDLs use it, so it may be required for compatibility reasons.

Definition at line 295 of file Wsdl.php.

296  {
297  $operation = $this->_dom->createElement('operation');
298  $operation->setAttribute('name', $name);
299 
300  if (is_array($input)) {
301  $node = $this->_dom->createElement('input');
302  $soap_node = $this->_dom->createElement('soap:body');
303  foreach ($input as $name => $value) {
304  $soap_node->setAttribute($name, $value);
305  }
306  $node->appendChild($soap_node);
307  $operation->appendChild($node);
308  }
309 
310  if (is_array($output)) {
311  $node = $this->_dom->createElement('output');
312  $soap_node = $this->_dom->createElement('soap:body');
313  foreach ($output as $name => $value) {
314  $soap_node->setAttribute($name, $value);
315  }
316  $node->appendChild($soap_node);
317  $operation->appendChild($node);
318  }
319 
320  if (is_array($fault)) {
321  $node = $this->_dom->createElement('fault');
327  if (isset($fault['name'])) {
328  $node->setAttribute('name', $fault['name']);
329  }
330 
331  $soap_node = $this->_dom->createElement('soap:fault');
332  foreach ($fault as $name => $value) {
333  $soap_node->setAttribute($name, $value);
334  }
335  $node->appendChild($soap_node);
336  $operation->appendChild($node);
337  }
338 
339  $binding->appendChild($operation);
340 
341  return $operation;
342  }
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addComplexType()

addComplexType (   $type)

Add a types data type definition

Parameters
string$typeName of the class to be specified
Returns
string XSD Type for the given PHP type

Definition at line 597 of file Wsdl.php.

598  {
599  if (in_array($type, $this->getTypes())) {
600  return "tns:$type";
601  }
602  $this->addSchemaTypeSection();
603 
604  $strategy = $this->getComplexTypeStrategy();
605  $strategy->setContext($this);
606  // delegates the detection of a complex type to the current strategy
607  return $strategy->addComplexType($type);
608  }
$type
Definition: item.phtml:13
addSchemaTypeSection()
Definition: Wsdl.php:579
getComplexTypeStrategy()
Definition: Wsdl.php:176

◆ addDocumentation()

addDocumentation (   $input_node,
  $documentation 
)

Add a documentation element to any element in the WSDL.

Note that the WSDL specification uses 'document', but the WSDL schema uses 'documentation' instead. The WS-I Basic Profile 1.1 recommends using 'documentation'.

Parameters
object$input_nodeAn XML_Tree_Node returned by another method to add the documentation to
string$documentationHuman readable documentation for the node
Returns
DOMElement The documentation element

Definition at line 426 of file Wsdl.php.

427  {
428  if ($input_node === $this) {
429  $node = $this->_dom->documentElement;
430  } else {
431  $node = $input_node;
432  }
433 
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);
437 
438  if($node->hasChildNodes()) {
439  $node->insertBefore($doc, $node->firstChild);
440  } else {
441  $node->appendChild($doc);
442  }
443 
444  return $doc;
445  }

◆ addElement()

addElement (   $element)

Add an xsd:element represented as an array to the schema.

Array keys represent attribute names and values their respective value. The 'sequence', 'all' and 'choice' keys must have an array of elements as their value, to add them to a nested complexType.

Example: array( 'name' => 'MyElement', 'sequence' => array( array('name' => 'myString', 'type' => 'string'), array('name' => 'myInteger', 'type' => 'int') ) ); Resulting XML: <xsd:element name="MyElement"><xsd:complexType><xsd:sequence> <xsd:element name="myString" type="string"/> <xsd:element name="myInteger" type="int"/> </xsd:sequence></xsd:complexType></xsd:element>

Parameters
array$elementan xsd:element represented as an array
Returns
string xsd:element for the given element array

Definition at line 663 of file Wsdl.php.

664  {
665  $schema = $this->getSchema();
666  $elementXml = $this->_parseElement($element);
667  $schema->appendChild($elementXml);
668  return 'tns:' . $element['name'];
669  }
$element
Definition: element.phtml:12

◆ addMessage()

addMessage (   $name,
  $parts 
)

Add a message element to the WSDL

Parameters
string$nameName for the message
array$partsAn array of parts The array is constructed like: 'name of part' => 'part xml schema data type' or 'name of part' => array('type' => 'part xml schema type') or 'name of part' => array('element' => 'part xml element name')
Returns
object The new message's XML_Tree_Node for use in addDocumentation

Definition at line 191 of file Wsdl.php.

192  {
193  $message = $this->_dom->createElement('message');
194 
195  $message->setAttribute('name', $name);
196 
197  if (sizeof($parts) > 0) {
198  foreach ($parts as $name => $type) {
199  $part = $this->_dom->createElement('part');
200  $part->setAttribute('name', $name);
201  if (is_array($type)) {
202  foreach ($type as $key => $value) {
203  $part->setAttribute($key, $value);
204  }
205  } else {
206  $part->setAttribute('type', $type);
207  }
208  $message->appendChild($part);
209  }
210  }
211 
212  $this->_wsdl->appendChild($message);
213 
214  return $message;
215  }
$message
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addPortOperation()

addPortOperation (   $portType,
  $name,
  $input = false,
  $output = false,
  $fault = false 
)

Add an operation element to a portType element

Parameters
object$portTypea portType XML_Tree_Node, from addPortType
string$nameOperation name
string$inputInput Message
string$outputOutput Message
string$faultFault Message
Returns
object The new operation's XML_Tree_Node for use in addDocumentation

Definition at line 242 of file Wsdl.php.

243  {
244  $operation = $this->_dom->createElement('operation');
245  $operation->setAttribute('name', $name);
246 
247  if (is_string($input) && (strlen(trim($input)) >= 1)) {
248  $node = $this->_dom->createElement('input');
249  $node->setAttribute('message', $input);
250  $operation->appendChild($node);
251  }
252  if (is_string($output) && (strlen(trim($output)) >= 1)) {
253  $node= $this->_dom->createElement('output');
254  $node->setAttribute('message', $output);
255  $operation->appendChild($node);
256  }
257  if (is_string($fault) && (strlen(trim($fault)) >= 1)) {
258  $node = $this->_dom->createElement('fault');
259  $node->setAttribute('message', $fault);
260  $operation->appendChild($node);
261  }
262 
263  $portType->appendChild($operation);
264 
265  return $operation;
266  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addPortType()

addPortType (   $name)

Add a portType element to the WSDL

Parameters
string$nameportType element's name
Returns
object The new portType's XML_Tree_Node for use in addPortOperation and addDocumentation

Definition at line 223 of file Wsdl.php.

224  {
225  $portType = $this->_dom->createElement('portType');
226  $portType->setAttribute('name', $name);
227  $this->_wsdl->appendChild($portType);
228 
229  return $portType;
230  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addSchemaTypeSection()

addSchemaTypeSection ( )

This function makes sure a complex types section and schema additions are set.

Returns
Zend_Soap_Wsdl

Definition at line 579 of file Wsdl.php.

580  {
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);
587  }
588  return $this;
589  }

◆ addService()

addService (   $name,
  $port_name,
  $binding,
  $location 
)

Add a service element to the WSDL

Parameters
string$nameService Name
string$port_nameName of the port for the service
string$bindingBinding for the port
string$locationSOAP Address for the service
Returns
object The new service's XML_Tree_Node for use with addDocumentation

Definition at line 392 of file Wsdl.php.

393  {
394  if ($location instanceof Zend_Uri_Http) {
395  $location = $location->getUri();
396  }
397  $service = $this->_dom->createElement('service');
398  $service->setAttribute('name', $name);
399 
400  $port = $this->_dom->createElement('port');
401  $port->setAttribute('name', $port_name);
402  $port->setAttribute('binding', $binding);
403 
404  $soap_address = $this->_dom->createElement('soap:address');
405  $soap_address->setAttribute('location', $location);
406 
407  $port->appendChild($soap_address);
408  $service->appendChild($port);
409 
410  $this->_wsdl->appendChild($service);
411 
412  return $service;
413  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addSoapBinding()

addSoapBinding (   $binding,
  $style = 'document',
  $transport = 'http://schemas.xmlsoap.org/soap/http' 
)

Add a SOAP binding element to a Binding element

Parameters
object$bindingA binding XML_Tree_Node returned by addBinding
string$stylebinding style, possible values are "rpc" (the default) and "document"
string$transportTransport method (defaults to HTTP)
Returns
boolean

Definition at line 352 of file Wsdl.php.

352  ://schemas.xmlsoap.org/soap/http')
353  {
354  $soap_binding = $this->_dom->createElement('soap:binding');
355  $soap_binding->setAttribute('style', $style);
356  $soap_binding->setAttribute('transport', $transport);
357 
358  $binding->appendChild($soap_binding);
359 
360  return $soap_binding;
361  }

◆ addSoapOperation()

addSoapOperation (   $binding,
  $soap_action 
)

Add a SOAP operation to an operation element

Parameters
object$operationAn operation XML_Tree_Node returned by addBindingOperation
string$soap_actionSOAP Action
Returns
boolean

Definition at line 370 of file Wsdl.php.

371  {
372  if ($soap_action instanceof Zend_Uri_Http) {
373  $soap_action = $soap_action->getUri();
374  }
375  $soap_operation = $this->_dom->createElement('soap:operation');
376  $soap_operation->setAttribute('soapAction', $soap_action);
377 
378  $binding->insertBefore($soap_operation, $binding->firstChild);
379 
380  return $soap_operation;
381  }

◆ addType()

addType (   $type)

Add a complex type name that is part of this WSDL and can be used in signatures.

Parameters
string$type
Returns
Zend_Soap_Wsdl

Definition at line 469 of file Wsdl.php.

470  {
471  if(!in_array($type, $this->_includedTypes)) {
472  $this->_includedTypes[] = $type;
473  }
474  return $this;
475  }
$type
Definition: item.phtml:13

◆ addTypes()

addTypes (   $types)

Add WSDL Types element

Parameters
object$typesA DomDocument|DomNode|DomElement|DomDocumentFragment with all the XML Schema types defined in it

Definition at line 452 of file Wsdl.php.

453  {
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);
460  }
461  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ dump()

dump (   $filename = false)

Echo the WSDL as XML

Returns
boolean

Definition at line 526 of file Wsdl.php.

527  {
528  if (!$filename) {
529  echo $this->toXML();
530  return true;
531  } else {
532  return file_put_contents($filename, $this->toXML());
533  }
534  }

◆ getComplexTypeStrategy()

getComplexTypeStrategy ( )

Get the current complex type strategy

Returns
Zend_Soap_Wsdl_Strategy_Interface

Definition at line 176 of file Wsdl.php.

177  {
178  return $this->_strategy;
179  }

◆ getSchema()

getSchema ( )

Return the Schema node of the WSDL

Returns
DOMElement

Definition at line 492 of file Wsdl.php.

493  {
494  if($this->_schema == null) {
495  $this->addSchemaTypeSection();
496  }
497 
498  return $this->_schema;
499  }
addSchemaTypeSection()
Definition: Wsdl.php:579

◆ getType()

getType (   $type)

Returns an XSD Type for the given PHP type

Parameters
string$typePHP Type to get the XSD type for
Returns
string

Definition at line 542 of file Wsdl.php.

543  {
544  switch (strtolower($type)) {
545  case 'string':
546  case 'str':
547  return 'xsd:string';
548  case 'long':
549  return 'xsd:long';
550  case 'int':
551  case 'integer':
552  return 'xsd:int';
553  case 'float':
554  return 'xsd:float';
555  case 'double':
556  return 'xsd:double';
557  case 'boolean':
558  case 'bool':
559  return 'xsd:boolean';
560  case 'array':
561  return 'soap-enc:Array';
562  case 'object':
563  return 'xsd:struct';
564  case 'mixed':
565  return 'xsd:anyType';
566  case 'void':
567  return '';
568  default:
569  // delegate retrieval of complex type to current strategy
570  return $this->addComplexType($type);
571  }
572  }
addComplexType($type)
Definition: Wsdl.php:597
$type
Definition: item.phtml:13

◆ getTypes()

getTypes ( )

Return an array of all currently included complex types

Returns
array

Definition at line 482 of file Wsdl.php.

483  {
484  return $this->_includedTypes;
485  }

◆ setComplexTypeStrategy()

setComplexTypeStrategy (   $strategy)

Set a strategy for complex type detection and handling

Todo:
Boolean is for backwards compability with extractComplexType object var. Remove it in later versions.
Parameters
boolean | string | Zend_Soap_Wsdl_Strategy_Interface$strategy
Returns
Zend_Soap_Wsdl

Definition at line 144 of file Wsdl.php.

145  {
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";
151  $strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
152  } else if(is_string($strategy)) {
153  if(class_exists($strategy)) {
154  $strategy = new $strategy();
155  } else {
156  #require_once "Zend/Soap/Wsdl/Exception.php";
157  throw new Zend_Soap_Wsdl_Exception(
158  sprintf("Strategy with name '%s does not exist.", $strategy
159  ));
160  }
161  }
162 
163  if(!($strategy instanceof Zend_Soap_Wsdl_Strategy_Interface)) {
164  #require_once "Zend/Soap/Wsdl/Exception.php";
165  throw new Zend_Soap_Wsdl_Exception("Set a strategy that is not of type 'Zend_Soap_Wsdl_Strategy_Interface'");
166  }
167  $this->_strategy = $strategy;
168  return $this;
169  }

◆ setUri()

setUri (   $uri)

Set a new uri for this WSDL

Parameters
string | Zend_Uri_Http$uri
Returns
Zend_Server_Wsdl

Definition at line 118 of file Wsdl.php.

119  {
120  if ($uri instanceof Zend_Uri_Http) {
121  $uri = $uri->getUri();
122  }
123  $oldUri = $this->_uri;
124  $this->_uri = $uri;
125 
126  if($this->_dom !== null) {
127  // @todo: This is the worst hack ever, but its needed due to design and non BC issues of WSDL generation
128  $xml = $this->_dom->saveXML();
129  $xml = str_replace($oldUri, $uri, $xml);
130  $this->_dom = new DOMDocument();
131  $this->_dom = Zend_Xml_Security::scan($xml, $this->_dom);
132  }
133 
134  return $this;
135  }
static scan($xml, DOMDocument $dom=null)
Definition: Security.php:71

◆ toDomDocument()

toDomDocument ( )

Return DOM Document

Returns
object DomDocum ent

Definition at line 516 of file Wsdl.php.

517  {
518  return $this->_dom;
519  }

◆ toXML()

toXML ( )

Return the WSDL as XML

Returns
string WSDL as XML

Definition at line 506 of file Wsdl.php.

507  {
508  return $this->_dom->saveXML();
509  }

Field Documentation

◆ $_strategy

$_strategy = null
protected

Strategy for detection of complex types

Definition at line 73 of file Wsdl.php.


The documentation for this class was generated from the following file: