Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Generator Class Reference
Inheritance diagram for Generator:
AbstractSchemaGenerator

Public Member Functions

 __construct (\Magento\Webapi\Model\Cache\Type\Webapi $cache, \Magento\Framework\Reflection\TypeProcessor $typeProcessor, \Magento\Framework\Webapi\CustomAttribute\ServiceTypeListInterface $serviceTypeList, \Magento\Webapi\Model\ServiceMetadata $serviceMetadata, Authorization $authorization, WsdlFactory $wsdlFactory)
 
 getPortTypeName ($serviceName)
 
 getBindingName ($serviceName)
 
 getPortName ($serviceName)
 
 getServiceName ($serviceName)
 
 getInputMessageName ($operationName)
 
 getOutputMessageName ($operationName)
 
- Public Member Functions inherited from AbstractSchemaGenerator
 __construct (Webapi $cache, \Magento\Framework\Reflection\TypeProcessor $typeProcessor, ServiceTypeListInterface $serviceTypeList, ServiceMetadata $serviceMetadata, Authorization $authorization, Json $serializer=null)
 
 getListOfServices ()
 
 generate ($requestedServices, $requestScheme, $requestHost, $endPointUrl)
 
 getElementComplexTypeName ($messageName)
 

Data Fields

const WSDL_NAME = 'MagentoWSDL'
 

Protected Member Functions

 generateSchema ($requestedServiceMetadata, $requestScheme, $requestHost, $endPointUrl)
 
 addCustomAttributeTypes ($wsdl)
 
 _createOperationInput (Wsdl $wsdl, $operationName, $methodData)
 
 _createOperationOutput (Wsdl $wsdl, $operationName, $methodData)
 
 _addGenericFaultComplexTypeNodes ($wsdl)
 
 getServiceMetadata ($serviceName)
 
 getAllowedServicesMetadata ($requestedServices)
 
- Protected Member Functions inherited from AbstractSchemaGenerator
 generateSchema ($requestedServiceMetadata, $requestScheme, $requestHost, $requestUri)
 
 getServiceMetadata ($serviceName)
 
 collectCallInfo ($requestedServiceMetadata)
 
 getAllowedServicesMetadata ($requestedServices)
 
 removeRestrictedRoutes (&$serviceMetadata)
 

Protected Attributes

 $_wsdlFactory
 
- Protected Attributes inherited from AbstractSchemaGenerator
 $cache
 
 $typeProcessor
 
 $serviceTypeList
 
 $serviceMetadata
 
 $authorization
 

Detailed Description

WSDL generator.

Definition at line 21 of file Generator.php.

Constructor & Destructor Documentation

◆ __construct()

Initialize dependencies.

Parameters
\Magento\Webapi\Model\Cache\Type\Webapi$cache
\Magento\Framework\Reflection\TypeProcessor$typeProcessor
\Magento\Framework\Webapi\CustomAttribute\ServiceTypeListInterface$serviceTypeList
\Magento\Webapi\Model\ServiceMetadata$serviceMetadata
Authorization$authorization
WsdlFactory$wsdlFactory

Definition at line 43 of file Generator.php.

Member Function Documentation

◆ _addGenericFaultComplexTypeNodes()

_addGenericFaultComplexTypeNodes (   $wsdl)
protected

Add WSDL elements related to generic SOAP fault, which are common for all operations: element, type and message.

Parameters
Wsdl$wsdl
Returns
string Default fault message name

Definition at line 284 of file Generator.php.

285  {
286  $faultMessageName = Fault::NODE_DETAIL_WRAPPER;
287  $complexTypeName = $this->getElementComplexTypeName($faultMessageName);
288  $wsdl->addElement(
289  [
290  'name' => $faultMessageName,
291  'type' => Wsdl::TYPES_NS . ':' . $complexTypeName,
292  ]
293  );
294  $faultParamsComplexType = Fault::NODE_DETAIL_PARAMETER;
295  $faultParamsData = [
296  'parameters' => [
298  'type' => 'string',
299  'required' => true,
300  'documentation' => '',
301  ],
303  'type' => 'string',
304  'required' => true,
305  'documentation' => '',
306  ],
307  ],
308  ];
309  $wrappedErrorComplexType = Fault::NODE_DETAIL_WRAPPED_ERROR;
310  $wrappedErrorData = [
311  'parameters' => [
313  'type' => 'string',
314  'required' => true,
315  'documentation' => '',
316  ],
318  'type' => "{$faultParamsComplexType}[]",
319  'required' => false,
320  'documentation' => 'Message parameters.',
321  ],
322  ],
323  ];
324  $genericFaultTypeData = [
325  'parameters' => [
327  'type' => 'string',
328  'required' => false,
329  'documentation' => 'Exception calls stack trace.',
330  ],
332  'type' => "{$faultParamsComplexType}[]",
333  'required' => false,
334  'documentation' => 'Additional exception parameters.',
335  ],
337  'type' => "{$wrappedErrorComplexType}[]",
338  'required' => false,
339  'documentation' => 'Additional wrapped errors.',
340  ],
341  ],
342  ];
343  $this->typeProcessor->setTypeData($faultParamsComplexType, $faultParamsData);
344  $this->typeProcessor->setTypeData($wrappedErrorComplexType, $wrappedErrorData);
345  $this->typeProcessor->setTypeData($complexTypeName, $genericFaultTypeData);
346  $wsdl->addComplexType($complexTypeName);
347  $wsdl->addMessage(
348  $faultMessageName,
349  [
350  'messageParameters' => [
351  'element' => Wsdl::TYPES_NS . ':' . $faultMessageName,
352  ]
353  ]
354  );
355 
356  return Wsdl::TYPES_NS . ':' . $faultMessageName;
357  }
const NODE_DETAIL_WRAPPED_ERROR_PARAMETERS
Definition: Fault.php:34

