PageRenderTime 57ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/PEAR/SOAP/Value.php

https://gitlab.com/LisovyiEvhenii/ismextensions
PHP | 288 lines | 94 code | 28 blank | 166 comment | 7 complexity | 026bce92aa9f922f0d8b410ff0f7ae3b MD5 | raw file
  1. <?php
  2. /**
  3. * This file contains the code for converting values between SOAP and PHP.
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * LICENSE: This source file is subject to version 2.02 of the PHP license,
  8. * that is bundled with this package in the file LICENSE, and is available at
  9. * through the world-wide-web at http://www.php.net/license/2_02.txt. If you
  10. * did not receive a copy of the PHP license and are unable to obtain it
  11. * through the world-wide-web, please send a note to license@php.net so we can
  12. * mail you a copy immediately.
  13. *
  14. * @category Web Services
  15. * @package SOAP
  16. * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
  17. * @author Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more
  18. * @author Chuck Hagenbuch <chuck@horde.org> Maintenance
  19. * @author Jan Schneider <jan@horde.org> Maintenance
  20. * @copyright 2003-2007 The PHP Group
  21. * @license http://www.php.net/license/2_02.txt PHP License 2.02
  22. * @link http://pear.php.net/package/SOAP
  23. */
  24. require_once 'SOAP/Base.php';
  25. /**
  26. * SOAP::Value
  27. *
  28. * This class converts values between PHP and SOAP.
  29. *
  30. * Originally based on SOAPx4 by Dietrich Ayala
  31. * http://dietrich.ganx4.com/soapx4
  32. *
  33. * @access public
  34. * @package SOAP
  35. * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
  36. * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
  37. */
  38. class SOAP_Value
  39. {
  40. /**
  41. * The actual value.
  42. *
  43. * @var mixed
  44. */
  45. var $value = null;
  46. /**
  47. * QName instance representing the value name.
  48. *
  49. * @var QName
  50. */
  51. var $nqn;
  52. /**
  53. * The value name, without namespace information.
  54. *
  55. * @var string
  56. */
  57. var $name = '';
  58. /**
  59. * The namespace of the value name.
  60. *
  61. * @var string
  62. */
  63. var $namespace = '';
  64. /**
  65. * QName instance representing the value type.
  66. *
  67. * @var QName
  68. */
  69. var $tqn;
  70. /**
  71. * The value type, without namespace information.
  72. *
  73. * @var string
  74. */
  75. var $type = '';
  76. /**
  77. * The namespace of the value type.
  78. *
  79. * @var string
  80. */
  81. var $type_namespace = '';
  82. /**
  83. * The type of the array elements, if this value is an array.
  84. *
  85. * @var string
  86. */
  87. var $arrayType = '';
  88. /**
  89. * A hash of additional attributes.
  90. *
  91. * @see SOAP_Value()
  92. * @var array
  93. */
  94. var $attributes = array();
  95. /**
  96. * List of encoding and serialization options.
  97. *
  98. * @see SOAP_Value()
  99. * @var array
  100. */
  101. var $options = array();
  102. /**
  103. * Constructor.
  104. *
  105. * @param string $name Name of the SOAP value {namespace}name.
  106. * @param mixed $type SOAP value {namespace}type. Determined
  107. * automatically if not set.
  108. * @param mixed $value Value to set.
  109. * @param array $attributes A has of additional XML attributes to be
  110. * added to the serialized value.
  111. * @param array $options A list of encoding and serialization options:
  112. * - 'attachment': array with information about
  113. * the attachment
  114. * - 'soap_encoding': defines encoding for SOAP
  115. * message part of a MIME encoded SOAP request
  116. * (default: base64)
  117. * - 'keep_arrays_flat': use the tag name
  118. * multiple times for each element when
  119. * passing in an array in literal mode
  120. * - 'no_type_prefix': supress adding of the
  121. * namespace prefix
  122. */
  123. function SOAP_Value($name = '', $type = false, $value = null,
  124. $attributes = array(), $options = array())
  125. {
  126. $this->nqn = new QName($name);
  127. $this->name = $this->nqn->name;
  128. $this->namespace = $this->nqn->namespace;
  129. if ($type) {
  130. $this->tqn = new QName($type);
  131. $this->type = $this->tqn->name;
  132. $this->type_namespace = $this->tqn->namespace;
  133. }
  134. $this->value = $value;
  135. $this->attributes = $attributes;
  136. $this->options = $options;
  137. }
  138. /**
  139. * Serializes this value.
  140. *
  141. * @param SOAP_Base $serializer A SOAP_Base instance or subclass to
  142. * serialize with.
  143. *
  144. * @return string XML representation of $this.
  145. */
  146. function serialize(&$serializer)
  147. {
  148. return $serializer->_serializeValue($this->value,
  149. $this->nqn,
  150. $this->tqn,
  151. $this->options,
  152. $this->attributes,
  153. $this->arrayType);
  154. }
  155. }
  156. /**
  157. * This class converts values between PHP and SOAP. It is a simple wrapper
  158. * around SOAP_Value, adding support for SOAP actor and mustunderstand
  159. * parameters.
  160. *
  161. * Originally based on SOAPx4 by Dietrich Ayala
  162. * http://dietrich.ganx4.com/soapx4
  163. *
  164. * @access public
  165. * @package SOAP
  166. * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
  167. * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
  168. */
  169. class SOAP_Header extends SOAP_Value
  170. {
  171. /**
  172. * Constructor
  173. *
  174. * @param string $name Name of the SOAP value {namespace}name.
  175. * @param mixed $type SOAP value {namespace}type. Determined
  176. * automatically if not set.
  177. * @param mixed $value Value to set
  178. * @param integer $mustunderstand Zero or one.
  179. * @param mixed $attributes Attributes.
  180. */
  181. function SOAP_Header($name = '', $type, $value, $mustunderstand = 0,
  182. $attributes = array())
  183. {
  184. if (!is_array($attributes)) {
  185. $actor = $attributes;
  186. $attributes = array();
  187. }
  188. parent::SOAP_Value($name, $type, $value, $attributes);
  189. if (isset($actor)) {
  190. $this->attributes[SOAP_BASE::SOAPENVPrefix().':actor'] = $actor;
  191. } elseif (!isset($this->attributes[SOAP_BASE::SOAPENVPrefix().':actor'])) {
  192. $this->attributes[SOAP_BASE::SOAPENVPrefix().':actor'] = 'http://schemas.xmlsoap.org/soap/actor/next';
  193. }
  194. $this->attributes[SOAP_BASE::SOAPENVPrefix().':mustUnderstand'] = (int)$mustunderstand;
  195. }
  196. }
  197. /**
  198. * This class handles MIME attachements per W3C's Note on Soap Attachements at
  199. * http://www.w3.org/TR/SOAP-attachments
  200. *
  201. * @access public
  202. * @package SOAP
  203. * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
  204. */
  205. class SOAP_Attachment extends SOAP_Value
  206. {
  207. /**
  208. * Constructor.
  209. *
  210. * @param string $name Name of the SOAP value <value_name>
  211. * @param string $type The attachment's MIME type.
  212. * @param string $filename The attachment's file name. Ignored if $file
  213. * is provide.
  214. * @param string $file The attachment data.
  215. * @param array $attributes Attributes.
  216. */
  217. function SOAP_Attachment($name = '', $type = 'application/octet-stream',
  218. $filename, $file = null, $attributes = null)
  219. {
  220. parent::SOAP_Value($name, null, null);
  221. $filedata = $file === null ? $this->_file2str($filename) : $file;
  222. $filename = basename($filename);
  223. if (PEAR::isError($filedata)) {
  224. $this->options['attachment'] = $filedata;
  225. return;
  226. }
  227. $cid = md5(uniqid(time()));
  228. $this->attributes = $attributes;
  229. $this->attributes['href'] = 'cid:' . $cid;
  230. $this->options['attachment'] = array('body' => $filedata,
  231. 'disposition' => $filename,
  232. 'content_type' => $type,
  233. 'encoding' => 'base64',
  234. 'cid' => $cid);
  235. }
  236. /**
  237. * Returns the contents of the given file name as string.
  238. *
  239. * @access private
  240. *
  241. * @param string $file_name The file location.
  242. *
  243. * @return string The file data or a PEAR_Error.
  244. */
  245. function _file2str($file_name)
  246. {
  247. if (!is_readable($file_name)) {
  248. return PEAR::raiseError('File is not readable: ' . $file_name);
  249. }
  250. if (function_exists('file_get_contents')) {
  251. return file_get_contents($file_name);
  252. }
  253. if (!$fd = fopen($file_name, 'rb')) {
  254. return PEAR::raiseError('Could not open ' . $file_name);
  255. }
  256. $cont = fread($fd, filesize($file_name));
  257. fclose($fd);
  258. return $cont;
  259. }
  260. }