Value.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more |
  17. // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: Value.php,v 1.35 2003/04/11 05:32:17 shane Exp $
  21. //
  22. require_once 'SOAP/Base.php';
  23. /**
  24. * SOAP::Value
  25. * this class converts values between PHP and SOAP
  26. *
  27. * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4
  28. *
  29. * @access public
  30. * @version $Id: Value.php,v 1.35 2003/04/11 05:32:17 shane Exp $
  31. * @package SOAP::Client
  32. * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
  33. * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
  34. */
  35. class SOAP_Value
  36. {
  37. /**
  38. *
  39. *
  40. * @var string
  41. */
  42. var $value = NULL;
  43. /**
  44. *
  45. * @var string
  46. */
  47. var $name = '';
  48. /**
  49. *
  50. * @var string
  51. */
  52. var $type = '';
  53. /**
  54. * Namespace
  55. *
  56. * @var string
  57. */
  58. var $namespace = '';
  59. var $type_namespace = '';
  60. var $attributes = array();
  61. /**
  62. *
  63. * @var string
  64. */
  65. var $arrayType = '';
  66. var $options = array();
  67. var $nqn;
  68. var $tqn;
  69. /**
  70. *
  71. *
  72. * @param string name of the soap-value {namespace}name
  73. * @param mixed soap value {namespace}type, if not set an automatic
  74. * @param mixed value to set
  75. */
  76. function SOAP_Value($name = '', $type = false, $value=NULL, $attributes = array())
  77. {
  78. // detect type if not passed
  79. $this->nqn =& new QName($name);
  80. $this->name = $this->nqn->name;
  81. $this->namespace = $this->nqn->namespace;
  82. $this->tqn =& new QName($type);
  83. $this->type = $this->tqn->name;
  84. $this->type_prefix = $this->tqn->ns;
  85. $this->type_namespace = $this->tqn->namespace;
  86. $this->value =& $value;
  87. $this->attributes = $attributes;
  88. }
  89. /**
  90. * Serialize
  91. *
  92. * @return string xml representation
  93. */
  94. function &serialize(&$serializer)
  95. {
  96. return $serializer->_serializeValue($this->value, $this->name, $this->type, $this->namespace, $this->type_namespace, $this->options, $this->attributes, $this->arrayType);
  97. }
  98. }
  99. /**
  100. * SOAP::Header
  101. * this class converts values between PHP and SOAP
  102. * it is a simple wrapper around SOAP_Value, adding support for
  103. * soap actor and mustunderstand parameters
  104. *
  105. * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4
  106. *
  107. * @access public
  108. * @version $Id: Value.php,v 1.35 2003/04/11 05:32:17 shane Exp $
  109. * @package SOAP::Header
  110. * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
  111. * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
  112. */
  113. class SOAP_Header extends SOAP_Value
  114. {
  115. /**
  116. * Constructor
  117. *
  118. * @param string name of the soap-value <value_name>
  119. * @param mixed soap header value
  120. * @param string namespace
  121. * @param int mustunderstand (zero or one)
  122. * @param string actor
  123. */
  124. function SOAP_Header($name = '', $type, $value,
  125. $mustunderstand = 0,
  126. $actor = 'http://schemas.xmlsoap.org/soap/actor/next')
  127. {
  128. parent::SOAP_Value($name, $type, $value);
  129. $this->attributes['SOAP-ENV:actor'] = $actor;
  130. $this->attributes['SOAP-ENV:mustUnderstand'] = (int)$mustunderstand;
  131. }
  132. }
  133. /**
  134. * SOAP::Attachment
  135. * this class converts values between PHP and SOAP
  136. * it handles Mime attachements per W3C Note on Soap Attachements at
  137. * http://www.w3.org/TR/SOAP-attachments
  138. *
  139. *
  140. * @access public
  141. * @package SOAP::Attachment
  142. * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
  143. */
  144. class SOAP_Attachment extends SOAP_Value
  145. {
  146. /**
  147. * Constructor
  148. *
  149. * @param string name of the soap-value <value_name>
  150. * @param mixed soap header value
  151. * @param string namespace
  152. */
  153. function SOAP_Attachment($name = '', $type = 'application/octet-stream',
  154. $filename, $file=NULL)
  155. {
  156. global $SOAP_options;
  157. if (!isset($SOAP_options['Mime'])) {
  158. return PEAR::raiseError('Mail_mime is not installed, unable to support SOAP Attachements');
  159. }
  160. parent::SOAP_Value($name, NULL, NULL);
  161. $filedata = ($file === NULL) ? $this->_file2str($filename) : $file;
  162. $filename = basename($filename);
  163. if (PEAR::isError($filedata)) {
  164. return $filedata;
  165. }
  166. $cid = md5(uniqid(time()));
  167. $this->attributes['href'] = 'cid:'.$cid;
  168. $this->options['attachment'] = array(
  169. 'body' => $filedata,
  170. 'disposition' => $filename,
  171. 'content_type' => $type,
  172. 'encoding' => 'base64',
  173. 'cid' => $cid
  174. );
  175. }
  176. /*
  177. * Returns the contents of the given file name as string
  178. * @param string $file_name
  179. * @return string
  180. * @acces private
  181. */
  182. function & _file2str($file_name)
  183. {
  184. if (!is_readable($file_name)) {
  185. return PEAR::raiseError('File is not readable ' . $file_name);
  186. }
  187. if (!$fd = fopen($file_name, 'rb')) {
  188. return PEAR::raiseError('Could not open ' . $file_name);
  189. }
  190. $cont = fread($fd, filesize($file_name));
  191. fclose($fd);
  192. return $cont;
  193. }
  194. }
  195. ?>