Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezsoapclient.php
Go to the documentation of this file.
1 <?php
48 class eZSOAPClient
49 {
50 public $errorNumber;
51 public $errorString;
55 public $ErrorString;
66 public function __construct( $server, $path = '/', $port = 80, $useSSL = null )
67 {
68 $this->Login = "";
69 $this->Password = "";
70 $this->Server = $server;
71 $this->Path = $path;
72 $this->Port = $port;
73 if ( is_numeric( $port ) )
74 {
75 $this->Port = $port;
76
77 if ( $port == 443 )
78 {
79 $this->UseSSL = true;
80 }
81 }
82 elseif ( strtolower( $port ) == 'ssl' )
83 {
84 $this->UseSSL = true;
85 $this->Port = 443;
86 }
87 else
88 {
89 $this->Port = 80;
90 }
91
92 if ( $useSSL === true )
93 {
94 $this->UseSSL = true;
95 }
96 else if ( $useSSL === false )
97 {
98 $this->UseSSL = false;
99 }
100 }
101
105 function send( $request )
106 {
107 if ( !$this->UseSSL || !in_array( "curl", get_loaded_extensions() ) )
108 {
109 if ( $this->Timeout != 0 )
110 {
111 $fp = fsockopen( $this->Server,
112 $this->Port,
113 $this->errorNumber,
114 $this->errorString,
115 $this->Timeout );
116 }
117 else
118 {
119 $fp = fsockopen( $this->Server,
120 $this->Port,
121 $this->errorNumber,
122 $this->errorString );
123 }
124
125 if ( $fp == 0 )
126 {
127 $this->ErrorString = '<b>Error:</b> eZSOAPClient::send() : Unable to open connection to ' . $this->Server . '.';
128 return 0;
129 }
130
131 $payload = $request->payload();
132
133 $authentification = "";
134 if ( ( $this->login() != "" ) )
135 {
136 $authentification = "Authorization: Basic " . base64_encode( $this->login() . ":" . $this->password() ) . "\r\n" ;
137 }
138
139 $HTTPRequest = "POST " . $this->Path . " HTTP/1.0\r\n" .
140 "User-Agent: eZ soap client\r\n" .
141 "Host: " . $this->Server . ":" . $this->Port . "\r\n" .
142 $authentification .
143 "Content-Type: text/xml\r\n" .
144 "SOAPAction: \"" . $request->ns() . '/' . $request->name() . "\"\r\n" .
145 "Content-Length: " . strlen( $payload ) . "\r\n\r\n" .
146 $payload;
147
148 if ( !fputs( $fp, $HTTPRequest, strlen( $HTTPRequest ) ) )
149 {
150 $this->ErrorString = "<b>Error:</b> could not send the SOAP request. Could not write to the socket.";
151 $response = 0;
152 return $response;
153 }
154
155 $rawResponse = "";
156 // fetch the SOAP response
157 while ( $data = fread( $fp, 32768 ) )
158 {
159 $rawResponse .= $data;
160 }
161
162 // close the socket
163 fclose( $fp );
164 }
165 else //SOAP With SSL
166 {
167 if ( $request instanceof eZSOAPRequest )
168 {
169 $URL = "https://" . $this->Server . ":" . $this->Port . $this->Path;
170 $ch = curl_init ( $URL );
171 if ( $this->Timeout != 0 )
172 {
173 curl_setopt( $ch, CURLOPT_TIMEOUT, $this->Timeout );
174 }
175 $payload = $request->payload();
176
177 if ( $ch != 0 )
178 {
179 $HTTPCall = "POST " . $this->Path . " HTTP/1.0\r\n" .
180 "User-Agent: eZ soap client\r\n" .
181 "Host: " . $this->Server . ":" . $this->Port . "\r\n" .
182 "Content-Type: text/xml\r\n" .
183 "SOAPAction: \"" . $request->ns() . '/' . $request->name() . "\"\r\n" .
184 "Content-Length: " . strlen( $payload ) . "\r\n";
185 if ( $this->login() != '' )
186 {
187 $HTTPCall .= "Authorization: Basic " . base64_encode( $this->login() . ":" . $this->Password() ) . "\r\n";
188 }
189 $HTTPCall .= "\r\n" . $payload;
190
191 curl_setopt( $ch, CURLOPT_URL, $URL );
192 curl_setopt( $ch, CURLOPT_HEADER, 1 );
193 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
194 curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $HTTPCall ); // Don't use CURLOPT_CUSTOMREQUEST without making sure your server supports the custom request method first.
195 unset( $rawResponse );
196
197 if ( $ch != 0 )
198 {
199 $rawResponse = curl_exec( $ch );
200 }
201 if ( !$rawResponse )
202 {
203 $this->ErrorString = "<b>Error:</b> could not send the XML-SOAP with SSL call. Could not write to the socket.";
204 $response = 0;
205 return $response;
206 }
207 }
208
209 curl_close( $ch );
210 }
211 }
212 $response = new eZSOAPResponse();
213 $response->decodeStream( $request, $rawResponse );
214 return $response;
215 }
216
222 function setTimeout( $timeout )
223 {
224 $this->Timeout = $timeout;
225 }
226
230 function setLogin( $login )
231 {
232 $this->Login = $login;
233 }
234
238 function login()
239 {
240 return $this->Login;
241 }
242
246 function setPassword( $password )
247 {
248 $this->Password = $password;
249 }
250
254 function password()
255 {
256 return $this->Password;
257 }
258
260 public $Server;
262 public $Path;
264 public $Port;
266 public $Timeout = 0;
268 public $Login;
270 public $Password;
271 private $UseSSL;
272 }
273
274 ?>
eZSOAPClient
eZSOAPClient is a class which can be used as a SOAP client
Definition: ezsoapclient.php:49
eZSOAPClient\login
login()
Definition: ezsoapclient.php:238
eZSOAPClient\$Password
$Password
HTTP password for HTTP authentification.
Definition: ezsoapclient.php:270
eZSOAPClient\$Port
$Port
The port of the server to communicate with.
Definition: ezsoapclient.php:264
eZSOAPClient\$Timeout
$Timeout
How long to wait for the call.
Definition: ezsoapclient.php:266
eZSOAPClient\$errorString
$errorString
Definition: ezsoapclient.php:51
eZSOAPClient\setPassword
setPassword( $password)
Definition: ezsoapclient.php:246
eZSOAPClient\password
password()
Definition: ezsoapclient.php:254
eZSOAPClient\$Server
$Server
The name or IP of the server to communicate with.
Definition: ezsoapclient.php:260
eZSOAPClient\__construct
__construct( $server, $path='/', $port=80, $useSSL=null)
Definition: ezsoapclient.php:66
eZSOAPClient\setLogin
setLogin( $login)
Definition: ezsoapclient.php:230
eZSOAPClient\$errorNumber
$errorNumber
Definition: ezsoapclient.php:50
eZSOAPClient\$UseSSL
$UseSSL
Definition: ezsoapclient.php:271
eZSOAPClient\$Login
$Login
HTTP login for HTTP authentification.
Definition: ezsoapclient.php:268
eZSOAPClient\$Path
$Path
The path to the SOAP server.
Definition: ezsoapclient.php:262
eZSOAPClient\$ErrorString
$ErrorString
Definition: ezsoapclient.php:55
eZSOAPClient\setTimeout
setTimeout( $timeout)
Definition: ezsoapclient.php:222
eZSOAPClient\send
send( $request)
Definition: ezsoapclient.php:105
eZSOAPRequest
eZSOAPRequest handles SOAP request messages
Definition: ezsoaprequest.php:19
eZSOAPResponse
eZSOAPResponse handles SOAP response packages
Definition: ezsoapresponse.php:19
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.