◆ _createOperationInput()

_createOperationInput ( Wsdl  $wsdl,
  $operationName,
  $methodData 
)
protected

Create input message and corresponding element and complex types in WSDL.

Parameters
Wsdl$wsdl
string$operationName
array$methodData
Returns
string input message name

Definition at line 139 of file Generator.php.

140  {
141  $inputMessageName = $this->getInputMessageName($operationName);
142  $complexTypeName = $this->getElementComplexTypeName($inputMessageName);
143  $inputParameters = [];
144  $elementData = [
145  'name' => $inputMessageName,
146  'type' => Wsdl::TYPES_NS . ':' . $complexTypeName,
147  ];
148  if (isset($methodData['interface']['in']['parameters'])) {
149  $inputParameters = $methodData['interface']['in']['parameters'];
150  } else {
151  $elementData['nillable'] = 'true';
152  }
153  $wsdl->addElement($elementData);
154  $callInfo = [];
155  $callInfo['requiredInput']['yes']['calls'] = [$operationName];
156  $typeData = [
157  'documentation' => $methodData['documentation'],
158  'parameters' => $inputParameters,
159  'callInfo' => $callInfo,
160  ];
161  $this->typeProcessor->setTypeData($complexTypeName, $typeData);
162  $wsdl->addComplexType($complexTypeName);
163  $wsdl->addMessage(
164  $inputMessageName,
165  [
166  'messageParameters' => [
167  'element' => Wsdl::TYPES_NS . ':' . $inputMessageName,
168  ]
169  ]
170  );
171  return Wsdl::TYPES_NS . ':' . $inputMessageName;
172  }

◆ _createOperationOutput()

_createOperationOutput ( Wsdl  $wsdl,
  $operationName,
  $methodData 
)
protected

Create output message and corresponding element and complex types in WSDL.

Parameters
Wsdl$wsdl
string$operationName
array$methodData
Returns
string output message name

Definition at line 182 of file Generator.php.

183  {
184  $outputMessageName = $this->getOutputMessageName($operationName);
185  $complexTypeName = $this->getElementComplexTypeName($outputMessageName);
186  $wsdl->addElement(
187  [
188  'name' => $outputMessageName,
189  'type' => Wsdl::TYPES_NS . ':' . $complexTypeName,
190  ]
191  );
192  $callInfo = [];
193  $callInfo['returned']['always']['calls'] = [$operationName];
194  $typeData = [
195  'documentation' => sprintf('Response container for the %s call.', $operationName),
196  'parameters' => $methodData['interface']['out']['parameters'],
197  'callInfo' => $callInfo,
198  ];
199  $this->typeProcessor->setTypeData($complexTypeName, $typeData);
200  $wsdl->addComplexType($complexTypeName);
201  $wsdl->addMessage(
202  $outputMessageName,
203  [
204  'messageParameters' => [
205  'element' => Wsdl::TYPES_NS . ':' . $outputMessageName,
206  ]
207  ]
208  );
209  return Wsdl::TYPES_NS . ':' . $outputMessageName;
210  }

◆ addCustomAttributeTypes()

addCustomAttributeTypes (   $wsdl)
protected

Create and add WSDL Types for complex custom attribute classes

Parameters
\Magento\Webapi\Model\Soap\Wsdl$wsdl
Returns
\Magento\Webapi\Model\Soap\Wsdl

Definition at line 122 of file Generator.php.

123  {
124  foreach ($this->serviceTypeList->getDataTypes() as $customAttributeClass) {
125  $typeName = $this->typeProcessor->register($customAttributeClass);
126  $wsdl->addComplexType($this->typeProcessor->getArrayItemType($typeName));
127  }
128  return $wsdl;
129  }

◆ generateSchema()

generateSchema (   $requestedServiceMetadata,
  $requestScheme,
  $requestHost,
  $endPointUrl 
)
protected

{}

Definition at line 64 of file Generator.php.

