1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-25 02:26:16 +02:00

Improve build

This commit is contained in:
Jordi Boggiano
2020-12-09 14:22:04 +01:00
parent bd9570d835
commit c5853b9b0f
27 changed files with 127 additions and 72 deletions

View File

@@ -53,6 +53,7 @@ class DynamoDbHandler extends AbstractProcessingHandler
*/
public function __construct(DynamoDbClient $client, string $table, $level = Logger::DEBUG, bool $bubble = true)
{
/** @phpstan-ignore-next-line */
if (defined('Aws\Sdk::VERSION') && version_compare(Sdk::VERSION, '3.0', '>=')) {
$this->version = 3;
$this->marshaler = new Marshaler;

View File

@@ -159,9 +159,14 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
$this->getHandler()->setFormatter($formatter);
$handler = $this->getHandler();
if ($handler instanceof FormattableHandlerInterface) {
$handler->setFormatter($formatter);
return $this;
return $this;
}
throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.');
}
/**
@@ -169,7 +174,12 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese
*/
public function getFormatter(): FormatterInterface
{
return $this->getHandler()->getFormatter();
$handler = $this->getHandler();
if ($handler instanceof FormattableHandlerInterface) {
return $handler->getFormatter();
}
throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.');
}
public function reset()

View File

@@ -202,9 +202,14 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
$this->getHandler()->setFormatter($formatter);
$handler = $this->getHandler();
if ($handler instanceof FormattableHandlerInterface) {
$handler->setFormatter($formatter);
return $this;
return $this;
}
throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.');
}
/**
@@ -212,6 +217,11 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
*/
public function getFormatter(): FormatterInterface
{
return $this->getHandler()->getFormatter();
$handler = $this->getHandler();
if ($handler instanceof FormattableHandlerInterface) {
return $handler->getFormatter();
}
throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.');
}
}

View File

