mirror of
https://github.com/Seldaek/monolog.git
synced 2025-02-24 06:52:34 +01:00
Merge remote-tracking branch 'Rvanlaak/patch-1'
This commit is contained in:
commit
996e80d031
@ -31,6 +31,13 @@ class PushoverHandler extends SocketHandler
|
||||
private $highPriorityLevel;
|
||||
private $emergencyLevel;
|
||||
|
||||
/**
|
||||
* All parameters that can be sent to Pushover
|
||||
* @see https://pushover.net/api
|
||||
* @var array
|
||||
*/
|
||||
private $parameters;
|
||||
|
||||
/**
|
||||
* Sounds the api supports by default
|
||||
* @see https://pushover.net/api#sounds
|
||||
@ -69,6 +76,13 @@ class PushoverHandler extends SocketHandler
|
||||
$this->emergencyLevel = Logger::toMonologLevel($emergencyLevel);
|
||||
$this->retry = $retry;
|
||||
$this->expire = $expire;
|
||||
|
||||
// Initialize API parameters as array keys
|
||||
$this->parameters = array_flip(array(
|
||||
'token', 'user', 'message', // these are the required parameters
|
||||
'device', 'title', 'url', 'url_title', 'priority', 'timestamp', 'sound',
|
||||
'retry', 'expire', 'callback',
|
||||
));
|
||||
}
|
||||
|
||||
protected function generateDataStream($record)
|
||||
@ -101,10 +115,16 @@ class PushoverHandler extends SocketHandler
|
||||
$dataArray['priority'] = 1;
|
||||
}
|
||||
|
||||
if (isset($record['context']['sound']) && in_array($record['context']['sound'], $this->sounds)) {
|
||||
$dataArray['sound'] = $record['context']['sound'];
|
||||
} elseif (isset($record['extra']['sound']) && in_array($record['extra']['sound'], $this->sounds)) {
|
||||
$dataArray['sound'] = $record['extra']['sound'];
|
||||
// First determine the available parameters
|
||||
$context = array_intersect_key($record['context'], $this->parameters);
|
||||
$extra = array_intersect_key($record['extra'], $this->parameters);
|
||||
|
||||
// Least important info should be merged with subsequent info
|
||||
$dataArray = array_merge($extra, $context, $dataArray);
|
||||
|
||||
// Only pass sounds that are supported by the API
|
||||
if (isset($dataArray['sound']) && !in_array($dataArray['sound'], $this->sounds)) {
|
||||
unset($dataArray['sound']);
|
||||
}
|
||||
|
||||
return http_build_query($dataArray);
|
||||
|
Loading…
x
Reference in New Issue
Block a user