mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-21 16:46:11 +02:00
Overwriting the generateDataStream method to format the Data sent to Pushover
This way, the write method does not have to be overwritten.
This commit is contained in:
@@ -42,37 +42,13 @@ class PushoverHandler extends SocketHandler
|
|||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function generateDataStream($record)
|
||||||
* Build the content to be sent through the socket, then connect
|
|
||||||
* (if necessary) and write to the socket
|
|
||||||
*
|
|
||||||
* @param array $record
|
|
||||||
*
|
|
||||||
* @throws \UnexpectedValueException
|
|
||||||
* @throws \RuntimeException
|
|
||||||
*/
|
|
||||||
public function write(array $record)
|
|
||||||
{
|
{
|
||||||
$data = $this->buildDataString($record);
|
$content = $this->buildContentString($record);
|
||||||
$content = $this->buildContent($data);
|
return $this->buildHeaderAndAddContent($content);
|
||||||
|
|
||||||
$this->connectIfNotConnected();
|
|
||||||
$this->writeToSocket($content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildContent($data)
|
private function buildContentString($record)
|
||||||
{
|
|
||||||
$content = "POST /1/messages.json HTTP/1.1\r\n";
|
|
||||||
$content .= "Host: api.pushover.net\r\n";
|
|
||||||
$content .= "Content-Type: application/x-www-form-urlencoded\r\n";
|
|
||||||
$content .= "Content-Length: " . strlen($data) . "\r\n";
|
|
||||||
$content .= "\r\n";
|
|
||||||
$content .= $data;
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function buildDataString($record)
|
|
||||||
{
|
{
|
||||||
// Pushover has a limit of 512 characters on title and message combined.
|
// Pushover has a limit of 512 characters on title and message combined.
|
||||||
$maxMessageLength = 512 - strlen($this->title);
|
$maxMessageLength = 512 - strlen($this->title);
|
||||||
@@ -89,4 +65,16 @@ class PushoverHandler extends SocketHandler
|
|||||||
|
|
||||||
return http_build_query($dataArray);
|
return http_build_query($dataArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildHeaderAndAddContent($content)
|
||||||
|
{
|
||||||
|
$header = "POST /1/messages.json HTTP/1.1\r\n";
|
||||||
|
$header .= "Host: api.pushover.net\r\n";
|
||||||
|
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
|
||||||
|
$header .= "Content-Length: " . strlen($content) . "\r\n";
|
||||||
|
$header .= "\r\n";
|
||||||
|
$header .= $content;
|
||||||
|
|
||||||
|
return $header;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user