Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 1325999

Browse files
committed
Merge pull request zendframework/zendframework#2210 from weierophinney/hotfix/remove-suppression-operator
Get rid of error suppression

File tree

3 files changed

+60
-25
lines changed

3 files changed

+60
-25
lines changed

src/Client.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Traversable;
1515
use Zend\Stdlib;
1616
use Zend\Stdlib\ArrayUtils;
17+
use Zend\Stdlib\ErrorHandler;
1718
use Zend\Uri\Http;
1819

1920
/**
@@ -598,11 +599,14 @@ protected function openTempStream()
598599
);
599600
}
600601

601-
if (false === ($fp = @fopen($this->streamName, "w+b"))) {
602+
ErrorHandler::start();
603+
$fp = fopen($this->streamName, "w+b");
604+
$error = ErrorHandler::stop();
605+
if (false === $fp) {
602606
if ($this->adapter instanceof Client\Adapter\AdapterInterface) {
603607
$this->adapter->close();
604608
}
605-
throw new Exception\RuntimeException("Could not open temp file {$this->streamName}");
609+
throw new Exception\RuntimeException("Could not open temp file {$this->streamName}", 0, $error);
606610
}
607611

608612
return $fp;
@@ -926,8 +930,11 @@ public function send(Request $request = null)
926930
public function setFileUpload($filename, $formname, $data = null, $ctype = null)
927931
{
928932
if ($data === null) {
929-
if (($data = @file_get_contents($filename)) === false) {
930-
throw new Exception\RuntimeException("Unable to read file '{$filename}' for upload");
933+
ErrorHandler::start();
934+
$data = file_get_contents($filename);
935+
$error = ErrorHandler::stop();
936+
if ($data === false) {
937+
throw new Exception\RuntimeException("Unable to read file '{$filename}' for upload", 0, $error);
931938
}
932939
if (!$ctype) {
933940
$ctype = $this->detectFileMimeType($filename);
@@ -1156,7 +1163,9 @@ protected function detectFileMimeType($file)
11561163
// First try with fileinfo functions
11571164
if (function_exists('finfo_open')) {
11581165
if (self::$fileInfoDb === null) {
1159-
self::$fileInfoDb = @finfo_open(FILEINFO_MIME);
1166+
ErrorHandler::start();
1167+
self::$fileInfoDb = finfo_open(FILEINFO_MIME);
1168+
ErrorHandler::stop();
11601169
}
11611170

11621171
if (self::$fileInfoDb) {

src/Client/Adapter/Proxy.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
use Zend\Http\Client;
1414
use Zend\Http\Client\Adapter\Exception as AdapterException;
15+
use Zend\Http\Response;
16+
use Zend\Stdlib\ErrorHandler;
1517

1618
/**
1719
* HTTP Proxy-supporting Zend_Http_Client adapter class, based on the default
@@ -154,8 +156,11 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
154156
}
155157

156158
// Send the request
157-
if (! @fwrite($this->socket, $request)) {
158-
throw new AdapterException\RuntimeException("Error writing request to proxy server");
159+
ErrorHandler::start();
160+
$test = fwrite($this->socket, $request);
161+
$error = ErrorHandler::stop();
162+
if (!$test) {
163+
throw new AdapterException\RuntimeException("Error writing request to proxy server", 0, $error);
159164
}
160165

161166
if (is_resource($body)) {
@@ -195,23 +200,28 @@ protected function connectHandshake($host, $port = 443, $http_ver = '1.1', array
195200
$request .= "\r\n";
196201

197202
// Send the request
198-
if (! @fwrite($this->socket, $request)) {
199-
throw new AdapterException\RuntimeException("Error writing request to proxy server");
203+
ErrorHandler::start();
204+
$test = fwrite($this->socket, $request);
205+
$error = ErrorHandler::stop();
206+
if (!$test) {
207+
throw new AdapterException\RuntimeException("Error writing request to proxy server", 0, $error);
200208
}
201209

202210
// Read response headers only
203211
$response = '';
204212
$gotStatus = false;
205-
while ($line = @fgets($this->socket)) {
213+
ErrorHandler::start();
214+
while ($line = fgets($this->socket)) {
206215
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
207216
if ($gotStatus) {
208217
$response .= $line;
209218
if (!rtrim($line)) break;
210219
}
211220
}
221+
ErrorHandler::stop();
212222

213223
// Check that the response from the proxy is 200
214-
if (\Zend\Http\Response::extractCode($response) != 200) {
224+
if (Response::extractCode($response) != 200) {
215225
throw new AdapterException\RuntimeException("Unable to connect to HTTPS proxy. Server response: " . $response);
216226
}
217227

src/Client/Adapter/Socket.php

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Zend\Http\Client\Adapter\Exception as AdapterException;
1616
use Zend\Http\Response;
1717
use Zend\Stdlib\ArrayUtils;
18+
use Zend\Stdlib\ErrorHandler;
1819

1920
/**
2021
* A sockets based (stream\socket\client) adapter class for Zend\Http\Client. Can be used
@@ -218,19 +219,25 @@ public function connect($host, $port = 80, $secure = false)
218219
$flags = STREAM_CLIENT_CONNECT;
219220
if ($this->config['persistent']) $flags |= STREAM_CLIENT_PERSISTENT;
220221

221-
$errno = null;
222-
$errstr = '';
223-
$this->socket = @stream_socket_client($host . ':' . $port,
224-
$errno,
225-
$errstr,
226-
(int) $this->config['timeout'],
227-
$flags,
228-
$context);
222+
ErrorHandler::start();
223+
$this->socket = stream_socket_client(
224+
$host . ':' . $port,
225+
$errno,
226+
$errstr,
227+
(int) $this->config['timeout'],
228+
$flags,
229+
$context
230+
);
231+
$error = ErrorHandler::stop();
229232

230233
if (! $this->socket) {
231234
$this->close();
232-
throw new AdapterException\RuntimeException(
233-
'Unable to Connect to ' . $host . ':' . $port . '. Error #' . $errno . ': ' . $errstr);
235+
throw new AdapterException\RuntimeException(sprintf(
236+
'Unable to connect to %s:%d%s',
237+
$host,
238+
$port
239+
($error ? '. Error #' . $error->getCode() . ': ' . $error->getMessage() : '')
240+
), 0, $error);
234241
}
235242

236243
// Set the stream timeout
@@ -287,8 +294,11 @@ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $bod
287294
}
288295

289296
// Send the request
290-
if (! @fwrite($this->socket, $request)) {
291-
throw new AdapterException\RuntimeException('Error writing request to server');
297+
ErrorHandler::start();
298+
$test = fwrite($this->socket, $request);
299+
$error = ErrorHandler::stop();
300+
if (!test) {
301+
throw new AdapterException\RuntimeException('Error writing request to server', 0, $error);
292302
}
293303

294304
if (is_resource($body)) {
@@ -392,7 +402,9 @@ public function read()
392402
}
393403
} while (! feof($this->socket));
394404

395-
$chunk .= @fgets($this->socket);
405+
ErrorHandler::start();
406+
$chunk .= fgets($this->socket);
407+
ErrorHandler::stop();
396408
$this->_checkSocketReadTimeout();
397409

398410
if (!$this->out_stream) {
@@ -485,7 +497,11 @@ public function read()
485497
*/
486498
public function close()
487499
{
488-
if (is_resource($this->socket)) @fclose($this->socket);
500+
if (is_resource($this->socket)) {
501+
ErrorHandler::start();
502+
fclose($this->socket);
503+
ErrorHandler::stop();
504+
}
489505
$this->socket = null;
490506
$this->connected_to = array(null, null);
491507
}

0 commit comments

Comments
 (0)