/lib/Zend/Soap/Wsdl/Parser.php

https://github.com/webkulture/net.webkulture.www · PHP · 173 lines · 95 code · 24 blank · 54 comment · 22 complexity · 1de405c878383745968566f3ffb70eec MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Soap
  17. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Parser.php 9722 2008-06-18 12:36:35Z alexander $
  20. */
  21. require_once 'Zend/Soap/Wsdl/Parser/Result.php';
  22. /**
  23. * Zend_Soap_Wsdl_Parser
  24. *
  25. * @category Zend
  26. * @package Zend_Soap
  27. */
  28. class Zend_Soap_Wsdl_Parser {
  29. /**
  30. * @var SimpleXML object for the WSDL document being parsed
  31. */
  32. private static $xml;
  33. /**
  34. * Parse a WSDL document into a generic object
  35. *
  36. * @param string|file $wsdl The WSDL document or a filename for the WSDL document to parse
  37. * @return Zend_Soap_Wsdl_Parser_Result The contents of the WSDL file
  38. */
  39. public static function parse($wsdl)
  40. {
  41. if (strpos($wsdl, '<') === false) {
  42. $wsdl_result = new Zend_Soap_Wsdl_Parser_Result($wsdl);
  43. $wsdl = file_get_contents($wsdl);
  44. } else {
  45. $tmp = new tempnam(ini_get('upload_tmp_dir'), 'ZF_Temp_');
  46. file_put_contents($tmp, $wsdl);
  47. $wsdl_result = new Zend_Soap_Wsdl_Parser_Result($tmp);
  48. }
  49. self::$xml = simplexml_load_string($wsdl);
  50. /* This is done so that we have a known prefix to the WSDL elements
  51. for XPath queries */
  52. self::$xml['xmlns:zfwsdl'] = 'http://schemas.xmlsoap.org/wsdl/';
  53. self::$xml = simplexml_load_string(self::$xml->asXML());
  54. if (isset(self::$xml->documentation)) {
  55. $wsdl_result->documentation = trim(self::$xml->documentation);
  56. }
  57. if (!isset(self::$xml['name'])) {
  58. $wsdl_result->name = null;
  59. } else {
  60. $wsdl_result->name = (string) self::$xml['name'];
  61. }
  62. foreach (self::$xml->binding->operation as $operation) {
  63. $name = (string) $operation['name'];
  64. $wsdl_result->operations[$name] = array();
  65. $wsdl_result->operations[$name]['input'] = self::getOperationInputs($name);
  66. $wsdl_result->operations[$name]['output'] = self::getOperationOutput($name);
  67. $wsdl_result->operations[$name]['documentation'] = self::getDocs($name);
  68. }
  69. $wsdl_result->portType = (string) self::$xml->portType['name'];
  70. $wsdl_result->binding = (string) self::$xml->binding['name'];
  71. $wsdl_result->service['name'] = (string) self::$xml->service['name'];
  72. $wsdl_result->service['address'] = (string) self::$xml->service->port->children('http://schemas.xmlsoap.org/wsdl/soap/')->attributes();
  73. $wsdl_result->targetNamespace = (string) self::$xml['targetNamespace'];
  74. return $wsdl_result;
  75. }
  76. /**
  77. * Get Function arguments
  78. *
  79. * @param string $operation_name Name of the <operation> element to find
  80. * @return string
  81. */
  82. private static function getOperationInputs($operation_name)
  83. {
  84. $operation = self::$xml->xpath('/zfwsdl:definitions[1]/zfwsdl:portType/zfwsdl:operation[@name="' .$operation_name. '"]');
  85. if ($operation == null) {
  86. return '';
  87. }
  88. if (isset($operation[0]->input)) {
  89. $input_message_name = $operation[0]->input['message'];
  90. $input_message_name = explode(':', $input_message_name);
  91. $input_message_name = $input_message_name[1];
  92. $input_message = self::$xml->xpath('/zfwsdl:definitions[1]/zfwsdl:message[@name="' .$input_message_name. '"]');
  93. }
  94. if ($input_message != null) {
  95. foreach ($input_message[0]->part as $part) {
  96. $args[] = array(
  97. 'name' => (string) $part['name'],
  98. 'type' => (string) $part['type'],
  99. );
  100. }
  101. if (isset($args) && is_array($args)) {
  102. return $args;
  103. } else {
  104. return null;
  105. }
  106. } else {
  107. return null;
  108. }
  109. }
  110. /**
  111. * Get Function return variable
  112. *
  113. * @param string $operation_name Name of the <operation> element to find
  114. * @return string|false Returns variable name if found, or false
  115. */
  116. private static function getOperationOutput($operation_name)
  117. {
  118. $operation = self::$xml->xpath('/zfwsdl:definitions[1]/zfwsdl:portType/zfwsdl:operation[@name="' .$operation_name. '"]');
  119. if (isset($operation[0]->output)) {
  120. $output_message_name = $operation[0]->output['message'];
  121. $output_message_name = explode(':', $output_message_name);
  122. $output_message_name = $output_message_name[1];
  123. $output_message = self::$xml->xpath('/zfwsdl:definitions[1]/zfwsdl:message[@name="' .$output_message_name. '"]');
  124. }
  125. if ($output_message != null) {
  126. return array(
  127. 'name' => (string) $output_message[0]->part['name'],
  128. 'type' => (string) $output_message[0]->part['type']
  129. );
  130. } else {
  131. return null;
  132. }
  133. }
  134. /**
  135. * Get Function Documentation
  136. *
  137. * @param string $operation_name Name of the <operation> element to find
  138. * @return string
  139. */
  140. private static function getDocs($operation_name)
  141. {
  142. $portType = self::$xml->xpath('//zfwsdl:operation[@name="' .$operation_name. '"]/zfwsdl:documentation');
  143. if (isset($portType) && is_array($portType) && (sizeof($portType) >= 1)) {
  144. return trim((string) $portType[0]);
  145. } else {
  146. return null;
  147. }
  148. }
  149. }