ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
Monolog\Handler\PushoverHandler Class Reference

Sends notifications through the pushover api to mobile phones. More...

+ Inheritance diagram for Monolog\Handler\PushoverHandler:
+ Collaboration diagram for Monolog\Handler\PushoverHandler:

Public Member Functions

 __construct ($token, $users, $title=null, $level=Logger::CRITICAL, $bubble=true, $useSSL=true, $highPriorityLevel=Logger::CRITICAL, $emergencyLevel=Logger::EMERGENCY, $retry=30, $expire=25200)
 
 setHighPriorityLevel ($value)
 
 setEmergencyLevel ($value)
 
 useFormattedMessage ($value)
 Use the formatted message? More...
 
- Public Member Functions inherited from Monolog\Handler\SocketHandler
 __construct ($connectionString, $level=Logger::DEBUG, $bubble=true)
 
 close ()
 We will not close a PersistentSocket instance so it can be reused in other requests. More...
 
 closeSocket ()
 Close socket, if open. More...
 
 setPersistent ($boolean)
 Set socket connection to nbe persistent. More...
 
 setConnectionTimeout ($seconds)
 Set connection timeout. More...
 
 setTimeout ($seconds)
 Set write timeout. More...
 
 getConnectionString ()
 Get current connection string. More...
 
 isPersistent ()
 Get persistent setting. More...
 
 getConnectionTimeout ()
 Get current connection timeout setting. More...
 
 getTimeout ()
 Get current in-transfer timeout. More...
 
 isConnected ()
 Check to see if the socket is currently available. More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
Boolean true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.
Parameters
array$recordPartial log record containing only a level key
Returns
Boolean
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 

Protected Member Functions

 generateDataStream ($record)
 
 write (array $record)
 
- Protected Member Functions inherited from Monolog\Handler\SocketHandler
 write (array $record)
 Connect (if necessary) and write to the socket. More...
 
 pfsockopen ()
 Wrapper to allow mocking. More...
 
 fsockopen ()
 Wrapper to allow mocking. More...
 
 streamSetTimeout ()
 Wrapper to allow mocking. More...
 
 fwrite ($data)
 Wrapper to allow mocking. More...
 
 streamGetMetadata ()
 Wrapper to allow mocking. More...
 
 generateDataStream ($record)
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Private Member Functions

 buildContent ($record)
 
 buildHeader ($content)
 

Private Attributes

 $token
 
 $users
 
 $title
 
 $user
 
 $retry
 
 $expire
 
 $highPriorityLevel
 
 $emergencyLevel
 
 $useFormattedMessage = false
 
 $parameterNames
 
 $sounds
 

Additional Inherited Members

- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Detailed Description

Sends notifications through the pushover api to mobile phones.

Author
Sebastian Göttschkes sebas.nosp@m.tian.nosp@m..goet.nosp@m.tsch.nosp@m.kes@g.nosp@m.oogl.nosp@m.email.nosp@m..com
See also
https://www.pushover.net/api

Definition at line 22 of file PushoverHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\PushoverHandler::__construct (   $token,
  $users,
  $title = null,
  $level = Logger::CRITICAL,
  $bubble = true,
  $useSSL = true,
  $highPriorityLevel = Logger::CRITICAL,
  $emergencyLevel = Logger::EMERGENCY,
  $retry = 30,
  $expire = 25200 
)
Parameters
string$tokenPushover api token
string | array$usersPushover user id or array of ids the message will be sent to
string$titleTitle sent to the Pushover API
integer$levelThe minimum logging level at which this handler will be triggered
Boolean$bubbleWhether the messages that are handled can bubble up the stack or not
Boolean$useSSLWhether to connect via SSL. Required when pushing messages to users that are not the pushover.net app owner. OpenSSL is required for this option.
integer$highPriorityLevelThe minimum logging level at which this handler will start sending "high priority" requests to the Pushover API
integer$emergencyLevelThe minimum logging level at which this handler will start sending "emergency" requests to the Pushover API
integer$retryThe retry parameter specifies how often (in seconds) the Pushover servers will send the same notification to the user.
integer$expireThe expire parameter specifies how many seconds your notification will continue to be retried for (every retry seconds).

