SlackRecord
in package
Slack record utility helping to log to Slack webhooks or API.
Tags
Table of Contents
Constants
- COLOR_DANGER = 'danger'
- COLOR_DEFAULT = '#e3e4e6'
- COLOR_GOOD = 'good'
- COLOR_WARNING = 'warning'
Properties
- $channel : string|null
- Slack channel (encoded ID or name)
- $excludeFields : array<string|int, mixed>
- Dot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2']
- $formatter : FormatterInterface
- $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
- 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
Methods
- __construct() : mixed
- getAttachmentColor() : string
- Returned a Slack message attachment color associated with provided level.
- getSlackData() : mixed
- setFormatter() : mixed
- Sets the formatter
- stringify() : string
- Stringifies an array of key/value pairs to be used in attachment fields
- excludeFields() : array<string|int, mixed>
- Get a copy of record with fields excluded according to $this->excludeFields
- generateAttachmentField() : array<string|int, mixed>
- Generates attachment field
- generateAttachmentFields() : array<string|int, mixed>
- Generates a collection of attachment fields from array
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, mixed>
$excludeFields
$formatter
private
FormatterInterface
$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
$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([mixed $channel = null ][, mixed $username = null ][, mixed $useAttachment = true ][, mixed $userIcon = null ][, mixed $useShortAttachment = false ][, mixed $includeContextAndExtra = false ][, array<string|int, mixed> $excludeFields = array() ][, FormatterInterface $formatter = null ]) : mixed
Parameters
- $channel : mixed = null
- $username : mixed = null
- $useAttachment : mixed = true
- $userIcon : mixed = null
- $useShortAttachment : mixed = false
- $includeContextAndExtra : mixed = false
- $excludeFields : array<string|int, mixed> = array()
- $formatter : FormatterInterface = null
getAttachmentColor()
Returned a Slack message attachment color associated with provided level.
public
getAttachmentColor(int $level) : string
Parameters
- $level : int
Return values
stringgetSlackData()
public
getSlackData(array<string|int, mixed> $record) : mixed
Parameters
- $record : array<string|int, mixed>
setFormatter()
Sets the formatter
public
setFormatter(FormatterInterface $formatter) : mixed
Parameters
- $formatter : FormatterInterface
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
stringexcludeFields()
Get a copy of record with fields excluded according to $this->excludeFields
private
excludeFields(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
- $record : array<string|int, mixed>
Return values
array<string|int, mixed>generateAttachmentField()
Generates attachment field
private
generateAttachmentField(string $title, string|array<string|int, mixed> $value) : array<string|int, mixed>
Parameters
- $title : string
- $value : string|array<string|int, mixed>
Return values
array<string|int, mixed>generateAttachmentFields()
Generates a collection of attachment fields from array
private
generateAttachmentFields(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
- $data : array<string|int, mixed>