65  {
66  $wsdl = $this->_wsdlFactory->create(self::WSDL_NAME, $endPointUrl);
67  $wsdl->addSchemaTypeSection();
68  $faultMessageName = $this->_addGenericFaultComplexTypeNodes($wsdl);
69  $wsdl = $this->addCustomAttributeTypes($wsdl);
70 
71  foreach ($requestedServiceMetadata as $serviceClass => &$serviceData) {
72  $portTypeName = $this->getPortTypeName($serviceClass);
73  $bindingName = $this->getBindingName($serviceClass);
74  $portType = $wsdl->addPortType($portTypeName);
75  $binding = $wsdl->addBinding($bindingName, Wsdl::TYPES_NS . ':' . $portTypeName);
76  $wsdl->addSoapBinding($binding, 'document', 'http://schemas.xmlsoap.org/soap/http', SOAP_1_2);
77  $portName = $this->getPortName($serviceClass);
78  $serviceName = $this->getServiceName($serviceClass);
79  $wsdl->addService($serviceName, $portName, Wsdl::TYPES_NS . ':' . $bindingName, $endPointUrl, SOAP_1_2);
80 
81  foreach ($serviceData[ServiceMetadata::KEY_SERVICE_METHODS] as $methodName => $methodData) {
82  $operationName = $this->typeProcessor->getOperationName($serviceClass, $methodName);
83  $bindingDataPrototype = ['use' => 'literal'];
84  $inputBinding = $bindingDataPrototype;
85  $inputMessageName = $this->_createOperationInput($wsdl, $operationName, $methodData);
86 
87  $outputMessageName = false;
88  $outputBinding = false;
89  if (isset($methodData['interface']['out']['parameters'])) {
90  $outputBinding = $bindingDataPrototype;
91  $outputMessageName = $this->_createOperationOutput($wsdl, $operationName, $methodData);
92  }
93  $faultBinding = ['name' => Fault::NODE_DETAIL_WRAPPER];
94 
95  $wsdl->addPortOperation(
96  $portType,
97  $operationName,
98  $inputMessageName,
99  $outputMessageName,
100  ['message' => $faultMessageName, 'name' => Fault::NODE_DETAIL_WRAPPER]
101  );
102  $bindingOperation = $wsdl->addBindingOperation(
103  $binding,
104  $operationName,
105  $inputBinding,
106  $outputBinding,
107  $faultBinding,
108  SOAP_1_2
109  );
110  $wsdl->addSoapOperation($bindingOperation, $operationName, SOAP_1_2);
111  }
112  }
113  return $wsdl->toXML();
114  }
_createOperationInput(Wsdl $wsdl, $operationName, $methodData)
Definition: Generator.php:139
_createOperationOutput(Wsdl $wsdl, $operationName, $methodData)
Definition: Generator.php:182

◆ getAllowedServicesMetadata()

getAllowedServicesMetadata (   $requestedServices)
protected

{}

Definition at line 373 of file Generator.php.

374  {
375  $allowedServicesMetadata = parent::getAllowedServicesMetadata($requestedServices);
376  if (!$allowedServicesMetadata) {
377  throw new AuthorizationException(
378  __(
379  "The consumer isn't authorized to access %resources.",
380  ['resources' => implode(', ', $requestedServices)]
381  )
382  );
383  }
384  return $allowedServicesMetadata;
385  }
__()
Definition: __.php:13

◆ getBindingName()

getBindingName (   $serviceName)

Get name for service binding node.

Parameters
string$serviceName
Returns
string

Definition at line 229 of file Generator.php.

230  {
231  return $serviceName . 'Binding';
232  }

◆ getInputMessageName()

getInputMessageName (   $operationName)

Get input message node name for operation.

Parameters
string$operationName
Returns
string

Definition at line 262 of file Generator.php.

263  {
264  return $operationName . 'Request';
265  }

◆ getOutputMessageName()

getOutputMessageName (   $operationName)

Get output message node name for operation.

Parameters
string$operationName
Returns
string

Definition at line 273 of file Generator.php.

274  {
275  return $operationName . 'Response';
276  }

◆ getPortName()

getPortName (   $serviceName)

Get name for service port node.

Parameters
string$serviceName
Returns
string

Definition at line 240 of file Generator.php.

241  {
242  return $serviceName . 'Port';
243  }

◆ getPortTypeName()

getPortTypeName (   $serviceName)

Get name for service portType node.

Parameters
string$serviceName
Returns
string

Definition at line 218 of file Generator.php.

219  {
220  return $serviceName . 'PortType';
221  }

◆ getServiceMetadata()

getServiceMetadata (   $serviceName)
protected

Get service metadata

Parameters
string$serviceName
Returns
array

Definition at line 365 of file Generator.php.

366  {
367  return $this->serviceMetadata->getServiceMetadata($serviceName);
368  }

◆ getServiceName()

getServiceName (   $serviceName)

Get name for service service.

Parameters
string$serviceName
Returns
string

Definition at line 251 of file Generator.php.

252  {
253  return $serviceName . 'Service';
254  }

Field Documentation

◆ $_wsdlFactory

$_wsdlFactory
protected

Definition at line 31 of file Generator.php.

◆ WSDL_NAME

const WSDL_NAME = 'MagentoWSDL'

WSDL name

Definition at line 24 of file Generator.php.


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