@@ -22,13 +22,12 @@ use Monolog\Formatter\LineFormatter;
trait FormattableHandlerTrait
{
/**
* @var FormatterInterface
* @var ?FormatterInterface
*/
protected $formatter;
/**
* {@inheritdoc}
* @suppress PhanTypeMismatchReturn
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{

View File

@@ -128,7 +128,7 @@ class HandlerWrapper implements HandlerInterface, ProcessableHandlerInterface, F
public function reset()
{
if ($this->handler instanceof ResettableInterface) {
return $this->handler->reset();
$this->handler->reset();
}
}
}

View File

@@ -68,7 +68,7 @@ class LogglyHandler extends AbstractProcessingHandler
protected function getCurlHandler(string $endpoint)
{
if (!array_key_exists($endpoint, $this->curlHandlers)) {
$this->curlHandlers[$endpoint] = $this->loadCurlHandler($endpoint);
$this->curlHandlers[$endpoint] = $this->loadCurlHandle($endpoint);
}
return $this->curlHandlers[$endpoint];
@@ -79,9 +79,9 @@ class LogglyHandler extends AbstractProcessingHandler
*
* @param string $endpoint
*
* @return resource
* @return resource|\CurlHandle
*/
private function loadCurlHandler(string $endpoint)
private function loadCurlHandle(string $endpoint)
{
$url = sprintf("https://%s/%s/%s/", static::HOST, $endpoint, $this->token);

View File

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
use Monolog\Logger;
use Swift;
use Swift_Message;
/**
* MandrillHandler uses cURL to send the emails to the Mandrill API
@@ -21,25 +22,27 @@ use Swift;
*/
class MandrillHandler extends MailHandler
{
/** @var Swift_Message */
protected $message;
/** @var string */
protected $apiKey;
/**
* @psalm-param Swift_Message|callable(string, array): Swift_Message $message
* @psalm-param Swift_Message|callable(): Swift_Message $message
*
* @param string $apiKey A valid Mandrill API key
* @param callable|\Swift_Message $message An example message for real messages, only the body will be replaced
* @param string|int $level The minimum logging level at which this handler will be triggered
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
* @param string $apiKey A valid Mandrill API key
* @param callable|Swift_Message $message An example message for real messages, only the body will be replaced
* @param string|int $level The minimum logging level at which this handler will be triggered
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
*/
public function __construct(string $apiKey, $message, $level = Logger::ERROR, bool $bubble = true)
{
parent::__construct($level, $bubble);
if (!$message instanceof \Swift_Message && is_callable($message)) {
if (!$message instanceof Swift_Message && is_callable($message)) {
$message = $message();
}
if (!$message instanceof \Swift_Message) {
if (!$message instanceof Swift_Message) {
throw new \InvalidArgumentException('You must provide either a Swift_Message instance or a callable returning it');
}
$this->message = $message;
@@ -58,9 +61,11 @@ class MandrillHandler extends MailHandler
$message = clone $this->message;
$message->setBody($content, $mime);
/** @phpstan-ignore-next-line */
if (version_compare(Swift::VERSION, '6.0.0', '>=')) {
$message->setDate(new \DateTimeImmutable());
} else {
/** @phpstan-ignore-next-line */
$message->setDate(time());
}

View File

@@ -131,9 +131,13 @@ class OverflowHandler extends AbstractHandler implements FormattableHandlerInter
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
$this->handler->setFormatter($formatter);
if ($this->handler instanceof FormattableHandlerInterface) {
$this->handler->setFormatter($formatter);
return $this;
return $this;
}
throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.');
}
/**
@@ -141,6 +145,10 @@ class OverflowHandler extends AbstractHandler implements FormattableHandlerInter
*/
public function getFormatter(): FormatterInterface
{
return $this->handler->getFormatter();
if ($this->handler instanceof FormattableHandlerInterface) {
return $this->handler->getFormatter();
}
throw new \UnexpectedValueException('The nested handler of type '.get_class($this->handler).' does not support formatters.');
}
}

View File

@@ -93,9 +93,6 @@ class PHPConsoleHandler extends AbstractProcessingHandler
return array_replace($this->options, $options);
}
/**
* @suppress PhanTypeMismatchArgument
*/
private function initConnector(?Connector $connector = null): Connector
{
if (!$connector) {

View File

@@ -27,7 +27,6 @@ trait ProcessableHandlerTrait
/**
* {@inheritdoc}
* @suppress PhanTypeMismatchReturn
*/
public function pushProcessor(callable $callback): HandlerInterface
{

View File

@@ -100,9 +100,14 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter
*/
public function setFormatter(FormatterInterface $formatter): HandlerInterface
{
$this->getHandler()->setFormatter($formatter);
$handler = $this->getHandler();
if ($handler instanceof FormattableHandlerInterface) {
$handler->setFormatter($formatter);
return $this;
return $this;
}
throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.');
}
/**
@@ -110,6 +115,11 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter
*/
public function getFormatter(): FormatterInterface
{
return $this->getHandler()->getFormatter();
$handler = $this->getHandler();
if ($handler instanceof FormattableHandlerInterface) {
return $handler->getFormatter();
}
throw new \UnexpectedValueException('The nested handler of type '.get_class($handler).' does not support formatters.');
}
}

View File

@@ -77,7 +77,7 @@ class SlackRecord
private $excludeFields;
/**
* @var FormatterInterface
* @var ?FormatterInterface
*/
private $formatter;
@@ -226,7 +226,7 @@ class SlackRecord
*
* @param ?string $channel
*
* @return SlackHandler
* @return static
*/
public function setChannel(?string $channel = null): self
{
@@ -240,7 +240,7 @@ class SlackRecord
*
* @param ?string $username
*
* @return SlackHandler
* @return static
*/
public function setUsername(?string $username = null): self
{

View File

@@ -93,9 +93,11 @@ class SwiftMailerHandler extends MailHandler
}
$message->setBody($content, $mime);
/** @phpstan-ignore-next-line */
if (version_compare(Swift::VERSION, '6.0.0', '>=')) {
$message->setDate(new \DateTimeImmutable());
} else {
/** @phpstan-ignore-next-line */
$message->setDate(time());
}

View File

@@ -94,7 +94,7 @@ class SyslogUdpHandler extends AbstractSyslogHandler
$hostname = '-';
}
if ($this->rfc === self::RFC3164) {
if ($this->rfc === self::RFC3164 && ($datetime instanceof \DateTimeImmutable || $datetime instanceof \DateTime)) {
$datetime->setTimezone(new \DateTimeZone('UTC'));
}
$date = $datetime->format($this->dateFormats[$this->rfc]);

View File

@@ -73,7 +73,7 @@ class ZendMonitorHandler extends AbstractProcessingHandler
* Write to Zend Monitor Events
* @param string $type Text displayed in "Class Name (custom)" field
* @param string $message Text displayed in "Error String"
* @param mixed $formatted Displayed in Custom Variables tab
* @param array $formatted Displayed in Custom Variables tab
* @param int $severity Set the event severity level (-1,0,1)
*/
protected function writeZendMonitorCustomEvent(string $type, string $message, array $formatted, int $severity): void