SOAP
[ class tree: SOAP ] [ index: SOAP ] [ all elements ]

Source for file Value.php

Documentation is available at Value.php

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

Documentation generated on Mon, 11 Mar 2019 13:59:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.