HipChatHandler
extends SocketHandler
in package
Sends notifications through the hipchat api to a hipchat room
Notes: API token - HipChat API token Room - HipChat Room Id or name, where messages are sent Name - Name used to send the message (from) notify - Should the message trigger a notification in the clients version - The API version to use (HipChatHandler::API_V1 | HipChatHandler::API_V2)
Tags
Table of Contents
- API_V1 = 'v1'
- Use API version 1
- API_V2 = 'v2'
- Use API version v2
- MAXIMUM_MESSAGE_LENGTH = 9500
- The maximum allowed length for the message.
- MAXIMUM_NAME_LENGTH = 15
- The maximum allowed length for the name used in the "from" field.
- $bubble : mixed
- $formatter : FormatterInterface
- $level : mixed
- $processors : mixed
- $chunkSize : mixed
- $connectionString : mixed
- $connectionTimeout : mixed
- $errno : mixed
- $errstr : mixed
- $format : string
- $host : string
- $lastSentBytes : mixed
- $lastWritingAt : mixed
- $name : string
- $notify : bool
- $persistent : mixed
- $resource : mixed
- $room : string
- $timeout : mixed
- $token : string
- $version : string
- $writingTimeout : mixed
- __construct() : mixed
- __destruct() : mixed
- close() : mixed
- Closes the handler.
- closeSocket() : mixed
- Close socket, if open
- getBubble() : bool
- Gets the bubbling behavior.
- getChunkSize() : float
- Get current chunk size
- getConnectionString() : string
- Get current connection string
- getConnectionTimeout() : float
- Get current connection timeout setting
- getFormatter() : FormatterInterface
- Gets the formatter.
- getLevel() : int
- Gets minimum logging level at which this handler will be triggered.
- getTimeout() : float
- Get current in-transfer timeout
- getWritingTimeout() : float
- Get current local writing timeout
- handle() : mixed
- {@inheritdoc}
- handleBatch() : mixed
- {@inheritdoc}
- isConnected() : bool
- Check to see if the socket is currently available.
- isHandling() : bool
- Checks whether the given record will be handled by this handler.
- isPersistent() : bool
- Get persistent setting
- popProcessor() : callable
- Removes the processor on top of the stack and returns it.
- pushProcessor() : self
- Adds a processor in the stack.
- reset() : mixed
- setBubble() : self
- Sets the bubbling behavior.
- setChunkSize() : mixed
- Set chunk size. Only has effect during connection in the writing cycle.
- setConnectionTimeout() : mixed
- Set connection timeout. Only has effect before we connect.
- setFormatter() : self
- Sets the formatter.
- setLevel() : self
- Sets minimum logging level at which this handler will be triggered.
- setPersistent() : mixed
- Set socket connection to nbe persistent. It only has effect before the connection is initiated.
- setTimeout() : mixed
- Set write timeout. Only has effect before we connect.
- setWritingTimeout() : mixed
- Set writing timeout. Only has effect during connection in the writing cycle.
- finalizeWrite() : mixed
- Finalizes the request by reading some bytes and then closing the socket
- fsockopen() : mixed
- Wrapper to allow mocking
- fwrite() : mixed
- Wrapper to allow mocking
- generateDataStream() : string
- getAlertColor() : string
- Assigns a color to each level of log records.
- getDefaultFormatter() : FormatterInterface
- Gets the default formatter.
- getResource() : resource|null
- pfsockopen() : mixed
- Wrapper to allow mocking
- processRecord() : array<string|int, mixed>
- Processes a record.
- streamGetMetadata() : mixed
- Wrapper to allow mocking
- streamSetChunkSize() : mixed
- Wrapper to allow mocking
- streamSetTimeout() : mixed
- Wrapper to allow mocking
- write() : void
- Connect (if necessary) and write to the socket
- buildContent() : string
- Builds the body of API call
- buildHeader() : string
- Builds the header of the API Call
- combineRecords() : array<string|int, mixed>
- Combines multiple records into one. Error level of the combined record will be the highest level from the given records. Datetime will be taken from the first record.
- connect() : mixed
- connectIfNotConnected() : mixed
- createSocketResource() : mixed
- setSocketTimeout() : mixed
- setStreamChunkSize() : mixed
- validateStringLength() : bool
- Validates the length of a string.
- validateTimeout() : mixed
- writeToSocket() : mixed
- writingIsTimedOut() : mixed
Constants
API_V1
Use API version 1
public
mixed
API_V1
= 'v1'
API_V2
Use API version v2
public
mixed
API_V2
= 'v2'
MAXIMUM_MESSAGE_LENGTH
The maximum allowed length for the message.
public
mixed
MAXIMUM_MESSAGE_LENGTH
= 9500
MAXIMUM_NAME_LENGTH
The maximum allowed length for the name used in the "from" field.
public
mixed
MAXIMUM_NAME_LENGTH
= 15
Properties
$bubble
protected
mixed
$bubble
= true
$formatter
protected
FormatterInterface
$formatter
$level
protected
mixed
$level
= MonologLogger::DEBUG
$processors
protected
mixed
$processors
= array()
$chunkSize
private
mixed
$chunkSize
= null
$connectionString
private
mixed
$connectionString
$connectionTimeout
private
mixed
$connectionTimeout
$errno
private
mixed
$errno
$errstr
private
mixed
$errstr
$format
private
string
$format
$host
private
string
$host
$lastSentBytes
private
mixed
$lastSentBytes
= null
$lastWritingAt
private
mixed
$lastWritingAt
$name
private
string
$name
$notify
private
bool
$notify
$persistent
private
mixed
$persistent
= false
$resource
private
mixed
$resource
$room
private
string
$room
$timeout
private
mixed
$timeout
= 0
$token
private
string
$token
$version
private
string
$version
$writingTimeout
private
mixed
$writingTimeout
= 10
Methods
__construct()
public
__construct(string $token, string $room[, string $name = 'Monolog' ][, bool $notify = false ][, int $level = Logger::CRITICAL ][, bool $bubble = true ][, bool $useSSL = true ][, string $format = 'text' ][, string $host = 'api.hipchat.com' ][, string $version = self::API_V1 ]) : mixed
Parameters
- $token : string
-
HipChat API Token
- $room : string
-
The room that should be alerted of the message (Id or Name)
- $name : string = 'Monolog'
-
Name used in the "from" field.
- $notify : bool = false
-
Trigger a notification in clients or not
- $level : int = Logger::CRITICAL
-
The minimum logging level at which this handler will be triggered
- $bubble : bool = true
-
Whether the messages that are handled can bubble up the stack or not
- $useSSL : bool = true
-
Whether to connect via SSL.
- $format : string = 'text'
-
The format of the messages (default to text, can be set to html if you have html in the messages)
- $host : string = 'api.hipchat.com'
-
The HipChat server hostname.
- $version : string = self::API_V1
-
The HipChat API version (default HipChatHandler::API_V1)
Return values
mixed —__destruct()
public
__destruct() : mixed
Return values
mixed —close()
Closes the handler.
public
close() : mixed
This will be called automatically when the object is destroyed
Return values
mixed —closeSocket()
Close socket, if open
public
closeSocket() : mixed
Return values
mixed —getBubble()
Gets the bubbling behavior.
public
getBubble() : bool
Return values
bool —true means that this handler allows bubbling. false means that bubbling is not permitted.
getChunkSize()
Get current chunk size
public
getChunkSize() : float
Return values
float —getConnectionString()
Get current connection string
public
getConnectionString() : string
Return values
string —getConnectionTimeout()
Get current connection timeout setting
public
getConnectionTimeout() : float
Return values
float —getFormatter()
Gets the formatter.
public
getFormatter() : FormatterInterface
Return values
FormatterInterface —getLevel()
Gets minimum logging level at which this handler will be triggered.
public
getLevel() : int
Return values
int —getTimeout()
Get current in-transfer timeout
public
getTimeout() : float
Return values
float —getWritingTimeout()
Get current local writing timeout
public
getWritingTimeout() : float
Return values
float —handle()
{@inheritdoc}
public
handle(array<string|int, mixed> $record) : mixed
Parameters
- $record : array<string|int, mixed>
Return values
mixed —handleBatch()
{@inheritdoc}
public
handleBatch(array<string|int, mixed> $records) : mixed
Parameters
- $records : array<string|int, mixed>
Return values
mixed —isConnected()
Check to see if the socket is currently available.
public
isConnected() : bool
UDP might appear to be connected but might fail when writing. See http://php.net/fsockopen for details.
Return values
bool —isHandling()
Checks whether the given record will be handled by this handler.
public
isHandling(array<string|int, mixed> $record) : bool
Parameters
- $record : array<string|int, mixed>
-
Partial log record containing only a level key
Return values
bool —isPersistent()
Get persistent setting
public
isPersistent() : bool
Return values
bool —popProcessor()
Removes the processor on top of the stack and returns it.
public
popProcessor() : callable
Return values
callable —pushProcessor()
Adds a processor in the stack.
public
pushProcessor(mixed $callback) : self
Parameters
- $callback : mixed
Return values
self —reset()
public
reset() : mixed
Return values
mixed —setBubble()
Sets the bubbling behavior.
public
setBubble(bool $bubble) : self
Parameters
- $bubble : bool
-
true means that this handler allows bubbling. false means that bubbling is not permitted.
Return values
self —setChunkSize()
Set chunk size. Only has effect during connection in the writing cycle.
public
setChunkSize(float $bytes) : mixed
Parameters
- $bytes : float
Return values
mixed —setConnectionTimeout()
Set connection timeout. Only has effect before we connect.
public
setConnectionTimeout(float $seconds) : mixed
Parameters
- $seconds : float
Tags
Return values
mixed —setFormatter()
Sets the formatter.
public
setFormatter(FormatterInterface $formatter) : self
Parameters
- $formatter : FormatterInterface
Return values
self —setLevel()
Sets minimum logging level at which this handler will be triggered.
public
setLevel(int|string $level) : self
Parameters
- $level : int|string
-
Level or level name
Return values
self —setPersistent()
Set socket connection to nbe persistent. It only has effect before the connection is initiated.
public
setPersistent(bool $persistent) : mixed
Parameters
- $persistent : bool
Return values
mixed —setTimeout()
Set write timeout. Only has effect before we connect.
public
setTimeout(float $seconds) : mixed
Parameters
- $seconds : float
Tags
Return values
mixed —setWritingTimeout()
Set writing timeout. Only has effect during connection in the writing cycle.
public
setWritingTimeout(float $seconds) : mixed
Parameters
- $seconds : float
-
0 for no timeout
Return values
mixed —finalizeWrite()
Finalizes the request by reading some bytes and then closing the socket
protected
finalizeWrite() : mixed
If we do not read some but close the socket too early, hipchat sometimes drops the request entirely.
Return values
mixed —fsockopen()
Wrapper to allow mocking
protected
fsockopen() : mixed
Return values
mixed —fwrite()
Wrapper to allow mocking
protected
fwrite(mixed $data) : mixed
Parameters
- $data : mixed
Return values
mixed —generateDataStream()
protected
generateDataStream(array<string|int, mixed> $record) : string
Parameters
- $record : array<string|int, mixed>
Return values
string —getAlertColor()
Assigns a color to each level of log records.
protected
getAlertColor(int $level) : string
Parameters
- $level : int
Return values
string —getDefaultFormatter()
Gets the default formatter.
protected
getDefaultFormatter() : FormatterInterface
Return values
FormatterInterface —getResource()
protected
getResource() : resource|null
Return values
resource|null —pfsockopen()
Wrapper to allow mocking
protected
pfsockopen() : mixed
Return values
mixed —processRecord()
Processes a record.
protected
processRecord(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
- $record : array<string|int, mixed>
Return values
array<string|int, mixed> —streamGetMetadata()
Wrapper to allow mocking
protected
streamGetMetadata() : mixed
Return values
mixed —streamSetChunkSize()
Wrapper to allow mocking
protected
streamSetChunkSize() : mixed
Tags
Return values
mixed —streamSetTimeout()
Wrapper to allow mocking
protected
streamSetTimeout() : mixed
Tags
Return values
mixed —write()
Connect (if necessary) and write to the socket
protected
write(array<string|int, mixed> $record) : void
Parameters
- $record : array<string|int, mixed>
Return values
void —buildContent()
Builds the body of API call
private
buildContent(array<string|int, mixed> $record) : string
Parameters
- $record : array<string|int, mixed>
Return values
string —buildHeader()
Builds the header of the API Call
private
buildHeader(string $content) : string
Parameters
- $content : string
Return values
string —combineRecords()
Combines multiple records into one. Error level of the combined record will be the highest level from the given records. Datetime will be taken from the first record.
private
combineRecords( $records) : array<string|int, mixed>
Parameters
Return values
array<string|int, mixed> —connect()
private
connect() : mixed
Return values
mixed —connectIfNotConnected()
private
connectIfNotConnected() : mixed
Return values
mixed —createSocketResource()
private
createSocketResource() : mixed
Return values
mixed —setSocketTimeout()
private
setSocketTimeout() : mixed
Return values
mixed —setStreamChunkSize()
private
setStreamChunkSize() : mixed
Return values
mixed —validateStringLength()
Validates the length of a string.
private
validateStringLength(string $str, int $length) : bool
If the mb_strlen() function is available, it will use that, as HipChat
allows UTF-8 characters. Otherwise, it will fall back to strlen().
Note that this might cause false failures in the specific case of using
a valid name with less than 16 characters, but 16 or more bytes, on a
system where mb_strlen() is unavailable.
Parameters
- $str : string
- $length : int
Return values
bool —validateTimeout()
private
validateTimeout(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —writeToSocket()
private
writeToSocket(mixed $data) : mixed
Parameters
- $data : mixed
Return values
mixed —writingIsTimedOut()
private
writingIsTimedOut(mixed $sent) : mixed
Parameters
- $sent : mixed