Definition at line 82 of file PushoverHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\SocketHandler\$connectionString, Monolog\Handler\PushoverHandler\$emergencyLevel, Monolog\Handler\PushoverHandler\$expire, Monolog\Handler\PushoverHandler\$highPriorityLevel, Monolog\Handler\AbstractHandler\$level, Monolog\Handler\PushoverHandler\$retry, Monolog\Handler\PushoverHandler\$title, Monolog\Handler\PushoverHandler\$token, Monolog\Handler\PushoverHandler\$users, and Monolog\Logger\toMonologLevel().

83  {
84  $connectionString = $useSSL ? 'ssl://api.pushover.net:443' : 'api.pushover.net:80';
85  parent::__construct($connectionString, $level, $bubble);
86 
87  $this->token = $token;
88  $this->users = (array) $users;
89  $this->title = $title ?: gethostname();
90  $this->highPriorityLevel = Logger::toMonologLevel($highPriorityLevel);
91  $this->emergencyLevel = Logger::toMonologLevel($emergencyLevel);
92  $this->retry = $retry;
93  $this->expire = $expire;
94  }
static toMonologLevel($level)
Converts PSR-3 levels to Monolog ones if necessary.
Definition: Logger.php:403
+ Here is the call graph for this function:

Member Function Documentation

◆ buildContent()

Monolog\Handler\PushoverHandler::buildContent (   $record)
private

Definition at line 103 of file PushoverHandler.php.

References Monolog\Handler\PushoverHandler\$expire, Monolog\Handler\PushoverHandler\$retry, $timestamp, and Monolog\Handler\PushoverHandler\$useFormattedMessage.

Referenced by Monolog\Handler\PushoverHandler\generateDataStream().

104  {
105  // Pushover has a limit of 512 characters on title and message combined.
106  $maxMessageLength = 512 - strlen($this->title);
107 
108  $message = ($this->useFormattedMessage) ? $record['formatted'] : $record['message'];
109  $message = substr($message, 0, $maxMessageLength);
110 
111  $timestamp = $record['datetime']->getTimestamp();
112 
113  $dataArray = array(
114  'token' => $this->token,
115  'user' => $this->user,
116  'message' => $message,
117  'title' => $this->title,
118  'timestamp' => $timestamp
119  );
120 
121  if (isset($record['level']) && $record['level'] >= $this->emergencyLevel) {
122  $dataArray['priority'] = 2;
123  $dataArray['retry'] = $this->retry;
124  $dataArray['expire'] = $this->expire;
125  } elseif (isset($record['level']) && $record['level'] >= $this->highPriorityLevel) {
126  $dataArray['priority'] = 1;
127  }
128 
129  // First determine the available parameters
130  $context = array_intersect_key($record['context'], $this->parameterNames);
131  $extra = array_intersect_key($record['extra'], $this->parameterNames);
132 
133  // Least important info should be merged with subsequent info
134  $dataArray = array_merge($extra, $context, $dataArray);
135 
136  // Only pass sounds that are supported by the API
137  if (isset($dataArray['sound']) && !in_array($dataArray['sound'], $this->sounds)) {
138  unset($dataArray['sound']);
139  }
140 
141  return http_build_query($dataArray);
142  }
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
+ Here is the caller graph for this function:

◆ buildHeader()

Monolog\Handler\PushoverHandler::buildHeader (   $content)
private

Definition at line 144 of file PushoverHandler.php.

References $header.

Referenced by Monolog\Handler\PushoverHandler\generateDataStream().

145  {
146  $header = "POST /1/messages.json HTTP/1.1\r\n";
147  $header .= "Host: api.pushover.net\r\n";
148  $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
149  $header .= "Content-Length: " . strlen($content) . "\r\n";
150  $header .= "\r\n";
151 
152  return $header;
153  }
$header
+ Here is the caller graph for this function:

◆ generateDataStream()

Monolog\Handler\PushoverHandler::generateDataStream (   $record)
protected

Definition at line 96 of file PushoverHandler.php.

