• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

payment/bmf/lib/SOAP/class.ilBMFBase.php

Go to the documentation of this file.
00001 <?php
00002 //
00003 // +----------------------------------------------------------------------+
00004 // | PHP Version 4                                                        |
00005 // +----------------------------------------------------------------------+
00006 // | Copyright (c) 1997-2003 The PHP Group                                |
00007 // +----------------------------------------------------------------------+
00008 // | This source file is subject to version 2.02 of the PHP license,      |
00009 // | that is bundled with this package in the file LICENSE, and is        |
00010 // | available at through the world-wide-web at                           |
00011 // | http://www.php.net/license/2_02.txt.                                 |
00012 // | If you did not receive a copy of the PHP license and are unable to   |
00013 // | obtain it through the world-wide-web, please send a note to          |
00014 // | license@php.net so we can mail you a copy immediately.               |
00015 // +----------------------------------------------------------------------+
00016 // | Authors: Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more   |
00017 // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author         |
00018 // +----------------------------------------------------------------------+
00019 //
00020 // $Id: class.ilBMFBase.php 11401 2006-07-12 10:40:54Z jconze $
00021 //
00022 error_reporting(E_COMPILE_ERROR + E_ERROR + E_CORE_ERROR + E_USER_ERROR );
00023 
00024 /*
00025    SOAP_OBJECT_STRUCT makes pear::soap use objects for soap structures
00026    rather than arrays.  This has been done to provide a closer match to php-soap.
00027    If the old behaviour is needed, set to false.  The old behaviour is depricated.
00028 */
00029 $GLOBALS['SOAP_OBJECT_STRUCT'] = TRUE;
00030 /*
00031    SOAP_RAW_CONVERT makes pear::soap attempt to determine what SOAP type
00032    a php string COULD be.  This may result in slightly better interoperability when
00033    you are not using WSDL, and are being lazy and not using ilBMFValue to define
00034    types for your values.
00035 */
00036 $GLOBALS['SOAP_RAW_CONVERT'] = FALSE;
00037 
00038 require_once 'PEAR.php';
00039 #require_once dirname(__FILE__).'/class.ilBMFFault.php';
00040 require_once dirname(__FILE__).'/Type/class.ilBMFType_dateTime.php';
00041 require_once dirname(__FILE__).'/Type/class.ilBMFType_hexBinary.php';
00042 
00043 // optional features
00044 $GLOBALS['SOAP_options'] = array();
00045 
00046 @include_once 'Mail/mimePart.php';
00047 @include_once 'Mail/mimeDecode.php';
00048 if (class_exists('Mail_mimePart')) {
00049     $GLOBALS['SOAP_options']['Mime'] = 1;
00050     define('MAIL_MIMEPART_CRLF',"\r\n");
00051 }
00052 
00053 @include_once 'Net/DIME.php';
00054 if (class_exists('Net_DIME_Message')) {
00055     $GLOBALS['SOAP_options']['DIME'] = 1;
00056 }
00057 
00063 $GLOBALS['SOAP_DEBUG']=false;
00064 
00065 if (!function_exists('version_compare') ||
00066     version_compare(phpversion(), '4.1', '<')) {
00067     die("requires PHP 4.1 or higher\n");
00068 }
00069 if (version_compare(phpversion(), '4.1', '>=') &&
00070     version_compare(phpversion(), '4.2', '<')) {
00071     define('FLOAT', 'double');
00072 } else {
00073     define('FLOAT', 'float');
00074 }
00075 
00076 if (!defined('INF')) {
00077     define('INF',   1.8e307);
00078 }
00079 if (!defined('NAN')) {
00080     define('NAN',   0.0);
00081 }
00082 
00083 define('SOAP_LIBRARY_VERSION', '0.8.0RC4');
00084 define('SOAP_LIBRARY_NAME',    'PEAR-SOAP 0.8.0RC4-devel');
00085 
00086 // set schema version
00087 define('SOAP_XML_SCHEMA_VERSION',   'http://www.w3.org/2001/XMLSchema');
00088 define('SOAP_XML_SCHEMA_INSTANCE',  'http://www.w3.org/2001/XMLSchema-instance');
00089 define('SOAP_XML_SCHEMA_1999',      'http://www.w3.org/1999/XMLSchema');
00090 define('SOAP_SCHEMA',               'http://schemas.xmlsoap.org/wsdl/soap/');
00091 define('SOAP_SCHEMA_ENCODING',      'http://schemas.xmlsoap.org/soap/encoding/');
00092 define('SOAP_ENVELOP',              'http://schemas.xmlsoap.org/soap/envelope/');
00093 
00094 define('SCHEMA_DISCO',              'http://schemas.xmlsoap.org/disco/');
00095 define('SCHEMA_DISCO_SCL',          'http://schemas.xmlsoap.org/disco/scl/');
00096 
00097 define('SCHEMA_SOAP',               'http://schemas.xmlsoap.org/wsdl/soap/');
00098 define('SCHEMA_SOAP_HTTP',          'http://schemas.xmlsoap.org/soap/http');
00099 define('SCHEMA_WSDL_HTTP',          'http://schemas.xmlsoap.org/wsdl/http/');
00100 define('SCHEMA_MIME',               'http://schemas.xmlsoap.org/wsdl/mime/');
00101 define('SCHEMA_WSDL',               'http://schemas.xmlsoap.org/wsdl/');
00102 define('SCHEMA_DIME',               'http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/');
00103 define('SCHEMA_CONTENT',            'http://schemas.xmlsoap.org/ws/2002/04/content-type/');
00104 define('SCHEMA_REF',                'http://schemas.xmlsoap.org/ws/2002/04/reference/');
00105 
00106 //define('SOAP_DEFAULT_ENCODING',  'UTF-8');
00107 define('SOAP_DEFAULT_ENCODING',  'ISO-8859-1');
00108 
00109 if (!function_exists('is_a'))
00110 {
00111    function is_a(&$object, $class_name)
00112    {
00113        if (strtolower(get_class($object)) == $class_name) return TRUE;
00114        else return is_subclass_of($object, $class_name);
00115    }
00116 }
00117 
00118 if (!class_exists('stdClass')) {
00119     /* PHP5 doesn't define this? */
00120     class stdClass {
00121         function __constructor() {}
00122     };
00123 }
00124 
00125 class ilBMFBase_Object extends PEAR
00126 {
00133     var $_debug_flag = false;
00134 
00142     var $_debug_data = '';
00143 
00144     # supported encodings, limited by XML extension
00145     var $_encodings = array('ISO-8859-1','US-ASCII','UTF-8');
00151     var $_myfaultcode = '';
00152 
00158     var $fault = NULL;
00159 
00166     function ilBMFBase_Object($faultcode = 'Client')
00167     {
00168         $this->_myfaultcode = $faultcode;
00169         $this->_debug_flag = $GLOBALS['SOAP_DEBUG'];
00170         parent::PEAR('ilBMFFault');
00171     }
00172 
00190     function &_raiseSoapFault($str, $detail = '', $actorURI = '', $code = null, $mode = null, $options = null, $skipmsg = false)
00191     {
00192         # pass through previous faults
00193         $is_instance = isset($this);
00194         if (is_object($str)) {
00195             $fault =& $str;
00196         } else {
00197             if (!$code) $code = $is_instance?$this->_myfaultcode:'Client';
00198             $fault =& new ilBMFFault($str,
00199                                           $code,
00200                                           $actorURI,
00201                                           $detail,
00202                                           $mode,
00203                                           $options);
00204         }
00205         if ($is_instance) $this->fault =& $fault;
00206         return $fault;
00207     }
00208 
00209     function __isfault()
00210     {
00211         return $this->fault != NULL;
00212     }
00213 
00214     function &__getfault()
00215     {
00216         return $this->fault;
00217     }
00218 
00224     function _debug($string)
00225     {
00226         if ($this->_debug_flag) {
00227             $this->_debug_data .= get_class($this) . ': ' . preg_replace("/>/", ">\r\n", $string) . "\n";
00228         }
00229     }
00230 }
00231 
00241 class ilBMFBase extends ilBMFBase_Object
00242 {
00243     var $_XMLSchema = array('http://www.w3.org/2001/XMLSchema', 'http://www.w3.org/1999/XMLSchema');
00244     var $_XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
00245 
00246     // load types into typemap array
00247     var $_typemap = array(
00248         'http://www.w3.org/2001/XMLSchema' => array(
00249             'string' => 'string',
00250             'boolean' => 'boolean',
00251             'float' => FLOAT,
00252             'double' => FLOAT,
00253             'decimal' => 'double',
00254             'duration' => 'integer',
00255             'dateTime' => 'string',
00256             'time' => 'string',
00257             'date' => 'string',
00258             'gYearMonth' => 'integer',
00259             'gYear' => 'integer',
00260             'gMonthDay' => 'integer',
00261             'gDay' => 'integer',
00262             'gMonth' => 'integer',
00263             'hexBinary' => 'string',
00264             'base64Binary' => 'string',
00265             // derived datatypes
00266             'normalizedString' => 'string',
00267             'token' => 'string',
00268             'language' => 'string',
00269             'NMTOKEN' => 'string',
00270             'NMTOKENS' => 'string',
00271             'Name' => 'string',
00272             'NCName' => 'string',
00273             'ID' => 'string',
00274             'IDREF' => 'string',
00275             'IDREFS' => 'string',
00276             'ENTITY' => 'string',
00277             'ENTITIES' => 'string',
00278             'integer' => 'integer',
00279             'nonPositiveInteger' => 'integer',
00280             'negativeInteger' => 'integer',
00281             'long' => 'integer',
00282             'int' => 'integer',
00283             'short' => 'integer',
00284             'byte' => 'string',
00285             'nonNegativeInteger' => 'integer',
00286             'unsignedLong' => 'integer',
00287             'unsignedInt' => 'integer',
00288             'unsignedShort' => 'integer',
00289             'unsignedByte' => 'integer',
00290             'positiveInteger'  => 'integer',
00291             'anyType' => 'string',
00292             'anyURI' => 'string',
00293             'QName' => 'string'
00294         ),
00295         'http://www.w3.org/1999/XMLSchema' => array(
00296             'i4' => 'integer',
00297             'int' => 'integer',
00298             'boolean' => 'boolean',
00299             'string' => 'string',
00300             'double' => FLOAT,
00301             'float' => FLOAT,
00302             'dateTime' => 'string',
00303             'timeInstant' => 'string',
00304             'base64Binary' => 'string',
00305             'base64' => 'string',
00306             'ur-type' => 'string'
00307         ),
00308         'http://schemas.xmlsoap.org/soap/encoding/' => array('base64' => 'string','array' => 'array','Array' => 'array', 'Struct'=>'array')
00309     );
00310 
00311     // load namespace uris into an array of uri => prefix
00312     var $_namespaces;
00313     var $_ns_count = 0;
00314 
00315     var $_xmlEntities = array ( '&' => '&amp;', '<' => '&lt;', '>' => '&gt;', "'" => '&apos;', '"' => '&quot;' );
00316 
00317     var $_doconversion = FALSE;
00318 
00319     var $__attachments = array();
00320 
00321     var $_wsdl = NULL;
00322 
00328     var $_section5 = TRUE;
00329 
00330     // handle type to class mapping
00331     var $_auto_translation = true;
00332     var $_type_translation = array();
00333 
00334 
00341     function ilBMFBase($faultcode = 'Client')
00342     {
00343         parent::ilBMFBase_Object($faultcode);
00344         $this->_resetNamespaces();
00345     }
00346 
00347     function _resetNamespaces()
00348     {
00349         $this->_namespaces = array(
00350             'http://schemas.xmlsoap.org/soap/envelope/' => 'SOAP-ENV',
00351             'http://www.w3.org/2001/XMLSchema' => 'xsd',
00352             'http://www.w3.org/2001/XMLSchema-instance' => 'xsi',
00353             'http://schemas.xmlsoap.org/soap/encoding/' => 'SOAP-ENC');
00354     }
00355 
00365     function _setSchemaVersion($schemaVersion)
00366     {
00367         if (!in_array($schemaVersion, $this->_XMLSchema)) {
00368             return $this->_raiseSoapFault("unsuported XMLSchema $schemaVersion");
00369         }
00370         $this->_XMLSchemaVersion = $schemaVersion;
00371         $tmpNS = array_flip($this->_namespaces);
00372         $tmpNS['xsd'] = $this->_XMLSchemaVersion;
00373         $tmpNS['xsi'] = $this->_XMLSchemaVersion.'-instance';
00374         $this->_namespaces = array_flip($tmpNS);
00375     }
00376 
00377     function _getNamespacePrefix($ns)
00378     {
00379         if (array_key_exists($ns,$this->_namespaces)) {
00380             return $this->_namespaces[$ns];
00381         }
00382         $prefix = 'ns'.count($this->_namespaces);
00383         $this->_namespaces[$ns] = $prefix;
00384         return $prefix;
00385         return NULL;
00386     }
00387 
00388     function _getNamespaceForPrefix($prefix)
00389     {
00390         $flipped = array_flip($this->_namespaces);
00391         if (array_key_exists($prefix,$flipped)) {
00392             return $flipped[$prefix];
00393         }
00394         return NULL;
00395     }
00396 
00397     function _isSoapValue(&$value)
00398     {
00399         return is_object($value) && is_a($value,'ilbmfvalue');
00400     }
00401 
00402     function _serializeValue(&$value, $name = '', $type = false, $elNamespace = NULL, $typeNamespace=NULL, $options=array(), $attributes = array(), $artype='', $OBJTypeNS = array())
00403     {
00404         $namespaces = array();
00405         $arrayType = $array_depth = $xmlout_value = null;
00406         $typePrefix = $elPrefix = $xmlout_offset = $xmlout_arrayType = $xmlout_type = $xmlns = '';
00407         $ptype = $array_type_ns = '';
00408 
00409         if (!$name || is_numeric($name)) {
00410             $name = 'item';
00411         }
00412 
00413         if ($this->_wsdl)
00414             list($ptype, $arrayType, $array_type_ns, $array_depth)
00415                     = $this->_wsdl->getSchemaType($type, $name, $typeNamespace);
00416 
00417         if (!$arrayType) $arrayType = $artype;
00418         if (!$ptype) $ptype = $this->_getType($value);
00419         if (!$type) $type = $ptype;
00420 
00421         if (strcasecmp($ptype,'Struct') == 0 || strcasecmp($type,'Struct') == 0) {
00422             // struct
00423             $vars = NULL;
00424             if (is_object($value)) {
00425                 $vars = get_object_vars($value);
00426             } else {
00427                 $vars = &$value;
00428             }
00429             if (is_array($vars)) {
00430                 foreach (array_keys($vars) as $k) {
00431                     if ($k[0]=='_') continue; // hide private vars
00432                     if (is_object($vars[$k])) {
00433                         if (is_a($vars[$k],'ilbmfvalue')) {
00434                             $xmlout_value .= $vars[$k]->serialize($this);
00435                         } else {
00436                             // XXX get the members and serialize them instead
00437                             // converting to an array is more overhead than we
00438                             // should realy do, but php-soap is on it's way.
00439                             $objarr = get_object_vars ( $vars[$k] );
00440                             if (!isset ($objarr['OBJTypeNS'])) {
00441                                 $xmlout_value .= $this->_serializeValue(get_object_vars($vars[$k]), $k, false, $this->_section5?NULL:$elNamespace, NULL, NULL, NULL, NULL);
00442                             } else {
00443                                 $xmlout_value .= $this->_serializeValue(get_object_vars($vars[$k]), $k, false, $this->_section5?NULL:$elNamespace, NULL, NULL, NULL, NULL, $objarr['OBJTypeNS']);
00444                             }
00445                         }
00446                     } else {
00447                         if ($k != 'OBJTypeNS') {
00448                             $xmlout_value .= $this->_serializeValue($vars[$k],$k, false, $this->_section5?NULL:$elNamespace);
00449                         }
00450                     }
00451                 }
00452             }
00453         } else if (strcasecmp($ptype,'Array')==0 || strcasecmp($type,'Array')==0) {
00454             // array
00455             $typeNamespace = SOAP_SCHEMA_ENCODING;
00456             $orig_type = $type;
00457             $type = 'Array';
00458             $numtypes = 0;
00459             // XXX this will be slow on larger array's.  Basicly, it flattens array's to allow us
00460             // to serialize multi-dimensional array's.  We only do this if arrayType is set,
00461             // which will typicaly only happen if we are using WSDL
00462             if (isset($options['flatten']) || ($arrayType && (strchr($arrayType,',') || strstr($arrayType,'][')))) {
00463                 $numtypes = $this->_multiArrayType($value, $arrayType, $ar_size, $xmlout_value);
00464             }
00465 
00466             $array_type = $array_type_prefix = '';
00467             if ($numtypes != 1) {
00468                 $arrayTypeQName =& new ilBMFQName($arrayType);
00469                 $arrayType = $arrayTypeQName->name;
00470                 $array_types = array();
00471                 $array_val = NULL;
00472 
00473                 // serialize each array element
00474                 $ar_size = count($value);
00475                 foreach ($value as $array_val) {
00476                     if ($this->_isSoapValue($array_val)) {
00477                         $array_type = $array_val->type;
00478                         $array_types[$array_type] = 1;
00479                         $array_type_ns = $array_val->type_namespace;
00480                         $xmlout_value .= $array_val->serialize($this);
00481                     } else {
00482                         $array_type = $this->_getType($array_val);
00483                         $array_types[$array_type] = 1;
00484                         $objarr = get_object_vars ( $array_val );
00485                         if (isset($objarr['OBJTypeNS'])) {
00486                             $tmp_arr['item'] = $objarr['OBJTypeNS']['item'];
00487                             $xmlout_value .= $this->_serializeValue($array_val,'item', $array_type, $elNamespace, NULL, NULL, NULL, NULL, $tmp_arr);
00488                         } else {
00489                             $xmlout_value .= $this->_serializeValue($array_val,'item', $array_type, $elNamespace);
00490                         }
00491                     }
00492                 }
00493 
00494                 $xmlout_offset = " SOAP-ENC:offset=\"[0]\"";
00495                 if (!$arrayType) {
00496                     $numtypes = count($array_types);
00497                     if ($numtypes == 1) $arrayType = $array_type;
00498                     // using anyType is more interoperable
00499                     if ($array_type == 'Struct') {
00500                         $array_type = '';
00501                     } else if ($array_type == 'Array') {
00502                         $arrayType = 'anyType';
00503                         $array_type_prefix = 'xsd';
00504                     } else
00505                     if (!$arrayType) $arrayType = $array_type;
00506                 }
00507             }
00508             if (!$arrayType || $numtypes > 1) {
00509                 $arrayType = 'xsd:anyType'; // should reference what schema we're using
00510             } else {
00511                 if ($array_type_ns) {
00512                     $array_type_prefix = $this->_getNamespacePrefix($array_type_ns);
00513                 } else if (array_key_exists($arrayType, $this->_typemap[$this->_XMLSchemaVersion])) {
00514                     $array_type_prefix = $this->_namespaces[$this->_XMLSchemaVersion];
00515                 }
00516                 if ($array_type_prefix)
00517                     $arrayType = $array_type_prefix.':'.$arrayType;
00518             }
00519 
00520              if (isset($value[0]->OBJTypeNS)) {
00521                  $xmlout_arrayType = ' xmlns:' . $value[0]->OBJTypeNS['nsPrefix'] . '="' . $value[0]->OBJTypeNS['namespace'] . '" xsi:type="' . $value[0]->OBJTypeNS['nsPrefix'] . ':Array" ' . $value[0]->OBJTypeNS['nsPrefix'] . ':arrayType="' . $value[0]->OBJTypeNS['pnsPrefix'] . ':' . get_class($value[0]);
00522                  $xmlout_type = $xmlns = $xmlout_offset = $xml_attr = $arrayType = '';
00523              } else {
00524                  $xmlout_arrayType = " SOAP-ENC:arrayType=\"" . $arrayType;
00525              }
00526             if ($array_depth != null) {
00527                 for ($i = 0; $i < $array_depth; $i++) {
00528                     $xmlout_arrayType .= '[]';
00529                 }
00530             }
00531             $xmlout_arrayType .= "[$ar_size]\"";
00532         } else if ($this->_isSoapValue($value)) {
00533             $xmlout_value =& $value->serialize($this);
00534         } else if ($type == 'string') {
00535             $xmlout_value = htmlspecialchars($value);
00536         } else if ($type == 'rawstring') {
00537             $xmlout_value =& $value;
00538         } else if ($type == 'boolean') {
00539             $xmlout_value = $value?'true':'false';
00540         } else {
00541             $xmlout_value =& $value;
00542         }
00543 
00544         // add namespaces
00545         if ($elNamespace) {
00546             $elPrefix = $this->_getNamespacePrefix($elNamespace);
00547             $xmlout_name = "$elPrefix:$name";
00548         } else {
00549             $xmlout_name = $name;
00550         }
00551 
00552         if ($typeNamespace) {
00553             $typePrefix = $this->_getNamespacePrefix($typeNamespace);
00554             $xmlout_type = "$typePrefix:$type";
00555         } else if ($type && array_key_exists($type, $this->_typemap[$this->_XMLSchemaVersion])) {
00556             $typePrefix = $this->_namespaces[$this->_XMLSchemaVersion];
00557             $xmlout_type = "$typePrefix:$type";
00558         }
00559 
00560         // handle additional attributes
00561         $xml_attr = '';
00562         if (count($attributes) > 0) {
00563             foreach ($attributes as $k => $v) {
00564                 $kqn =& new ilBMFQName($k);
00565                 $vqn =& new ilBMFQName($v);
00566                 $xml_attr .= ' '.$kqn->fqn().'="'.$vqn->fqn().'"';
00567             }
00568         }
00569 
00570         // store the attachement for mime encoding
00571         if (isset($options['attachment']))
00572             $this->__attachments[] = $options['attachment'];
00573 
00574         if ($this->_section5) {
00575             if ($name == 'item' && isset($OBJTypeNS['item'])) {
00576                 $xmlout_type = $OBJTypeNS['item'];
00577             }
00578             
00579             if ($xmlout_type) $xmlout_type = " xsi:type=\"$xmlout_type\"";
00580             if (is_null($xmlout_value)) {
00581                 $xml = "";
00582             } else {
00583                 if (isset ($value[0]->OBJTypeNS)) {
00584                     $xmlout_type = '';
00585                 }
00586                 $xml = "\r\n<$xmlout_name$xmlout_type$xmlns$xmlout_arrayType$xmlout_offset$xml_attr ";
00587                 if (isset($OBJTypeNS['namespace']) && isset($OBJTypeNS['type'])) {
00588                     if (trim($OBJTypeNS['namespace']) != '' || trim($OBJTypeNS['type']) != '') {
00589                         if (isset($OBJTypeNS['namespace']) && $OBJTypeNS['namespace'] != '') {
00590                            $xml .= ' xmlns:';
00591                            if ( isset($OBJTypeNS['nsPrefix']))
00592                               $xml .= $OBJTypeNS['nsPrefix'];
00593                            else
00594                                $xml .= 'intf';
00595                            $xml .= '="' . $OBJTypeNS['namespace'] . '"';
00596                         }
00597                         if (isset($OBJTypeNS['type']) && $OBJTypeNS['type'] != '') {
00598                            $xml .= ' xsi:type="';
00599                            if (strpos($OBJTypeNS['type'], "xsd:") === false){
00600                                if (isset($OBJTypeNS['nsPrefix']))
00601                                   $xml .= $OBJTypeNS['nsPrefix'] . ':';
00602                                else
00603                                    $xml .= 'intf:';
00604                            }
00605                            $xml .= $OBJTypeNS['type'] . '"';
00606                         }
00607                     }
00608                 }
00609                 $xml .= ">" . $xmlout_value . "</$xmlout_name>";
00610             }
00611         } else {
00612             if (is_null($xmlout_value)) {
00613                 $xml = "";
00614             } else {
00615                 $xml = "\r\n<$xmlout_name$xmlns$xml_attr>".
00616                     $xmlout_value."</$xmlout_name>";
00617             }
00618         }
00619         return $xml;
00620     }
00621 
00622 
00632     function _getType(&$value) {
00633         global $SOAP_OBJECT_STRUCT,$SOAP_RAW_CONVERT;
00634         $type = gettype($value);
00635         switch ($type) {
00636         case 'object':
00637             if (is_a($value,'ilbmfvalue')) {
00638                 $type = $value->type;
00639             } else {
00640                 $type = 'Struct';
00641             }
00642             break;
00643         case 'array':
00644             // XXX hashes always get done as structs by pear::soap
00645             if ($this->_isHash($value)) {
00646                 $type = 'Struct';
00647             } else {
00648                 $ar_size = count($value);
00649                     reset($value);
00650             $key1 = key($value);
00651             if ($ar_size > 0 && is_a($key1,'ilbmfvalue')) {
00652             // fixme for non-wsdl structs that are all the same type
00653             $key2 = key($value);
00654             if ($ar_size > 1 &&
00655                 $this->_isSoapValue($key1) &&
00656             $this->_isSoapValue($key2) &&
00657             $key1->name != $key2->name) {
00658                         // this is a struct, not an array
00659                         $type = 'Struct';
00660                     } else {
00661                         $type = 'Array';
00662                     }
00663                 } else {
00664                     $type = 'Array';
00665                 }
00666             }
00667             break;
00668         case 'integer':
00669         case 'long':
00670             $type = 'int';
00671             break;
00672         case 'boolean':
00673             #$value = $value?'true':'false';
00674             break;
00675         case 'double':
00676             $type = 'decimal';
00677             break;
00678         case 'NULL':
00679             $type = '';
00680             break;
00681         case 'string':
00682             if ($SOAP_RAW_CONVERT) {
00683                 if (is_numeric($value)) {
00684                     if (strstr($value,'.')) $type = 'float';
00685                     else $type = 'int';
00686                 } else
00687                 if (ilBMFType_hexBinary::is_hexbin($value)) {
00688                     $type = 'hexBinary';
00689                 } else
00690                 if ($this->_isBase64($value)) {
00691                     $type = 'base64Binary';
00692                 } else {
00693                     $dt =& new ilBMFType_dateTime($value);
00694                     if ($dt->toUnixtime() != -1) {
00695                         $type = 'dateTime';
00696                         #$value = $dt->toSOAP();
00697                     }
00698                 }
00699             } else {
00700                 $dt =& new ilBMFType_dateTime($value);
00701                 if ($dt->toUnixtime() != -1) {
00702                     $type = 'dateTime';
00703                     #$value = $dt->toSOAP();
00704                 }
00705             }
00706         default:
00707             break;
00708         }
00709         return $type;
00710     }
00711 
00712     function _multiArrayType(&$value, &$type, &$size, &$xml)
00713     {
00714         $sz = count($value);
00715         if (is_array($value)) {
00716             // seems we have a multi dimensional array, figure it out if we do
00717             $c = count($value);
00718             for ($i=0; $i<$c; $i++) {
00719                 $this->_multiArrayType($value[$i], $type, $size, $xml);
00720             }
00721 
00722             if ($size) {
00723                 $size = $sz.','.$size;
00724             } else {
00725                 $size = $sz;
00726             }
00727             return 1;
00728         } else {
00729             if (is_object($value)) {
00730                 $type = $value->type;
00731                 $xml .= $value->serialize($this);
00732             } else {
00733                 $type = $this->_getType($value);
00734                 $xml .= $this->_serializeValue($value,'item',$type);
00735             }
00736         }
00737         $size = NULL;
00738         return 1;
00739     }
00740     // support functions
00746     function _isBase64(&$value)
00747     {
00748         $l = strlen($value);
00749         if ($l > 0)
00750             return $value[$l-1] == '=' && preg_match("/[A-Za-z=\/\+]+/",$value);
00751         return FALSE;
00752     }
00753 
00759     function _isHash(&$a) {
00760         # XXX I realy dislike having to loop through this in php code,
00761         # realy large arrays will be slow.  We need a C function to do this.
00762         $names = array();
00763         $it = 0;
00764         foreach ($a as $k => $v) {
00765             # checking the type is faster than regexp.
00766             $t = gettype($k);
00767             if ($t != 'integer') {
00768                 return TRUE;
00769             } else if ($this->_isSoapValue($v)) {
00770                 $names[$v->name] = 1;
00771             }
00772             // if someone has a large hash they should realy be defining the type
00773             if ($it++ > 10) return FALSE;
00774         }
00775         return count($names)>1;
00776     }
00777 
00778     function &_un_htmlentities($string)
00779     {
00780        $trans_tbl = get_html_translation_table (HTML_ENTITIES);
00781        $trans_tbl = array_flip($trans_tbl);
00782        return strtr($string, $trans_tbl);
00783     }
00784 
00789     function &_decode(&$soapval)
00790     {
00791         global $SOAP_OBJECT_STRUCT;
00792         if (!$this->_isSoapValue($soapval)) {
00793             return $soapval;
00794         } else if (is_array($soapval->value)) {
00795             if ($SOAP_OBJECT_STRUCT && $soapval->type != 'Array') {
00796                 $classname = 'stdclass';
00797                 if (isset($this->_type_translation[$soapval->tqn->fqn()])) {
00798                     // this will force an error in php if the
00799                     // class does not exist
00800                     $classname = $this->_type_translation[$soapval->tqn->fqn()];
00801                 } else if (isset($this->_type_translation[$soapval->type])) {
00802                     // this will force an error in php if the
00803                     // class does not exist
00804                     $classname = $this->_type_translation[$soapval->type];
00805                 } else if ($this->_auto_translation) {
00806                     if (class_exists($soapval->type)) {
00807                         $classname = $soapval->type;
00808                     } else if ($this->_wsdl) {
00809                         $t = $this->_wsdl->getComplexTypeNameForElement($soapval->name, $soapval->namespace);
00810                         if ($t && class_exists($t)) $classname = $t;
00811                     }
00812                 }
00813                 $return =& new $classname;
00814             } else {
00815                 $return = array();
00816             }
00817 
00818             $counter = 1;
00819             $isstruct = !$SOAP_OBJECT_STRUCT || !is_array($return);
00820             foreach ($soapval->value as $item) {
00821                 if (is_object($return)) {
00822                     if ($this->_wsdl) {
00823                         // get this childs wsdl information
00824                         // /$soapval->ns/$soapval->type/$item->ns/$item->name
00825                         $child_type = $this->_wsdl->getComplexTypeChildType(
00826                                                 $soapval->namespace,
00827                                                 $soapval->name,
00828                                                 $item->namespace,
00829                                                 $item->name);
00830                         if ($child_type) $item->type = $child_type;
00831                     }
00832                     if (!$isstruct || $item->type == 'Array') {
00833                         if (isset($return->{$item->name}) &&
00834                           is_object($return->{$item->name})) {
00835                             $return->{$item->name} =& $this->_decode($item);
00836                         } else if (isset($return->{$item->name}) &&
00837                           is_array($return->{$item->name})) {
00838                             $return->{$item->name}[] =& $this->_decode($item);
00839                         } else if (is_array($return)) {
00840                             $return[] =& $this->_decode($item);
00841                         } else {
00842                             $return->{$item->name} =& $this->_decode($item);
00843                         }
00844                     } else if (isset($return->{$item->name})) {
00845                         $isstruct = FALSE;
00846                         if (count(get_object_vars($return)) == 1) {
00847                             $d =& $this->_decode($item);
00848                             $return = array($return->{$item->name}, $d);
00849                         } else {
00850                             $d =& $this->_decode($item);
00851                             $return->{$item->name} = array($return->{$item->name}, $d);
00852                         }
00853                     } else {
00854                         $return->{$item->name} =& $this->_decode($item);
00855                     }
00856                     /* set the attributes as members in the class */
00857                     if (method_exists($return,'__set_attribute')) {
00858                         foreach ($soapval->attributes as $key=>$value) {
00859                             call_user_func_array(array(&$return,'__set_attribute'),array($key,$value));
00860                         }
00861                     }
00862                 } else {
00863                     if ($soapval->arrayType && $this->_isSoapValue($item)) {
00864                         $item->type = $soapval->arrayType;
00865                     }
00866                     if (!$isstruct) {
00867                         $return[] =& $this->_decode($item);
00868                     } else if (isset($return[$item->name])) {
00869                         $isstruct = FALSE;
00870                         $d =& $this->_decode($item);
00871                         $return = array($return[$item->name], $d);
00872                     } else {
00873                         $return[$item->name] =& $this->_decode($item);
00874                     }
00875                 }
00876             }
00877             return $return;
00878         }
00879 
00880         if ($soapval->type == 'boolean') {
00881             if ($soapval->value != '0' && strcasecmp($soapval->value,'false') !=0) {
00882                 $soapval->value = TRUE;
00883             } else {
00884                 $soapval->value = FALSE;
00885             }
00886         } else if ($soapval->type && array_key_exists($soapval->type, $this->_typemap[SOAP_XML_SCHEMA_VERSION])) {
00887             # if we can, lets set php's variable type
00888             settype($soapval->value, $this->_typemap[SOAP_XML_SCHEMA_VERSION][$soapval->type]);
00889         }
00890         return $soapval->value;
00891     }
00892 
00900     function &_makeEnvelope(&$method, &$headers, $encoding = SOAP_DEFAULT_ENCODING,$options = array())
00901     {
00902         $smsg = $header_xml = $ns_string = '';
00903 
00904         if ($headers) {
00905             $c = count($headers);
00906             for ($i=0; $i < $c; $i++) {
00907                 $header_xml .= $headers[$i]->serialize($this);
00908             }
00909             $header_xml = "<SOAP-ENV:Header>\r\n$header_xml\r\n</SOAP-ENV:Header>\r\n";
00910         }
00911         if (!isset($options['input']) || $options['input'] == 'parse') {
00912             if (is_array($method)) {
00913                 $c = count($method);
00914                 for ($i = 0; $i < $c; $i++) {
00915                     $smsg .= $method[$i]->serialize($this);
00916                 }
00917             }  else {
00918                 $smsg =& $method->serialize($this);
00919             }
00920         } else {
00921             $smsg =& $method;
00922         }
00923         $body = "<SOAP-ENV:Body>\r\n".$smsg."\r\n</SOAP-ENV:Body>\r\n";
00924 
00925         foreach ($this->_namespaces as $k => $v) {
00926             $ns_string .= " xmlns:$v=\"$k\"\r\n";
00927         }
00928 
00929         /* if use='literal', we do not put in the encodingStyle.  This is denoted by
00930            $this->_section5 being false.
00931            XXX use can be defined at a more granular level than we are dealing with
00932            here, so this does not work for all services.
00933         */
00934         $xml = "<?xml version=\"1.0\" encoding=\"$encoding\"?>\r\n\r\n".
00935             "<SOAP-ENV:Envelope $ns_string".
00936             ($this->_section5?" SOAP-ENV:encodingStyle=\"" . SOAP_SCHEMA_ENCODING . "\"":'').
00937             ">\r\n".
00938             "$header_xml$body</SOAP-ENV:Envelope>\r\n";
00939 
00940         return $xml;
00941     }
00942 
00943     function &_makeMimeMessage(&$xml, $encoding = SOAP_DEFAULT_ENCODING)
00944     {
00945         global $SOAP_options;
00946 
00947         if (!isset($SOAP_options['Mime'])) {
00948             return $this->_raiseSoapFault('Mime is not installed');
00949         }
00950 
00951         // encode any attachments
00952         // see http://www.w3.org/TR/SOAP-attachments
00953         // now we have to mime encode the message
00954         $params = array('content_type' => 'multipart/related; type=text/xml');
00955         $msg =& new Mail_mimePart('', $params);
00956         // add the xml part
00957         $params['content_type'] = 'text/xml';
00958         $params['charset'] = $encoding;
00959         $params['encoding'] = 'base64';
00960         $msg->addSubPart($xml, $params);
00961 
00962         // add the attachements
00963         $c = count($this->__attachments);
00964         for ($i=0; $i < $c; $i++) {
00965             $attachment =& $this->__attachments[$i];
00966             $msg->addSubPart($attachment['body'],$attachment);
00967         }
00968         return $msg->encode();
00969     }
00970 
00971     // XXX this needs to be used from the Transport system
00972     function &_makeDIMEMessage(&$xml)
00973     {
00974         global $SOAP_options;
00975 
00976         if (!isset($SOAP_options['DIME'])) {
00977             return $this->_raiseSoapFault('DIME is not installed');
00978         }
00979 
00980         // encode any attachments
00981         // see http://search.ietf.org/internet-drafts/draft-nielsen-dime-soap-00.txt
00982         // now we have to DIME encode the message
00983         $dime =& new Net_DIME_Message();
00984         $msg =& $dime->encodeData($xml,SOAP_ENVELOP,NULL,NET_DIME_TYPE_URI);
00985 
00986         // add the attachements
00987         $c = count($this->__attachments);
00988         for ($i=0; $i < $c; $i++) {
00989             $attachment =& $this->__attachments[$i];
00990             $msg .= $dime->encodeData($attachment['body'],$attachment['content_type'],$attachment['cid'],NET_DIME_TYPE_MEDIA);
00991         }
00992         $msg .= $dime->endMessage();
00993         return $msg;
00994     }
00995 
00996     function _decodeMimeMessage(&$data, &$headers, &$attachments)
00997     {
00998         global $SOAP_options;
00999         if (!isset($SOAP_options['Mime'])) {
01000             $this->_raiseSoapFault('Mime Unsupported, install PEAR::Mail::Mime','','','Server');
01001             return;
01002         }
01003 
01004         $params['include_bodies'] = TRUE;
01005         $params['decode_bodies']  = TRUE;
01006         $params['decode_headers'] = TRUE;
01007 
01008         // XXX lame thing to have to do for decoding
01009         $decoder =& new Mail_mimeDecode($data);
01010         $structure = $decoder->decode($params);
01011 
01012         if (isset($structure->body)) {
01013             $data = $structure->body;
01014             $headers = $structure->headers;
01015             return;
01016         } else if (isset($structure->parts)) {
01017             $data = $structure->parts[0]->body;
01018             $headers = array_merge($structure->headers,$structure->parts[0]->headers);
01019             if (count($structure->parts) > 1) {
01020                 $mime_parts = array_splice($structure->parts,1);
01021                 // prepare the parts for the soap parser
01022 
01023                 $c = count($mime_parts);
01024                 for ($i = 0; $i < $c; $i++) {
01025                     $p =& $mime_parts[$i];
01026                     if (isset($p->headers['content-location'])) {
01027                         // XXX TODO: modify location per SwA note section 3
01028                         // http://www.w3.org/TR/SOAP-attachments
01029                         $attachments[$p->headers['content-location']] = $p->body;
01030                     } else {
01031                         $cid = 'cid:'.substr($p->headers['content-id'],1,strlen($p->headers['content-id'])-2);
01032                         $attachments[$cid] = $p->body;
01033                     }
01034                 }
01035             }
01036             return;
01037         }
01038         $this->_raiseSoapFault('Mime parsing error','','','Server');
01039     }
01040 
01041     function _decodeDIMEMessage(&$data, &$headers, &$attachments)
01042     {
01043         global $SOAP_options;
01044         if (!isset($SOAP_options['DIME'])) {
01045             $this->_raiseSoapFault('DIME Unsupported, install PEAR::Net::DIME','','','Server');
01046             return;
01047         }
01048 
01049         // XXX this SHOULD be moved to the transport layer, e.g. PHP  itself
01050         // should handle parsing DIME ;)
01051         $dime =& new Net_DIME_Message();
01052         $err = $dime->decodeData($data);
01053         if ( PEAR::isError($err) ) {
01054             $this->_raiseSoapFault('Failed to decode the DIME message!','','','Server');
01055             return;
01056         }
01057         if (strcasecmp($dime->parts[0]['type'],SOAP_ENVELOP) !=0) {
01058             $this->_raiseSoapFault('DIME record 1 is not a SOAP envelop!','','','Server');
01059             return;
01060         }
01061 
01062             $data = $dime->parts[0]['data'];
01063             $headers['content-type'] = 'text/xml'; // fake it for now
01064             $c = count($dime->parts);
01065             for ($i = 0; $i < $c; $i++) {
01066                 $part =& $dime->parts[$i];
01067                 // XXX we need to handle URI's better
01068             $id = strncmp( $part['id'], 'cid:', 4 ) ? 'cid:'.$part['id'] : $part['id'];
01069             $attachments[$id] = $part['data'];
01070         }
01071     }
01072 
01073     function __set_type_translation($type, $class=NULL)
01074     {
01075         $tq =& new ilBMFQName($type);
01076         if (!$class) {
01077             $class = $tq->name;
01078         }
01079         $this->_type_translation[$type]=$class;
01080     }
01081 }
01082 
01092 class ilBMFQName
01093 {
01094     var $name = '';
01095     var $ns = '';
01096     var $namespace='';
01097     #var $arrayInfo = '';
01098 
01099     function ilBMFQName($name, $namespace = '') {
01100         if ($name && $name[0] == '{') {
01101             preg_match('/\{(.*?)\}(.*)/',$name, $m);
01102             $this->name = $m[2];
01103             $this->namespace = $m[1];
01104         } else if (strpos($name, ':') != FALSE) {
01105             $s = split(':',$name);
01106             $s = array_reverse($s);
01107             $this->name = $s[0];
01108             $this->ns = $s[1];
01109             $this->namespace = $namespace;
01110         } else {
01111             $this->name = $name;
01112             $this->namespace = $namespace;
01113         }
01114 
01115         # a little more magic than should be in a qname
01116         $p = strpos($this->name, '[');
01117         if ($p) {
01118             # XXX need to re-examine this logic later
01119             # chop off []
01120             $this->arraySize = split(',',substr($this->name,$p+1, strlen($this->name)-$p-2));
01121             $this->arrayInfo = substr($this->name, $p);
01122             $this->name = substr($this->name, 0, $p);
01123         }
01124     }
01125 
01126     function fqn()
01127     {
01128         if ($this->namespace) {
01129             return '{'.$this->namespace.'}'.$this->name;
01130         } else if ($this->ns) {
01131             return $this->ns.':'.$this->name;
01132         }
01133         return $this->name;
01134     }
01135 
01136 }
01137 ?>

Generated on Fri Dec 13 2013 11:57:58 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1