mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-03 11:47:38 +02:00
Remove SocketHandler's ConnecitonException and WriteToSocketException - replace them with \UnexpectedValueException and \RuntimeException respectively
This commit is contained in:
@@ -12,8 +12,6 @@
|
|||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Monolog\Handler\SocketHandler\Exception\ConnectionException;
|
|
||||||
use Monolog\Handler\SocketHandler\Exception\WriteToSocketException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores to any socket - uses fsockopen() or pfsockopen().
|
* Stores to any socket - uses fsockopen() or pfsockopen().
|
||||||
@@ -47,8 +45,8 @@ class SocketHandler extends AbstractProcessingHandler
|
|||||||
/**
|
/**
|
||||||
* Connect (if necessary) and write to the socket
|
* Connect (if necessary) and write to the socket
|
||||||
*
|
*
|
||||||
* @throws Monolog\Handler\SocketHandler\Exception\ConnectionException
|
* @throws \UnexpectedValueException
|
||||||
* @throws Monolog\Handler\SocketHandler\Exception\WriteToSocketException
|
* @throws \RuntimeException
|
||||||
* @param string $string
|
* @param string $string
|
||||||
*/
|
*/
|
||||||
public function write(array $record)
|
public function write(array $record)
|
||||||
@@ -170,7 +168,7 @@ class SocketHandler extends AbstractProcessingHandler
|
|||||||
$resource = $this->fsockopen();
|
$resource = $this->fsockopen();
|
||||||
}
|
}
|
||||||
if (!$resource) {
|
if (!$resource) {
|
||||||
throw new ConnectionException("Failed connecting to $this->connectionString ($this->errno: $this->errstr)");
|
throw new \UnexpectedValueException("Failed connecting to $this->connectionString ($this->errno: $this->errstr)");
|
||||||
}
|
}
|
||||||
return $this->resource = $resource;
|
return $this->resource = $resource;
|
||||||
}
|
}
|
||||||
@@ -178,7 +176,7 @@ class SocketHandler extends AbstractProcessingHandler
|
|||||||
private function setSocketTimeout()
|
private function setSocketTimeout()
|
||||||
{
|
{
|
||||||
if (!$this->stream_set_timeout()) {
|
if (!$this->stream_set_timeout()) {
|
||||||
throw new ConnectionException("Failed setting timeout with stream_set_timeout()");
|
throw new \UnexpectedValueException("Failed setting timeout with stream_set_timeout()");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,16 +187,16 @@ class SocketHandler extends AbstractProcessingHandler
|
|||||||
while ($this->isConnected() && $sent < $length) {
|
while ($this->isConnected() && $sent < $length) {
|
||||||
$chunk = $this->fwrite(substr($data, $sent));
|
$chunk = $this->fwrite(substr($data, $sent));
|
||||||
if ($chunk === false) {
|
if ($chunk === false) {
|
||||||
throw new WriteToSocketException("Could not write to socket");
|
throw new \RuntimeException("Could not write to socket");
|
||||||
}
|
}
|
||||||
$sent += $chunk;
|
$sent += $chunk;
|
||||||
$socketInfo = $this->stream_get_meta_data();
|
$socketInfo = $this->stream_get_meta_data();
|
||||||
if ($socketInfo['timed_out']) {
|
if ($socketInfo['timed_out']) {
|
||||||
throw new WriteToSocketException("Write timed-out");
|
throw new \RuntimeException("Write timed-out");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$this->isConnected() && $sent < $length) {
|
if (!$this->isConnected() && $sent < $length) {
|
||||||
throw new WriteToSocketException("End-of-file reached, probably we got disconnected (sent $sent of $length)");
|
throw new \RuntimeException("End-of-file reached, probably we got disconnected (sent $sent of $length)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Monolog package.
|
|
||||||
*
|
|
||||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Monolog\Handler\SocketHandler\Exception;
|
|
||||||
|
|
||||||
class ConnectionException extends \RuntimeException
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Monolog package.
|
|
||||||
*
|
|
||||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Monolog\Handler\SocketHandler\Exception;
|
|
||||||
|
|
||||||
class WriteToSocketException extends \RuntimeException
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@@ -13,8 +13,6 @@ namespace Monolog\Handler;
|
|||||||
|
|
||||||
use Monolog\TestCase;
|
use Monolog\TestCase;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Monolog\Handler\SocketHandler\Exception\ConnectionException;
|
|
||||||
use Monolog\Handler\SocketHandler\Exception\WriteToSocketException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pablo de Leon Belloc <pablolb@gmail.com>
|
* @author Pablo de Leon Belloc <pablolb@gmail.com>
|
||||||
@@ -33,7 +31,7 @@ class SocketHandlerTest extends TestCase
|
|||||||
private $res;
|
private $res;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Monolog\Handler\SocketHandler\Exception\ConnectionException
|
* @expectedException UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
public function testInvalidHostname()
|
public function testInvalidHostname()
|
||||||
{
|
{
|
||||||
@@ -86,13 +84,13 @@ class SocketHandlerTest extends TestCase
|
|||||||
$string = 'Hello world';
|
$string = 'Hello world';
|
||||||
$this->writeRecord($string);
|
$this->writeRecord($string);
|
||||||
$this->fail("Shoul not connect - are you running a server on 127.0.0.1:7894 ?");
|
$this->fail("Shoul not connect - are you running a server on 127.0.0.1:7894 ?");
|
||||||
} catch (\Monolog\Handler\SocketHandler\Exception\ConnectionException $e) {
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Monolog\Handler\SocketHandler\Exception\ConnectionException
|
* @expectedException UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
public function testExceptionIsThrownOnFsockopenError()
|
public function testExceptionIsThrownOnFsockopenError()
|
||||||
{
|
{
|
||||||
@@ -104,7 +102,7 @@ class SocketHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Monolog\Handler\SocketHandler\Exception\ConnectionException
|
* @expectedException UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
public function testExceptionIsThrownOnPfsockopenError()
|
public function testExceptionIsThrownOnPfsockopenError()
|
||||||
{
|
{
|
||||||
@@ -117,7 +115,7 @@ class SocketHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Monolog\Handler\SocketHandler\Exception\ConnectionException
|
* @expectedException UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
public function testExceptionIsThrownIfCannotSetTimeout()
|
public function testExceptionIsThrownIfCannotSetTimeout()
|
||||||
{
|
{
|
||||||
@@ -129,7 +127,7 @@ class SocketHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Monolog\Handler\SocketHandler\Exception\WriteToSocketException
|
* @expectedException RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testWriteFailsOnIfFwriteReturnsFalse()
|
public function testWriteFailsOnIfFwriteReturnsFalse()
|
||||||
{
|
{
|
||||||
@@ -148,7 +146,7 @@ class SocketHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Monolog\Handler\SocketHandler\Exception\WriteToSocketException
|
* @expectedException RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testWriteFailsIfStreamTimesOut()
|
public function testWriteFailsIfStreamTimesOut()
|
||||||
{
|
{
|
||||||
@@ -171,7 +169,7 @@ class SocketHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Monolog\Handler\SocketHandler\Exception\WriteToSocketException
|
* @expectedException RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testWriteFailsOnIncompleteWrite()
|
public function testWriteFailsOnIncompleteWrite()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user