public function dumpServiceDefinition(ServiceDefinition $definition, array $options = array()) { Assert::thatArgumentNotNull('definition', $definition); $options = array_merge(array('endpoint' => ''), $options); $this->definition = $definition; $wsdl = new Wsdl($definition->getName(), $definition->getNamespace()); $port = $wsdl->addPortType($this->getPortTypeName()); $binding = $wsdl->addBinding($this->getBindingName(), 'tns:' . $this->getPortTypeName()); $wsdl->addSoapBinding($binding, 'rpc'); $wsdl->addService($this->getServiceName(), $this->getPortName(), 'tns:' . $this->getBindingName(), $options['endpoint']); foreach ($definition->getMethods() as $method) { $requestParts = array(); $responseParts = array(); foreach ($method->getArguments() as $argument) { $requestParts[$argument->getName()] = $wsdl->getType($argument->getType()->getPhpType()); } if ($method->getReturn() !== null) { $responseParts['return'] = $wsdl->getType($method->getReturn()->getPhpType()); } $wsdl->addMessage($this->getRequestMessageName($method), $requestParts); $wsdl->addMessage($this->getResponseMessageName($method), $responseParts); $portOperation = $wsdl->addPortOperation($port, $method->getName(), 'tns:' . $this->getRequestMessageName($method), 'tns:' . $this->getResponseMessageName($method)); $portOperation->setAttribute('parameterOrder', implode(' ', array_keys($requestParts))); $bindingInput = array('parts' => implode(' ', array_keys($requestParts)), 'use' => 'literal', 'namespace' => $definition->getNamespace(), 'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'); $bindingOutput = array('parts' => implode(' ', array_keys($responseParts)), 'use' => 'literal', 'namespace' => $definition->getNamespace(), 'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'); $bindingOperation = $wsdl->addBindingOperation($binding, $method->getName(), $bindingInput, $bindingOutput); $wsdl->addSoapOperation($bindingOperation, $this->getSoapOperationName($method)); } $this->definition = null; $wsdl->toDomDocument()->formatOutput = true; return $wsdl->toXml(); }
/** * Proxy to WSDL toXml() function */ public function toXml() { if ($this->_wsdl !== null) { return $this->_wsdl->toXml(); } else { throw new Exception\RuntimeException('Cannot return autodiscovered contents, WSDL file has not been generated yet.'); } }
/** * @group ZF-5149 */ public function testArrayOfComplexNestedObjectsIsCoveredByStrategyAndAddsAllTypesRecursivly() { $return = $this->wsdl->addComplexType('\\ZendTest\\Soap\\TestAsset\\ComplexTypeA'); $wsdl = $this->wsdl->toXml(); $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ComplexTypeA">'), 'No definition of complex type A found.'); $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfComplexTypeB">'), 'No definition of complex type B array found.'); $this->assertEquals(1, substr_count($wsdl, 'wsdl:arrayType="tns:ComplexTypeB[]"'), 'No usage of Complex Type B array found.'); }
/** * @group ZF-5430 */ public function testMultipleSequenceDefinitionsOfSameTypeWillBeRecognizedOnceBySequenceStrategy() { $wsdl = new Wsdl("MyService", "http://localhost/MyService.php"); $wsdl->setComplexTypeStrategy(new Strategy\ArrayOfTypeSequence()); $wsdl->addComplexType("string[]"); $wsdl->addComplexType("int[]"); $wsdl->addComplexType("string[]"); $xml = $wsdl->toXml(); $this->assertEquals(1, substr_count($xml, "ArrayOfString"), "ArrayOfString should appear only once."); $this->assertEquals(1, substr_count($xml, "ArrayOfInt"), "ArrayOfInt should appear only once."); }