SlackRecord
in package
Slack record utility helping to log to Slack webhooks or API.
Tags
Table of Contents
- COLOR_DANGER = 'danger'
- COLOR_DEFAULT = '#e3e4e6'
- COLOR_GOOD = 'good'
- COLOR_WARNING = 'warning'
- $channel : string|null
- Slack channel (encoded ID or name)
- $excludeFields : array<string|int, string>
- Dot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2']
- $formatter : FormatterInterface|null
- $includeContextAndExtra : bool
- Whether the attachment should include context and extra data
- $normalizerFormatter : NormalizerFormatter
- $useAttachment : bool
- Whether the message should be added to Slack as attachment (plain text otherwise)
- $userIcon : string|null
- User icon e.g. 'ghost', 'http://example.com/user.png'
- $username : string|null
- Name of a bot
- $useShortAttachment : bool
- Whether the the context/extra messages added to Slack as attachments are in a short style
- __construct() : mixed
- excludeFields() : self
- getAttachmentColor() : string
- Returns a Slack message attachment color associated with provided level.
- getSlackData() : array<string|int, mixed>
- Returns required data in format that Slack is expecting.
- includeContextAndExtra() : self
- setChannel() : static
- Channel used by the bot when posting
- setFormatter() : self
- setUserIcon() : self
- setUsername() : static
- Username used by the bot when posting
- stringify() : string
- Stringifies an array of key/value pairs to be used in attachment fields
- useAttachment() : self
- useShortAttachment() : self
- generateAttachmentField() : array{title: string, value: string, short: false}
- Generates attachment field
- generateAttachmentFields() : array<string|int, array{title: string, value: string, short: false}>
- Generates a collection of attachment fields from array
- removeExcludedFields() : array<string|int, mixed>
- Get a copy of record with fields excluded according to $this->excludeFields
Constants
COLOR_DANGER
public
mixed
COLOR_DANGER
= 'danger'
COLOR_DEFAULT
public
mixed
COLOR_DEFAULT
= '#e3e4e6'
COLOR_GOOD
public
mixed
COLOR_GOOD
= 'good'
COLOR_WARNING
public
mixed
COLOR_WARNING
= 'warning'
Properties
$channel
Slack channel (encoded ID or name)
private
string|null
$channel
$excludeFields
Dot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2']
private
array<string|int, string>
$excludeFields
$formatter
private
FormatterInterface|null
$formatter
$includeContextAndExtra
Whether the attachment should include context and extra data
private
bool
$includeContextAndExtra
$normalizerFormatter
private
NormalizerFormatter
$normalizerFormatter
$useAttachment
Whether the message should be added to Slack as attachment (plain text otherwise)
private
bool
$useAttachment
$userIcon
User icon e.g. 'ghost', 'http://example.com/user.png'
private
string|null
$userIcon
$username
Name of a bot
private
string|null
$username
$useShortAttachment
Whether the the context/extra messages added to Slack as attachments are in a short style
private
bool
$useShortAttachment
Methods
__construct()
public
__construct([string|null $channel = null ][, string|null $username = null ][, bool $useAttachment = true ][, string|null $userIcon = null ][, bool $useShortAttachment = false ][, bool $includeContextAndExtra = false ][, array<string|int, string> $excludeFields = array() ][, FormatterInterface|null $formatter = null ]) : mixed
Parameters
- $channel : string|null = null
- $username : string|null = null
- $useAttachment : bool = true
- $userIcon : string|null = null
- $useShortAttachment : bool = false
- $includeContextAndExtra : bool = false
- $excludeFields : array<string|int, string> = array()
- $formatter : FormatterInterface|null = null
Return values
mixed —excludeFields()
public
excludeFields([array<string|int, string> $excludeFields = [] ]) : self
Parameters
- $excludeFields : array<string|int, string> = []
Return values
self —getAttachmentColor()
Returns a Slack message attachment color associated with provided level.
public
getAttachmentColor(int $level) : string
Parameters
- $level : int
Return values
string —getSlackData()
Returns required data in format that Slack is expecting.
public
getSlackData(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
- $record : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —includeContextAndExtra()
public
includeContextAndExtra([bool $includeContextAndExtra = false ]) : self
Parameters
- $includeContextAndExtra : bool = false
Return values
self —setChannel()
Channel used by the bot when posting
public
setChannel([string|null $channel = null ]) : static
Parameters
- $channel : string|null = null
Return values
static —setFormatter()
public
setFormatter([FormatterInterface|null $formatter = null ]) : self
Parameters
- $formatter : FormatterInterface|null = null
Return values
self —setUserIcon()
public
setUserIcon([string|null $userIcon = null ]) : self
Parameters
- $userIcon : string|null = null
Return values
self —setUsername()
Username used by the bot when posting
public
setUsername([string|null $username = null ]) : static
Parameters
- $username : string|null = null
Return values
static —stringify()
Stringifies an array of key/value pairs to be used in attachment fields
public
stringify(array<string|int, mixed> $fields) : string
Parameters
- $fields : array<string|int, mixed>
Return values
string —useAttachment()
public
useAttachment([bool $useAttachment = true ]) : self
Parameters
- $useAttachment : bool = true
Return values
self —useShortAttachment()
public
useShortAttachment([bool $useShortAttachment = false ]) : self
Parameters
- $useShortAttachment : bool = false
Return values
self —generateAttachmentField()
Generates attachment field
private
generateAttachmentField(string $title, string|array<string|int, mixed> $value) : array{title: string, value: string, short: false}
Parameters
- $title : string
- $value : string|array<string|int, mixed>
Return values
array{title: string, value: string, short: false} —generateAttachmentFields()
Generates a collection of attachment fields from array
private
generateAttachmentFields(array<string|int, mixed> $data) : array<string|int, array{title: string, value: string, short: false}>
Parameters
- $data : array<string|int, mixed>
Return values
array<string|int, array{title: string, value: string, short: false}> —removeExcludedFields()
Get a copy of record with fields excluded according to $this->excludeFields
private
removeExcludedFields(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
- $record : array<string|int, mixed>