/**
  * @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.');
 }
Example #2
0
 /**
  * Return the ArrayOf or simple type name based on the singular xsdtype and the nesting level
  *
  * @param  string $singularType
  * @param  int    $level
  * @return string
  */
 protected function _getTypeBasedOnNestingLevel($singularType, $level)
 {
     if ($level == 0) {
         // This is not an Array anymore, return the xsd simple type
         return $this->getContext()->getType($singularType);
     } else {
         return 'tns:' . str_repeat('ArrayOf', $level) . ucfirst(Wsdl::translateType($singularType));
     }
 }
Example #3
0
 /**
  *
  *
  * @param \Zend\Soap\Wsdl $wsdl
  * @param null            $documentNamespace
  */
 public function bindWsdl(Wsdl $wsdl, $documentNamespace = null)
 {
     $this->dom = new \DOMDocument();
     $this->dom->formatOutput = true;
     $this->dom->preserveWhiteSpace = false;
     $this->dom->loadXML($wsdl->toXML());
     if (empty($documentNamespace)) {
         $documentNamespace = $this->defaultServiceUri;
     }
     $this->xpath = new \DOMXPath($this->dom);
     $this->xpath->registerNamespace('unittest', Wsdl::WSDL_NS_URI);
     $this->xpath->registerNamespace('tns', $documentNamespace);
     $this->xpath->registerNamespace('soap', Wsdl::SOAP_11_NS_URI);
     $this->xpath->registerNamespace('soap12', Wsdl::SOAP_12_NS_URI);
     $this->xpath->registerNamespace('xsd', Wsdl::XSD_NS_URI);
     $this->xpath->registerNamespace('soap-enc', Wsdl::SOAP_ENC_URI);
     $this->xpath->registerNamespace('wsdl', Wsdl::WSDL_NS_URI);
 }
Example #4
0
 /**
  * Returns an XSD Type for the given PHP type
  *
  * @param string $type PHP Type to get the XSD type for
  * @return string
  */
 public function getType($type)
 {
     if (!$this->_wsdl instanceof Wsdl) {
         /** @todo Exception throwing may be more correct */
         // WSDL is not defined yet, so we can't recognize type in context of current service
         return '';
     } else {
         return $this->_wsdl->getType($type);
     }
 }
Example #5
0
 /**
  * Add an operation to port type.
  *
  * @param DOMElement $portType
  * @param string $name Operation name
  * @param string|bool $input Input Message
  * @param string|bool $output Output Message
  * @param string|bool|array $fault Message name OR array('message' => ..., 'name' => ...)
  * @return object The new operation's XML_Tree_Node
  */
 public function addPortOperation($portType, $name, $input = false, $output = false, $fault = false)
 {
     $operation = parent::addPortOperation($portType, $name, $input, $output, false);
     if (is_array($fault)) {
         $isMessageValid = isset($fault['message']) && is_string($fault['message']) && strlen(trim($fault['message']));
         $isNameValid = isset($fault['name']) && is_string($fault['name']) && strlen(trim($fault['name']));
         if ($isNameValid && $isMessageValid) {
             $node = $this->toDomDocument()->createElement('fault');
             $node->setAttribute('name', $fault['name']);
             $node->setAttribute('message', $fault['message']);
             $operation->appendChild($node);
         }
     }
     return $operation;
 }
Example #6
0
 /**
  * @param \DOMElement $element
  */
 public function testDocumentNodes($element = null)
 {
     if (!$this->wsdl instanceof Wsdl) {
         return;
     }
     if (null === $element) {
         $element = $this->wsdl->toDomDocument()->documentElement;
     }
     /** @var $node \DOMElement */
     foreach ($element->childNodes as $node) {
         if (in_array($node->nodeType, array(XML_ELEMENT_NODE))) {
             $this->assertNotEmpty($node->namespaceURI, 'Document element: ' . $node->nodeName . ' has no valid namespace. Line: ' . $node->getLineNo());
             $this->testDocumentNodes($node);
         }
     }
 }
