|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZSOAPCodec class 00004 // 00005 // Created on: <03-Jan-2006 10:12:37 hovik> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezsoapcodec.php 00032 */ 00033 00034 /*! 00035 \class eZSOAPCodec ezsoapcodec.php 00036 \brief The class eZSOAPCodec does 00037 00038 */ 00039 00040 class eZSOAPCodec 00041 { 00042 /*! 00043 Constructor 00044 */ 00045 function eZSOAPCodec() 00046 { 00047 } 00048 00049 /*! 00050 \static 00051 Encodes a PHP variable into a SOAP datatype. 00052 */ 00053 static function encodeValue( $doc, $name, $value ) 00054 { 00055 switch ( gettype( $value ) ) 00056 { 00057 case "string" : 00058 { 00059 $node = $doc->createElement( $name ); 00060 $node->appendChild( $doc->createTextNode( $value ) ); 00061 $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type', 00062 eZSOAPEnvelope::XSD_PREFIX . ':string' ); 00063 return $node; 00064 } break; 00065 00066 case "boolean" : 00067 { 00068 $node = $doc->createElement( $name ); 00069 $node->appendChild( $doc->createTextNode( $value ? 'true' : 'false' ) ); 00070 $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type', 00071 eZSOAPEnvelope::XSD_PREFIX . ':boolean' ); 00072 return $node; 00073 } break; 00074 00075 case "integer" : 00076 { 00077 $node = $doc->createElement( $name ); 00078 $node->appendChild( $doc->createTextNode( $value ) ); 00079 $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type', 00080 eZSOAPEnvelope::XSD_PREFIX . ':int' ); 00081 return $node; 00082 } break; 00083 00084 case "double" : 00085 { 00086 $node = $doc->createElement( $name ); 00087 $node->appendChild( $doc->createTextNode( $value ) ); 00088 $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type', 00089 eZSOAPEnvelope::XSD_PREFIX . ':float' ); 00090 return $node; 00091 } break; 00092 00093 case "array" : 00094 { 00095 $arrayCount = count( $value ); 00096 00097 $isStruct = false; 00098 // Check for struct 00099 $i = 0; 00100 foreach( $value as $key => $val ) 00101 { 00102 if ( $i !== $key ) 00103 { 00104 $isStruct = true; 00105 break; 00106 } 00107 $i++; 00108 } 00109 00110 if ( $isStruct == true ) 00111 { 00112 $node = $doc->createElement( $name ); 00113 $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type', 00114 eZSOAPEnvelope::ENC_PREFIX . ':SOAPStruct' ); 00115 00116 foreach( $value as $key => $val ) 00117 { 00118 $subNode = eZSOAPCodec::encodeValue( $doc, (string)$key, $val ); 00119 $node->appendChild( $subNode ); 00120 } 00121 return $node; 00122 } 00123 else 00124 { 00125 $node = $doc->createElement( $name ); 00126 $node->setAttribute( eZSOAPEnvelope::XSI_PREFIX . ':type', 00127 eZSOAPEnvelope::ENC_PREFIX . ':Array' ); 00128 $node->setAttribute( eZSOAPEnvelope::ENC_PREFIX . ':arrayType', 00129 eZSOAPEnvelope::XSD_PREFIX . ":string[$arrayCount]" ); 00130 00131 foreach ( $value as $arrayItem ) 00132 { 00133 $subNode = eZSOAPCodec::encodeValue( $doc, "item", $arrayItem ); 00134 $node->appendChild( $subNode ); 00135 } 00136 00137 return $node; 00138 } 00139 } break; 00140 } 00141 00142 return false; 00143 } 00144 } 00145 00146 ?>