diff --git a/src/Monolog/Handler/Curl/Util.php b/src/Monolog/Handler/Curl/Util.php index b0aeac9c..cc0b6c39 100644 --- a/src/Monolog/Handler/Curl/Util.php +++ b/src/Monolog/Handler/Curl/Util.php @@ -11,6 +11,8 @@ namespace Monolog\Handler\Curl; +use CurlHandle; + /** * This class is marked as internal and it is not under the BC promise of the package. * @@ -31,10 +33,10 @@ final class Util /** * Executes a CURL request with optional retries and exception on failure * - * @param resource $ch curl handler - * @param int $retries - * @param bool $closeAfterDone - * @return bool|string @see curl_exec + * @param resource|CurlHandle $ch curl handler + * @param int $retries + * @param bool $closeAfterDone + * @return bool|string @see curl_exec */ public static function execute($ch, int $retries = 5, bool $closeAfterDone = true) { diff --git a/src/Monolog/Handler/LogglyHandler.php b/src/Monolog/Handler/LogglyHandler.php index 19710d93..6fc7066c 100644 --- a/src/Monolog/Handler/LogglyHandler.php +++ b/src/Monolog/Handler/LogglyHandler.php @@ -15,6 +15,7 @@ use Monolog\Logger; use Monolog\Formatter\FormatterInterface; use Monolog\Formatter\LogglyFormatter; use function array_key_exists; +use CurlHandle; /** * Sends errors to Loggly. @@ -32,7 +33,7 @@ class LogglyHandler extends AbstractProcessingHandler /** * Caches the curl handlers for every given endpoint. * - * @var array + * @var resource[]|CurlHandle[] */ protected $curlHandlers = []; @@ -63,7 +64,7 @@ class LogglyHandler extends AbstractProcessingHandler * * @param string $endpoint * - * @return resource + * @return resource|CurlHandle */ protected function getCurlHandler(string $endpoint) { @@ -79,7 +80,7 @@ class LogglyHandler extends AbstractProcessingHandler * * @param string $endpoint * - * @return resource|\CurlHandle + * @return resource|CurlHandle */ private function loadCurlHandle(string $endpoint) { diff --git a/src/Monolog/Handler/SyslogUdp/UdpSocket.php b/src/Monolog/Handler/SyslogUdp/UdpSocket.php index 371edb49..33696d7a 100644 --- a/src/Monolog/Handler/SyslogUdp/UdpSocket.php +++ b/src/Monolog/Handler/SyslogUdp/UdpSocket.php @@ -12,6 +12,7 @@ namespace Monolog\Handler\SyslogUdp; use Monolog\Utils; +use Socket; class UdpSocket { @@ -21,7 +22,7 @@ class UdpSocket protected $ip; /** @var int */ protected $port; - /** @var resource|null */ + /** @var resource|Socket|null */ protected $socket; public function __construct(string $ip, int $port = 514) @@ -35,7 +36,7 @@ class UdpSocket $domain = AF_UNIX; $protocol = IPPROTO_IP; } - $this->socket = socket_create($domain, SOCK_DGRAM, $protocol); + $this->socket = socket_create($domain, SOCK_DGRAM, $protocol) ?: null; } public function write($line, $header = "") @@ -45,7 +46,7 @@ class UdpSocket public function close(): void { - if (is_resource($this->socket)) { + if (is_resource($this->socket) || $this->socket instanceof Socket) { socket_close($this->socket); $this->socket = null; } @@ -53,7 +54,7 @@ class UdpSocket protected function send(string $chunk): void { - if (!is_resource($this->socket)) { + if (!is_resource($this->socket) && !$this->socket instanceof Socket) { throw new \RuntimeException('The UdpSocket to '.$this->ip.':'.$this->port.' has been closed and can not be written to anymore'); } socket_sendto($this->socket, $chunk, strlen($chunk), $flags = 0, $this->ip, $this->port);