mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-20 16:16:37 +02:00
Merge remote-tracking branch 'EspadaV8/add-fluent-setters-for-slack-handler'
This commit is contained in:
@@ -95,14 +95,15 @@ class SlackRecord
|
|||||||
array $excludeFields = array(),
|
array $excludeFields = array(),
|
||||||
FormatterInterface $formatter = null
|
FormatterInterface $formatter = null
|
||||||
) {
|
) {
|
||||||
$this->channel = $channel;
|
$this
|
||||||
$this->username = $username;
|
->setChannel($channel)
|
||||||
$this->userIcon = $userIcon !== null ? trim($userIcon, ':') : null;
|
->setUsername($username)
|
||||||
$this->useAttachment = $useAttachment;
|
->useAttachment($useAttachment)
|
||||||
$this->useShortAttachment = $useShortAttachment;
|
->setUserIcon($userIcon)
|
||||||
$this->includeContextAndExtra = $includeContextAndExtra;
|
->useShortAttachment($useShortAttachment)
|
||||||
$this->excludeFields = $excludeFields;
|
->includeContextAndExtra($includeContextAndExtra)
|
||||||
$this->formatter = $formatter;
|
->excludeFields($excludeFields)
|
||||||
|
->setFormatter($formatter);
|
||||||
|
|
||||||
if ($this->includeContextAndExtra) {
|
if ($this->includeContextAndExtra) {
|
||||||
$this->normalizerFormatter = new NormalizerFormatter();
|
$this->normalizerFormatter = new NormalizerFormatter();
|
||||||
@@ -116,7 +117,7 @@ class SlackRecord
|
|||||||
public function getSlackData(array $record): array
|
public function getSlackData(array $record): array
|
||||||
{
|
{
|
||||||
$dataArray = array();
|
$dataArray = array();
|
||||||
$record = $this->excludeFields($record);
|
$record = $this->removeExcludedFields($record);
|
||||||
|
|
||||||
if ($this->username) {
|
if ($this->username) {
|
||||||
$dataArray['username'] = $this->username;
|
$dataArray['username'] = $this->username;
|
||||||
@@ -220,7 +221,78 @@ class SlackRecord
|
|||||||
: json_encode($normalized, JSON_UNESCAPED_UNICODE);
|
: json_encode($normalized, JSON_UNESCAPED_UNICODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setFormatter(FormatterInterface $formatter): self
|
/**
|
||||||
|
* Channel used by the bot when posting
|
||||||
|
*
|
||||||
|
* @param ?string $channel
|
||||||
|
*
|
||||||
|
* @return SlackHandler
|
||||||
|
*/
|
||||||
|
public function setChannel(?string $channel = null): self
|
||||||
|
{
|
||||||
|
$this->channel = $channel;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Username used by the bot when posting
|
||||||
|
*
|
||||||
|
* @param ?string $username
|
||||||
|
*
|
||||||
|
* @return SlackHandler
|
||||||
|
*/
|
||||||
|
public function setUsername(?string $username = null): self
|
||||||
|
{
|
||||||
|
$this->username = $username;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function useAttachment(bool $useAttachment = true): self
|
||||||
|
{
|
||||||
|
$this->useAttachment = $useAttachment;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUserIcon(?string $userIcon = null): self
|
||||||
|
{
|
||||||
|
$this->userIcon = $userIcon;
|
||||||
|
|
||||||
|
if (\is_string($userIcon)) {
|
||||||
|
$this->userIcon = trim($userIcon, ':');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function useShortAttachment(bool $useShortAttachment = false): self
|
||||||
|
{
|
||||||
|
$this->useShortAttachment = $useShortAttachment;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function includeContextAndExtra(bool $includeContextAndExtra = false): self
|
||||||
|
{
|
||||||
|
$this->includeContextAndExtra = $includeContextAndExtra;
|
||||||
|
|
||||||
|
if ($this->includeContextAndExtra) {
|
||||||
|
$this->normalizerFormatter = new NormalizerFormatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function excludeFields(array $excludeFields = []): self
|
||||||
|
{
|
||||||
|
$this->excludeFields = $excludeFields;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFormatter(?FormatterInterface $formatter = null): self
|
||||||
{
|
{
|
||||||
$this->formatter = $formatter;
|
$this->formatter = $formatter;
|
||||||
|
|
||||||
@@ -261,7 +333,7 @@ class SlackRecord
|
|||||||
/**
|
/**
|
||||||
* Get a copy of record with fields excluded according to $this->excludeFields
|
* Get a copy of record with fields excluded according to $this->excludeFields
|
||||||
*/
|
*/
|
||||||
private function excludeFields(array $record): array
|
private function removeExcludedFields(array $record): array
|
||||||
{
|
{
|
||||||
foreach ($this->excludeFields as $field) {
|
foreach ($this->excludeFields as $field) {
|
||||||
$keys = explode('.', $field);
|
$keys = explode('.', $field);
|
||||||
|
@@ -174,4 +174,59 @@ class SlackHandler extends SocketHandler
|
|||||||
|
|
||||||
return $formatter;
|
return $formatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Channel used by the bot when posting
|
||||||
|
*/
|
||||||
|
public function setChannel(string $channel): self
|
||||||
|
{
|
||||||
|
$this->slackRecord->setChannel($channel);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Username used by the bot when posting
|
||||||
|
*/
|
||||||
|
public function setUsername(string $username): self
|
||||||
|
{
|
||||||
|
$this->slackRecord->setUsername($username);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function useAttachment(bool $useAttachment): self
|
||||||
|
{
|
||||||
|
$this->slackRecord->useAttachment($useAttachment);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIconEmoji(string $iconEmoji): self
|
||||||
|
{
|
||||||
|
$this->slackRecord->setUserIcon($iconEmoji);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function useShortAttachment(bool $useShortAttachment): self
|
||||||
|
{
|
||||||
|
$this->slackRecord->useShortAttachment($useShortAttachment);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function includeContextAndExtra(bool $includeContextAndExtra): self
|
||||||
|
{
|
||||||
|
$this->slackRecord->includeContextAndExtra($includeContextAndExtra);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function excludeFields(array $excludeFields): self
|
||||||
|
{
|
||||||
|
$this->slackRecord->excludeFields($excludeFields);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user