Example #7
0
 /**
  * Add a complex type by recursivly using all the class properties fetched via Reflection.
  *
  * @param  string $type Name of the class to be specified
  * @return string XSD Type for the given PHP type
  */
 public function addComplexType($type)
 {
     if (!class_exists($type)) {
         throw new Exception\InvalidArgumentException(sprintf('Cannot add a complex type %s that is not an object or where ' . 'class could not be found in \'DefaultComplexType\' strategy.', $type));
     }
     if (($soapType = $this->scanRegisteredTypes($type)) !== null) {
         return $soapType;
     }
     $dom = $this->getContext()->toDomDocument();
     $class = new \ReflectionClass($type);
     $soapTypeName = Soap\Wsdl::translateType($type);
     $soapType = 'tns:' . $soapTypeName;
     // Register type here to avoid recursion
     $this->getContext()->addType($type, $soapType);
     $defaultProperties = $class->getDefaultProperties();
     $defaultProperties = $class->getDefaultProperties();
     $complexType = $dom->createElement('xsd:complexType');
     $complexType->setAttribute('name', $soapTypeName);
     $all = $dom->createElement('xsd:all');
     foreach ($class->getProperties() as $property) {
         if ($property->isPublic() && preg_match_all('/@var\\s+([^\\s]+)/m', $property->getDocComment(), $matches)) {
             /**
              * @todo check if 'xsd:element' must be used here (it may not be compatible with using 'complexType'
              * node for describing other classes used as attribute types for current class
              */
             $element = $dom->createElement('xsd:element');
             $element->setAttribute('name', $propertyName = $property->getName());
             $element->setAttribute('type', $this->getContext()->getType(trim($matches[1][0])));
             // If the default value is null, then this property is nillable.
             if ($defaultProperties[$propertyName] === null) {
                 $element->setAttribute('nillable', 'true');
             }
             $all->appendChild($element);
         }
     }
     $complexType->appendChild($all);
     $this->getContext()->getSchema()->appendChild($complexType);
     return $soapType;
 }
 /**
  * Add an ArrayOfType based on the xsd:complexType syntax if type[] is detected in return value doc comment.
  *
  * @param string $singularType   e.g. '\MyNamespace\MyClassname'
  * @param string $type           e.g. '\MyNamespace\MyClassname[]'
  * @return string tns:xsd-type   e.g. 'tns:ArrayOfMyNamespace.MyClassname'
  */
 protected function _addArrayOfComplexType($singularType, $type)
 {
     if (($soapType = $this->scanRegisteredTypes($type)) !== null) {
         return $soapType;
     }
     $xsdComplexTypeName = 'ArrayOf' . Wsdl::translateType($singularType);
     $xsdComplexType = 'tns:' . $xsdComplexTypeName;
     // Register type here to avoid recursion
     $this->getContext()->addType($type, $xsdComplexType);
     // Process singular type using DefaultComplexType strategy
     parent::addComplexType($singularType);
     // Add array type structure to WSDL document
     $dom = $this->getContext()->toDomDocument();
     $complexType = $dom->createElement('xsd:complexType');
     $complexType->setAttribute('name', $xsdComplexTypeName);
     $complexContent = $dom->createElement('xsd:complexContent');
     $complexType->appendChild($complexContent);
     $xsdRestriction = $dom->createElement('xsd:restriction');
     $xsdRestriction->setAttribute('base', 'soap-enc:Array');
     $complexContent->appendChild($xsdRestriction);
     $xsdAttribute = $dom->createElement('xsd:attribute');
     $xsdAttribute->setAttribute('ref', 'soap-enc:arrayType');
     $xsdAttribute->setAttribute('wsdl:arrayType', 'tns:' . Wsdl::translateType($singularType) . '[]');
     $xsdRestriction->appendChild($xsdAttribute);
     $this->getContext()->getSchema()->appendChild($complexType);
     return $xsdComplexType;
 }
Example #9
0
 /**
  * @group ZF-5736
  */
 public function testHtmlAmpersandInUrlInSetUriIsEncodedCorrectly()
 {
     $wsdl = new Wsdl("MyService", "http://example.com");
     $wsdl->setUri(self::URI_WITH_EXPANDED_AMP);
     $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML());
 }
Example #10
0
 /**
  * Constructor.
  * Save URI for targetNamespace generation.
  *
  * @param string $name
  * @param string|Zend\Uri\Uri $uri
  * @param Mage_Webapi_Model_Soap_Wsdl_ComplexTypeStrategy_ConfigBased $strategy
  */
 public function __construct($name, $uri, Mage_Webapi_Model_Soap_Wsdl_ComplexTypeStrategy_ConfigBased $strategy)
 {
     $this->_uri = $uri;
     parent::__construct($name, $uri, $strategy);
 }
Example #11
0
 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();
 }
Example #12
0
 public function testGetComplexTypeBasedOnStrategiesStringNames()
 {
     $this->wsdl = new Wsdl($this->defaultServiceName, 'http://localhost/MyService.php', new Wsdl\ComplexTypeStrategy\DefaultComplexType());
     $this->assertEquals('tns:WsdlTestClass', $this->wsdl->getType('\\ZendTest\\Soap\\TestAsset\\WsdlTestClass'));
     $this->assertTrue($this->wsdl->getComplexTypeStrategy() instanceof Wsdl\ComplexTypeStrategy\DefaultComplexType);
     $wsdl2 = new Wsdl($this->defaultServiceName, $this->defaultServiceUri, new Wsdl\ComplexTypeStrategy\AnyType());
     $this->assertEquals('xsd:anyType', $wsdl2->getType('\\ZendTest\\Soap\\TestAsset\\WsdlTestClass'));
     $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof Wsdl\ComplexTypeStrategy\AnyType);
 }