1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tylercd100\Monolog\Handler; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Monolog\Logger; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Clickatell - Monolog Handler |
10
|
|
|
* @url https://www.clickatell.com/developers/api-documentation/rest-api-request-parameters |
11
|
|
|
*/ |
12
|
|
|
class ClickatellHandler extends SMSHandler |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* API version 1 |
16
|
|
|
*/ |
17
|
|
|
const API_V1 = '2010-04-01'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param string $secret Twilio API Secret Token |
21
|
|
|
* @param string $fromNumber The phone number that will be shown as the sender ID |
22
|
|
|
* @param string $toNumber The phone number to which the message will be sent |
23
|
|
|
* @param int $level The minimum logging level at which this handler will be triggered |
24
|
|
|
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not |
25
|
|
|
* @param bool $useSSL Whether to connect via SSL. |
26
|
|
|
* @param string $host The Twilio server hostname. |
27
|
|
|
* @param string $version The Twilio API version (default ClickatellHandler::API_V1) |
28
|
|
|
* @param int $limit The character limit |
29
|
|
|
*/ |
30
|
18 |
|
public function __construct($secret, $fromNumber, $toNumber, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $host = 'platform.clickatell.com', $version = self::API_V1, $limit = 160) |
31
|
|
|
{ |
32
|
18 |
|
if ($version !== self::API_V1) { |
33
|
3 |
|
throw new Exception("API Version \'{$version}\' is not supported!"); |
34
|
|
|
} |
35
|
15 |
|
parent::__construct($secret, null, $fromNumber, $toNumber, $level, $bubble, $useSSL, $host, $version, $limit); |
36
|
15 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
* |
41
|
|
|
* @param array $record |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
12 |
|
protected function buildContent($record) |
45
|
|
|
{ |
46
|
12 |
|
if (strlen($record['formatted']) > $this->limit) { |
47
|
|
|
$record['formatted'] = substr($record['formatted'], 0, $this->limit); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$dataArray = [ |
51
|
12 |
|
'content' => $record['formatted'], |
52
|
12 |
|
'to' => (!is_array($this->toNumber)? [$this->toNumber] : $this->toNumber) |
53
|
12 |
|
]; |
54
|
|
|
|
55
|
12 |
|
($this->fromNumber)? $dataArray['from'] = $this->fromNumber : false; |
56
|
|
|
|
57
|
12 |
|
return json_encode($dataArray); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Builds the URL for the API call |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
12 |
|
protected function buildRequestUrl() |
66
|
|
|
{ |
67
|
12 |
|
return "POST /messages HTTP/1.1\r\n"; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|