References Monolog\Handler\PushoverHandler\buildContent(), and Monolog\Handler\PushoverHandler\buildHeader().

97  {
98  $content = $this->buildContent($record);
99 
100  return $this->buildHeader($content) . $content;
101  }
+ Here is the call graph for this function:

◆ setEmergencyLevel()

Monolog\Handler\PushoverHandler::setEmergencyLevel (   $value)

Definition at line 172 of file PushoverHandler.php.

173  {
174  $this->emergencyLevel = $value;
175  }

◆ setHighPriorityLevel()

Monolog\Handler\PushoverHandler::setHighPriorityLevel (   $value)

Definition at line 167 of file PushoverHandler.php.

168  {
169  $this->highPriorityLevel = $value;
170  }

◆ useFormattedMessage()

Monolog\Handler\PushoverHandler::useFormattedMessage (   $value)

Use the formatted message?

Parameters
boolean$value

Definition at line 181 of file PushoverHandler.php.

182  {
183  $this->useFormattedMessage = (boolean) $value;
184  }
useFormattedMessage($value)
Use the formatted message?

◆ write()

Monolog\Handler\PushoverHandler::write ( array  $record)
protected

Definition at line 155 of file PushoverHandler.php.

References Monolog\Handler\PushoverHandler\$user, and Monolog\Handler\SocketHandler\closeSocket().

156  {
157  foreach ($this->users as $user) {
158  $this->user = $user;
159 
160  parent::write($record);
161  $this->closeSocket();
162  }
163 
164  $this->user = null;
165  }
closeSocket()
Close socket, if open.
+ Here is the call graph for this function:

Field Documentation

◆ $emergencyLevel

Monolog\Handler\PushoverHandler::$emergencyLevel
private

Definition at line 32 of file PushoverHandler.php.

Referenced by Monolog\Handler\PushoverHandler\__construct().

◆ $expire

Monolog\Handler\PushoverHandler::$expire
private

◆ $highPriorityLevel

Monolog\Handler\PushoverHandler::$highPriorityLevel
private

Definition at line 31 of file PushoverHandler.php.

Referenced by Monolog\Handler\PushoverHandler\__construct().

◆ $parameterNames

Monolog\Handler\PushoverHandler::$parameterNames
private
Initial value:
= array(
'token' => true,
'user' => true,
'message' => true,
'device' => true,
'title' => true,
'url' => true,
'url_title' => true,
'priority' => true,
'timestamp' => true,
'sound' => true,
'retry' => true,
'expire' => true,
'callback' => true,
)

Definition at line 40 of file PushoverHandler.php.

◆ $retry

Monolog\Handler\PushoverHandler::$retry
private

◆ $sounds

Monolog\Handler\PushoverHandler::$sounds
private
Initial value:
= array(
'pushover', 'bike', 'bugle', 'cashregister', 'classical', 'cosmic', 'falling', 'gamelan', 'incoming',
'intermission', 'magic', 'mechanical', 'pianobar', 'siren', 'spacealarm', 'tugboat', 'alien', 'climb',
'persistent', 'echo', 'updown', 'none',
)

Definition at line 61 of file PushoverHandler.php.

◆ $title

Monolog\Handler\PushoverHandler::$title
private

Definition at line 26 of file PushoverHandler.php.

Referenced by Monolog\Handler\PushoverHandler\__construct().

◆ $token

Monolog\Handler\PushoverHandler::$token
private

Definition at line 24 of file PushoverHandler.php.

Referenced by Monolog\Handler\PushoverHandler\__construct().

◆ $useFormattedMessage

Monolog\Handler\PushoverHandler::$useFormattedMessage = false
private

Definition at line 33 of file PushoverHandler.php.

Referenced by Monolog\Handler\PushoverHandler\buildContent().

◆ $user

Monolog\Handler\PushoverHandler::$user
private

Definition at line 27 of file PushoverHandler.php.

Referenced by Monolog\Handler\PushoverHandler\write().

◆ $users

Monolog\Handler\PushoverHandler::$users
private

Definition at line 25 of file PushoverHandler.php.

Referenced by Monolog\Handler\PushoverHandler\__construct().


The documentation for this class was generated from the following file: