Support Incident Tracker GIT4.x
class.nusoap_base.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004 $Id: class.nusoap_base.php,v 1.51 2007/11/06 15:17:46 snichol Exp $
00005 
00006 NuSOAP - Web Services Toolkit for PHP
00007 
00008 Copyright (c) 2002 NuSphere Corporation
00009 
00010 This library is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU Lesser General Public
00012 License as published by the Free Software Foundation; either
00013 version 2.1 of the License, or (at your option) any later version.
00014 
00015 This library is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 Lesser General Public License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public
00021 License along with this library; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 
00024 The NuSOAP project home is:
00025 http://sourceforge.net/projects/nusoap/
00026 
00027 The primary support for NuSOAP is the mailing list:
00028 nusoap-general@lists.sourceforge.net
00029 
00030 If you have any questions or comments, please email:
00031 
00032 Dietrich Ayala
00033 dietrich@ganx4.com
00034 http://dietrich.ganx4.com/nusoap
00035 
00036 NuSphere Corporation
00037 http://www.nusphere.com
00038 
00039 */
00040 
00041 /*
00042  *  Some of the standards implmented in whole or part by NuSOAP:
00043  *
00044  *  SOAP 1.1 (http://www.w3.org/TR/2000/NOTE-SOAP-20000508/)
00045  *  WSDL 1.1 (http://www.w3.org/TR/2001/NOTE-wsdl-20010315)
00046  *  SOAP Messages With Attachments (http://www.w3.org/TR/SOAP-attachments)
00047  *  XML 1.0 (http://www.w3.org/TR/2006/REC-xml-20060816/)
00048  *  Namespaces in XML 1.0 (http://www.w3.org/TR/2006/REC-xml-names-20060816/)
00049  *  XML Schema 1.0 (http://www.w3.org/TR/xmlschema-0/)
00050  *  RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
00051  *  RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1
00052  *  RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
00053  */
00054 
00055 /* load classes
00056 
00057 // necessary classes
00058 require_once('class.soapclient.php');
00059 require_once('class.soap_val.php');
00060 require_once('class.soap_parser.php');
00061 require_once('class.soap_fault.php');
00062 
00063 // transport classes
00064 require_once('class.soap_transport_http.php');
00065 
00066 // optional add-on classes
00067 require_once('class.xmlschema.php');
00068 require_once('class.wsdl.php');
00069 
00070 // server class
00071 require_once('class.soap_server.php');*/
00072 
00073 // class variable emulation
00074 // cf. http://www.webkreator.com/php/techniques/php-static-class-variables.html
00075 $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel = 9;
00076 
00086 class nusoap_base {
00093     var $title = 'NuSOAP';
00100     var $version = '0.7.3';
00107     var $revision = '$Revision: 1.51 $';
00114     var $error_str = '';
00121     var $debug_str = '';
00129     var $charencoding = true;
00136     var $debugLevel;
00137 
00144     var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
00145     
00152     var $soap_defencoding = 'ISO-8859-1';
00153     //var $soap_defencoding = 'UTF-8';
00154 
00163     var $namespaces = array(
00164         'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
00165         'xsd' => 'http://www.w3.org/2001/XMLSchema',
00166         'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
00167         'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
00168         );
00169 
00176     var $usedNamespaces = array();
00177 
00185     var $typemap = array(
00186     'http://www.w3.org/2001/XMLSchema' => array(
00187         'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
00188         'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
00189         'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
00190         // abstract "any" types
00191         'anyType'=>'string','anySimpleType'=>'string',
00192         // derived datatypes
00193         'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
00194         'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
00195         'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
00196         'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
00197     'http://www.w3.org/2000/10/XMLSchema' => array(
00198         'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
00199         'float'=>'double','dateTime'=>'string',
00200         'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
00201     'http://www.w3.org/1999/XMLSchema' => array(
00202         'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
00203         'float'=>'double','dateTime'=>'string',
00204         'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
00205     'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
00206     'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
00207     'http://xml.apache.org/xml-soap' => array('Map')
00208     );
00209 
00218     var $xmlEntities = array('quot' => '"','amp' => '&',
00219         'lt' => '<','gt' => '>','apos' => "'");
00220 
00226     function nusoap_base() {
00227         $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel;
00228     }
00229 
00236     function getGlobalDebugLevel() {
00237         return $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel;
00238     }
00239 
00246     function setGlobalDebugLevel($level) {
00247         $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel = $level;
00248     }
00249 
00256     function getDebugLevel() {
00257         return $this->debugLevel;
00258     }
00259 
00266     function setDebugLevel($level) {
00267         $this->debugLevel = $level;
00268     }
00269 
00276     function debug($string){
00277         if ($this->debugLevel > 0) {
00278             $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n");
00279         }
00280     }
00281 
00288     function appendDebug($string){
00289         if ($this->debugLevel > 0) {
00290             // it would be nice to use a memory stream here to use
00291             // memory more efficiently
00292             $this->debug_str .= $string;
00293         }
00294     }
00295 
00301     function clearDebug() {
00302         // it would be nice to use a memory stream here to use
00303         // memory more efficiently
00304         $this->debug_str = '';
00305     }
00306 
00313     function &getDebug() {
00314         // it would be nice to use a memory stream here to use
00315         // memory more efficiently
00316         return $this->debug_str;
00317     }
00318 
00326     function &getDebugAsXMLComment() {
00327         // it would be nice to use a memory stream here to use
00328         // memory more efficiently
00329         while (strpos($this->debug_str, '--')) {
00330             $this->debug_str = str_replace('--', '- -', $this->debug_str);
00331         }
00332         $ret = "<!--\n" . $this->debug_str . "\n-->";
00333         return $ret;
00334     }
00335 
00342     function expandEntities($val) {
00343         if ($this->charencoding) {
00344             $val = str_replace('&', '&amp;', $val);
00345             $val = str_replace("'", '&apos;', $val);
00346             $val = str_replace('"', '&quot;', $val);
00347             $val = str_replace('<', '&lt;', $val);
00348             $val = str_replace('>', '&gt;', $val);
00349         }
00350         return $val;
00351     }
00352 
00359     function getError(){
00360         if($this->error_str != ''){
00361             return $this->error_str;
00362         }
00363         return false;
00364     }
00365 
00372     function setError($str){
00373         $this->error_str = $str;
00374     }
00375 
00383     function isArraySimpleOrStruct($val) {
00384         $keyList = array_keys($val);
00385         foreach ($keyList as $keyListValue) {
00386             if (!is_int($keyListValue)) {
00387                 return 'arrayStruct';
00388             }
00389         }
00390         return 'arraySimple';
00391     }
00392 
00408     function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) {
00409         $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
00410         $this->appendDebug('value=' . $this->varDump($val));
00411         $this->appendDebug('attributes=' . $this->varDump($attributes));
00412         
00413         if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) {
00414             $this->debug("serialize_val: serialize soapval");
00415             $xml = $val->serialize($use);
00416             $this->appendDebug($val->getDebug());
00417             $val->clearDebug();
00418             $this->debug("serialize_val of soapval returning $xml");
00419             return $xml;
00420         }
00421         // force valid name if necessary
00422         if (is_numeric($name)) {
00423             $name = '__numeric_' . $name;
00424         } elseif (! $name) {
00425             $name = 'noname';
00426         }
00427         // if name has ns, add ns prefix to name
00428         $xmlns = '';
00429         if($name_ns){
00430             $prefix = 'nu'.rand(1000,9999);
00431             $name = $prefix.':'.$name;
00432             $xmlns .= " xmlns:$prefix=\"$name_ns\"";
00433         }
00434         // if type is prefixed, create type prefix
00435         if($type_ns != '' && $type_ns == $this->namespaces['xsd']){
00436             // need to fix this. shouldn't default to xsd if no ns specified
00437             // w/o checking against typemap
00438             $type_prefix = 'xsd';
00439         } elseif($type_ns){
00440             $type_prefix = 'ns'.rand(1000,9999);
00441             $xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
00442         }
00443         // serialize attributes if present
00444         $atts = '';
00445         if($attributes){
00446             foreach($attributes as $k => $v){
00447                 $atts .= " $k=\"".$this->expandEntities($v).'"';
00448             }
00449         }
00450         // serialize null value
00451         if (is_null($val)) {
00452             $this->debug("serialize_val: serialize null");
00453             if ($use == 'literal') {
00454                 // TODO: depends on minOccurs
00455                 $xml = "<$name$xmlns$atts/>";
00456                 $this->debug("serialize_val returning $xml");
00457                 return $xml;
00458             } else {
00459                 if (isset($type) && isset($type_prefix)) {
00460                     $type_str = " xsi:type=\"$type_prefix:$type\"";
00461                 } else {
00462                     $type_str = '';
00463                 }
00464                 $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
00465                 $this->debug("serialize_val returning $xml");
00466                 return $xml;
00467             }
00468         }
00469         // serialize if an xsd built-in primitive type
00470         if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){
00471             $this->debug("serialize_val: serialize xsd built-in primitive type");
00472             if (is_bool($val)) {
00473                 if ($type == 'boolean') {
00474                     $val = $val ? 'true' : 'false';
00475                 } elseif (! $val) {
00476                     $val = 0;
00477                 }
00478             } else if (is_string($val)) {
00479                 $val = $this->expandEntities($val);
00480             }
00481             if ($use == 'literal') {
00482                 $xml = "<$name$xmlns$atts>$val</$name>";
00483                 $this->debug("serialize_val returning $xml");
00484                 return $xml;
00485             } else {
00486                 $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
00487                 $this->debug("serialize_val returning $xml");
00488                 return $xml;
00489             }
00490         }
00491         // detect type and serialize
00492         $xml = '';
00493         switch(true) {
00494             case (is_bool($val) || $type == 'boolean'):
00495                 $this->debug("serialize_val: serialize boolean");
00496                 if ($type == 'boolean') {
00497                     $val = $val ? 'true' : 'false';
00498                 } elseif (! $val) {
00499                     $val = 0;
00500                 }
00501                 if ($use == 'literal') {
00502                     $xml .= "<$name$xmlns$atts>$val</$name>";
00503                 } else {
00504                     $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
00505                 }
00506                 break;
00507             case (is_int($val) || is_long($val) || $type == 'int'):
00508                 $this->debug("serialize_val: serialize int");
00509                 if ($use == 'literal') {
00510                     $xml .= "<$name$xmlns$atts>$val</$name>";
00511                 } else {
00512                     $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
00513                 }
00514                 break;
00515             case (is_float($val)|| is_double($val) || $type == 'float'):
00516                 $this->debug("serialize_val: serialize float");
00517                 if ($use == 'literal') {
00518                     $xml .= "<$name$xmlns$atts>$val</$name>";
00519                 } else {
00520                     $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
00521                 }
00522                 break;
00523             case (is_string($val) || $type == 'string'):
00524                 $this->debug("serialize_val: serialize string");
00525                 $val = $this->expandEntities($val);
00526                 if ($use == 'literal') {
00527                     $xml .= "<$name$xmlns$atts>$val</$name>";
00528                 } else {
00529                     $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
00530                 }
00531                 break;
00532             case is_object($val):
00533                 $this->debug("serialize_val: serialize object");
00534                 if (get_class($val) == 'soapval') {
00535                     $this->debug("serialize_val: serialize soapval object");
00536                     $pXml = $val->serialize($use);
00537                     $this->appendDebug($val->getDebug());
00538                     $val->clearDebug();
00539                 } else {
00540                     if (! $name) {
00541                         $name = get_class($val);
00542                         $this->debug("In serialize_val, used class name $name as element name");
00543                     } else {
00544                         $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
00545                     }
00546                     foreach(get_object_vars($val) as $k => $v){
00547                         $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use);
00548                     }
00549                 }
00550                 if(isset($type) && isset($type_prefix)){
00551                     $type_str = " xsi:type=\"$type_prefix:$type\"";
00552                 } else {
00553                     $type_str = '';
00554                 }
00555                 if ($use == 'literal') {
00556                     $xml .= "<$name$xmlns$atts>$pXml</$name>";
00557                 } else {
00558                     $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
00559                 }
00560                 break;
00561             break;
00562             case (is_array($val) || $type):
00563                 // detect if struct or array
00564                 $valueType = $this->isArraySimpleOrStruct($val);
00565                 if($valueType=='arraySimple' || ereg('^ArrayOf',$type)){
00566                     $this->debug("serialize_val: serialize array");
00567                     $i = 0;
00568                     if(is_array($val) && count($val)> 0){
00569                         foreach($val as $v){
00570                             if(is_object($v) && get_class($v) ==  'soapval'){
00571                                 $tt_ns = $v->type_ns;
00572                                 $tt = $v->type;
00573                             } elseif (is_array($v)) {
00574                                 $tt = $this->isArraySimpleOrStruct($v);
00575                             } else {
00576                                 $tt = gettype($v);
00577                             }
00578                             $array_types[$tt] = 1;
00579                             // TODO: for literal, the name should be $name
00580                             $xml .= $this->serialize_val($v,'item',false,false,false,false,$use);
00581                             ++$i;
00582                         }
00583                         if(count($array_types) > 1){
00584                             $array_typename = 'xsd:anyType';
00585                         } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
00586                             if ($tt == 'integer') {
00587                                 $tt = 'int';
00588                             }
00589                             $array_typename = 'xsd:'.$tt;
00590                         } elseif(isset($tt) && $tt == 'arraySimple'){
00591                             $array_typename = 'SOAP-ENC:Array';
00592                         } elseif(isset($tt) && $tt == 'arrayStruct'){
00593                             $array_typename = 'unnamed_struct_use_soapval';
00594                         } else {
00595                             // if type is prefixed, create type prefix
00596                             if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){
00597                                  $array_typename = 'xsd:' . $tt;
00598                             } elseif ($tt_ns) {
00599                                 $tt_prefix = 'ns' . rand(1000, 9999);
00600                                 $array_typename = "$tt_prefix:$tt";
00601                                 $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
00602                             } else {
00603                                 $array_typename = $tt;
00604                             }
00605                         }
00606                         $array_type = $i;
00607                         if ($use == 'literal') {
00608                             $type_str = '';
00609                         } else if (isset($type) && isset($type_prefix)) {
00610                             $type_str = " xsi:type=\"$type_prefix:$type\"";
00611                         } else {
00612                             $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"";
00613                         }
00614                     // empty array
00615                     } else {
00616                         if ($use == 'literal') {
00617                             $type_str = '';
00618                         } else if (isset($type) && isset($type_prefix)) {
00619                             $type_str = " xsi:type=\"$type_prefix:$type\"";
00620                         } else {
00621                             $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
00622                         }
00623                     }
00624                     // TODO: for array in literal, there is no wrapper here
00625                     $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>";
00626                 } else {
00627                     // got a struct
00628                     $this->debug("serialize_val: serialize struct");
00629                     if(isset($type) && isset($type_prefix)){
00630                         $type_str = " xsi:type=\"$type_prefix:$type\"";
00631                     } else {
00632                         $type_str = '';
00633                     }
00634                     if ($use == 'literal') {
00635                         $xml .= "<$name$xmlns$atts>";
00636                     } else {
00637                         $xml .= "<$name$xmlns$type_str$atts>";
00638                     }
00639                     foreach($val as $k => $v){
00640                         // Apache Map
00641                         if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') {
00642                             $xml .= '<item>';
00643                             $xml .= $this->serialize_val($k,'key',false,false,false,false,$use);
00644                             $xml .= $this->serialize_val($v,'value',false,false,false,false,$use);
00645                             $xml .= '</item>';
00646                         } else {
00647                             $xml .= $this->serialize_val($v,$k,false,false,false,false,$use);
00648                         }
00649                     }
00650                     $xml .= "</$name>";
00651                 }
00652                 break;
00653             default:
00654                 $this->debug("serialize_val: serialize unknown");
00655                 $xml .= 'not detected, got '.gettype($val).' for '.$val;
00656                 break;
00657         }
00658         $this->debug("serialize_val returning $xml");
00659         return $xml;
00660     }
00661 
00674     function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'){
00675     // TODO: add an option to automatically run utf8_encode on $body and $headers
00676     // if $this->soap_defencoding is UTF-8.  Not doing this automatically allows
00677     // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1
00678 
00679     $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
00680     $this->debug("headers:");
00681     $this->appendDebug($this->varDump($headers));
00682     $this->debug("namespaces:");
00683     $this->appendDebug($this->varDump($namespaces));
00684 
00685     // serialize namespaces
00686     $ns_string = '';
00687     foreach(array_merge($this->namespaces,$namespaces) as $k => $v){
00688         $ns_string .= " xmlns:$k=\"$v\"";
00689     }
00690     if($encodingStyle) {
00691         $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
00692     }
00693 
00694     // serialize headers
00695     if($headers){
00696         if (is_array($headers)) {
00697             $xml = '';
00698             foreach ($headers as $k => $v) {
00699                 if (is_object($v) && get_class($v) == 'soapval') {
00700                     $xml .= $this->serialize_val($v, false, false, false, false, false, $use);
00701                 } else {
00702                     $xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
00703                 }
00704             }
00705             $headers = $xml;
00706             $this->debug("In serializeEnvelope, serialized array of headers to $headers");
00707         }
00708         $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
00709     }
00710     // serialize envelope
00711     return
00712     '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".
00713     '<SOAP-ENV:Envelope'.$ns_string.">".
00714     $headers.
00715     "<SOAP-ENV:Body>".
00716         $body.
00717     "</SOAP-ENV:Body>".
00718     "</SOAP-ENV:Envelope>";
00719     }
00720 
00729     function formatDump($str){
00730         $str = htmlspecialchars($str);
00731         return nl2br($str);
00732     }
00733 
00741     function contractQname($qname){
00742         // get element namespace
00743         //$this->xdebug("Contract $qname");
00744         if (strrpos($qname, ':')) {
00745             // get unqualified name
00746             $name = substr($qname, strrpos($qname, ':') + 1);
00747             // get ns
00748             $ns = substr($qname, 0, strrpos($qname, ':'));
00749             $p = $this->getPrefixFromNamespace($ns);
00750             if ($p) {
00751                 return $p . ':' . $name;
00752             }
00753             return $qname;
00754         } else {
00755             return $qname;
00756         }
00757     }
00758 
00766     function expandQname($qname){
00767         // get element prefix
00768         if(strpos($qname,':') && !ereg('^http://',$qname)){
00769             // get unqualified name
00770             $name = substr(strstr($qname,':'),1);
00771             // get ns prefix
00772             $prefix = substr($qname,0,strpos($qname,':'));
00773             if(isset($this->namespaces[$prefix])){
00774                 return $this->namespaces[$prefix].':'.$name;
00775             } else {
00776                 return $qname;
00777             }
00778         } else {
00779             return $qname;
00780         }
00781     }
00782 
00791     function getLocalPart($str){
00792         if($sstr = strrchr($str,':')){
00793             // get unqualified name
00794             return substr( $sstr, 1 );
00795         } else {
00796             return $str;
00797         }
00798     }
00799 
00808     function getPrefix($str){
00809         if($pos = strrpos($str,':')){
00810             // get prefix
00811             return substr($str,0,$pos);
00812         }
00813         return false;
00814     }
00815 
00823     function getNamespaceFromPrefix($prefix){
00824         if (isset($this->namespaces[$prefix])) {
00825             return $this->namespaces[$prefix];
00826         }
00827         //$this->setError("No namespace registered for prefix '$prefix'");
00828         return false;
00829     }
00830 
00839     function getPrefixFromNamespace($ns) {
00840         foreach ($this->namespaces as $p => $n) {
00841             if ($ns == $n || $ns == $p) {
00842                 $this->usedNamespaces[$p] = $n;
00843                 return $p;
00844             }
00845         }
00846         return false;
00847     }
00848 
00855     function getmicrotime() {
00856         if (function_exists('gettimeofday')) {
00857             $tod = gettimeofday();
00858             $sec = $tod['sec'];
00859             $usec = $tod['usec'];
00860         } else {
00861             $sec = time();
00862             $usec = 0;
00863         }
00864         return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec);
00865     }
00866 
00874     function varDump($data) {
00875         ob_start();
00876         var_dump($data);
00877         $ret_val = ob_get_contents();
00878         ob_end_clean();
00879         return $ret_val;
00880     }
00881 
00888     function __toString() {
00889         return $this->varDump($this);
00890     }
00891 }
00892 
00893 // XML Schema Datatype Helper Functions
00894 
00895 //xsd:dateTime helpers
00896 
00904 function timestamp_to_iso8601($timestamp,$utc=true){
00905     $datestr = date('Y-m-d\TH:i:sO',$timestamp);
00906     if($utc){
00907         $eregStr =
00908         '([0-9]{4})-'.  // centuries & years CCYY-
00909         '([0-9]{2})-'.  // months MM-
00910         '([0-9]{2})'.   // days DD
00911         'T'.            // separator T
00912         '([0-9]{2}):'.  // hours hh:
00913         '([0-9]{2}):'.  // minutes mm:
00914         '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss...
00915         '(Z|[+\-][0-9]{2}:?[0-9]{2})?'; // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
00916 
00917         if(ereg($eregStr,$datestr,$regs)){
00918             return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]);
00919         }
00920         return false;
00921     } else {
00922         return $datestr;
00923     }
00924 }
00925 
00932 function iso8601_to_timestamp($datestr){
00933     $eregStr =
00934     '([0-9]{4})-'.  // centuries & years CCYY-
00935     '([0-9]{2})-'.  // months MM-
00936     '([0-9]{2})'.   // days DD
00937     'T'.            // separator T
00938     '([0-9]{2}):'.  // hours hh:
00939     '([0-9]{2}):'.  // minutes mm:
00940     '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss...
00941     '(Z|[+\-][0-9]{2}:?[0-9]{2})?'; // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
00942     if(ereg($eregStr,$datestr,$regs)){
00943         // not utc
00944         if($regs[8] != 'Z'){
00945             $op = substr($regs[8],0,1);
00946             $h = substr($regs[8],1,2);
00947             $m = substr($regs[8],strlen($regs[8])-2,2);
00948             if($op == '-'){
00949                 $regs[4] = $regs[4] + $h;
00950                 $regs[5] = $regs[5] + $m;
00951             } elseif($op == '+'){
00952                 $regs[4] = $regs[4] - $h;
00953                 $regs[5] = $regs[5] - $m;
00954             }
00955         }
00956         return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
00957 //      return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
00958     } else {
00959         return false;
00960     }
00961 }
00962 
00970 function usleepWindows($usec)
00971 {
00972     $start = gettimeofday();
00973     
00974     do
00975     {
00976         $stop = gettimeofday();
00977         $timePassed = 1000000 * ($stop['sec'] - $start['sec'])
00978         + $stop['usec'] - $start['usec'];
00979     }
00980     while ($timePassed < $usec);
00981 }
00982 
00983 
00984 ?>