mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-20 16:16:37 +02:00
Wrap up type-hint adding to all handlers
This commit is contained in:
@@ -48,8 +48,18 @@ class SlackHandler extends SocketHandler
|
||||
* @param array $excludeFields Dot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2']
|
||||
* @throws MissingExtensionException If no OpenSSL PHP extension configured
|
||||
*/
|
||||
public function __construct($token, $channel, $username = null, $useAttachment = true, $iconEmoji = null, $level = Logger::CRITICAL, bool $bubble = true, $useShortAttachment = false, $includeContextAndExtra = false, array $excludeFields = array())
|
||||
{
|
||||
public function __construct(
|
||||
string $token,
|
||||
string $channel,
|
||||
?string $username = null,
|
||||
bool $useAttachment = true,
|
||||
?string $iconEmoji = null,
|
||||
$level = Logger::CRITICAL,
|
||||
bool $bubble = true,
|
||||
bool $useShortAttachment = false,
|
||||
bool $includeContextAndExtra = false,
|
||||
array $excludeFields = array()
|
||||
) {
|
||||
if (!extension_loaded('openssl')) {
|
||||
throw new MissingExtensionException('The OpenSSL PHP extension is required to use the SlackHandler');
|
||||
}
|
||||
@@ -69,23 +79,20 @@ class SlackHandler extends SocketHandler
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public function getSlackRecord()
|
||||
public function getSlackRecord(): SlackRecord
|
||||
{
|
||||
return $this->slackRecord;
|
||||
}
|
||||
|
||||
public function getToken()
|
||||
public function getToken(): string
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param array $record
|
||||
* @return string
|
||||
*/
|
||||
protected function generateDataStream($record)
|
||||
protected function generateDataStream(array $record): string
|
||||
{
|
||||
$content = $this->buildContent($record);
|
||||
|
||||
@@ -94,24 +101,15 @@ class SlackHandler extends SocketHandler
|
||||
|
||||
/**
|
||||
* Builds the body of API call
|
||||
*
|
||||
* @param array $record
|
||||
* @return string
|
||||
*/
|
||||
private function buildContent($record)
|
||||
private function buildContent(array $record): string
|
||||
{
|
||||
$dataArray = $this->prepareContentData($record);
|
||||
|
||||
return http_build_query($dataArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares content data
|
||||
*
|
||||
* @param array $record
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareContentData($record)
|
||||
protected function prepareContentData(array $record): array
|
||||
{
|
||||
$dataArray = $this->slackRecord->getSlackData($record);
|
||||
$dataArray['token'] = $this->token;
|
||||
@@ -125,11 +123,8 @@ class SlackHandler extends SocketHandler
|
||||
|
||||
/**
|
||||
* Builds the header of the API Call
|
||||
*
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
private function buildHeader($content)
|
||||
private function buildHeader(string $content): string
|
||||
{
|
||||
$header = "POST /api/chat.postMessage HTTP/1.1\r\n";
|
||||
$header .= "Host: slack.com\r\n";
|
||||
@@ -142,8 +137,6 @@ class SlackHandler extends SocketHandler
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param array $record
|
||||
*/
|
||||
protected function write(array $record): void
|
||||
{
|
||||
@@ -157,7 +150,7 @@ class SlackHandler extends SocketHandler
|
||||
* If we do not read some but close the socket too early, slack sometimes
|
||||
* drops the request entirely.
|
||||
*/
|
||||
protected function finalizeWrite()
|
||||
protected function finalizeWrite(): void
|
||||
{
|
||||
$res = $this->getResource();
|
||||
if (is_resource($res)) {
|
||||
@@ -166,41 +159,6 @@ class SlackHandler extends SocketHandler
|
||||
$this->closeSocket();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returned a Slack message attachment color associated with
|
||||
* provided level.
|
||||
*
|
||||
* @param int $level
|
||||
* @return string
|
||||
* @deprecated Use underlying SlackRecord instead
|
||||
*/
|
||||
protected function getAttachmentColor($level)
|
||||
{
|
||||
trigger_error(
|
||||
'SlackHandler::getAttachmentColor() is deprecated. Use underlying SlackRecord instead.',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
return $this->slackRecord->getAttachmentColor($level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringifies an array of key/value pairs to be used in attachment fields
|
||||
*
|
||||
* @param array $fields
|
||||
* @return string
|
||||
* @deprecated Use underlying SlackRecord instead
|
||||
*/
|
||||
protected function stringify($fields)
|
||||
{
|
||||
trigger_error(
|
||||
'SlackHandler::stringify() is deprecated. Use underlying SlackRecord instead.',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
return $this->slackRecord->stringify($fields);
|
||||
}
|
||||
|
||||
public function setFormatter(FormatterInterface $formatter): HandlerInterface
|
||||
{
|
||||
parent::setFormatter($formatter);
|
||||
|
Reference in New Issue
Block a user