diff --git a/docs/404.html b/docs/404.html index a7275551..d37ad166 100644 --- a/docs/404.html +++ b/docs/404.html @@ -211,7 +211,7 @@

Page not found

- + diff --git a/docs/class-LINE.LINEBot.Constant.Meta.html b/docs/class-LINE.LINEBot.Constant.Meta.html index 4950e69d..14253f31 100644 --- a/docs/class-LINE.LINEBot.Constant.Meta.html +++ b/docs/class-LINE.LINEBot.Constant.Meta.html @@ -197,7 +197,7 @@

Class Meta

# - '1.4.0' + '1.5.0'
diff --git a/docs/class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html b/docs/class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html index 96ad695b..4e781f94 100644 --- a/docs/class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html +++ b/docs/class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html @@ -171,7 +171,7 @@

Class CurlHTTPClient

Namespace: LINE\LINEBot\HTTPClient
Package: LINE\LINEBot\HTTPClient
- Located at LINEBot/HTTPClient/CurlHTTPClient.php + Located at LINEBot/HTTPClient/CurlHTTPClient.php
@@ -191,7 +191,7 @@

Class CurlHTTPClient

# - __construct( string $channelToken ) + __construct( string $channelToken )

CurlHTTPClient constructor.

@@ -226,7 +226,7 @@

Parameters

# - get( string $url ) + get( string $url )

Sends GET request to LINE Messaging API.

@@ -267,7 +267,7 @@

Implementation of

# - post( string $url, array $data ) + post( string $url, array $data )

Sends POST request to LINE Messaging API.

diff --git a/docs/class-LINE.LINEBot.MessageBuilder.TextMessageBuilder.html b/docs/class-LINE.LINEBot.MessageBuilder.TextMessageBuilder.html index 89d95410..28ec9d63 100644 --- a/docs/class-LINE.LINEBot.MessageBuilder.TextMessageBuilder.html +++ b/docs/class-LINE.LINEBot.MessageBuilder.TextMessageBuilder.html @@ -180,7 +180,7 @@

Class TextMessageBuilder

Namespace: LINE\LINEBot\MessageBuilder
Package: LINE\LINEBot\MessageBuilder
- Located at LINEBot/MessageBuilder/TextMessageBuilder.php + Located at LINEBot/MessageBuilder/TextMessageBuilder.php
@@ -200,7 +200,7 @@

Class TextMessageBuilder

# - __construct( string $text, string[] $extraTexts ) + __construct( string $text, string[]|null $extraTexts = null )

TextMessageBuilder constructor.

@@ -209,6 +209,16 @@

Class TextMessageBuilder

- + diff --git a/docs/source-class-LINE.LINEBot.Event.BaseEvent.html b/docs/source-class-LINE.LINEBot.Event.BaseEvent.html index 9dafc2f4..0e6d8ac7 100644 --- a/docs/source-class-LINE.LINEBot.Event.BaseEvent.html +++ b/docs/source-class-LINE.LINEBot.Event.BaseEvent.html @@ -385,7 +385,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.BeaconDetectionEvent.html b/docs/source-class-LINE.LINEBot.Event.BeaconDetectionEvent.html index 4af97a6f..6736488e 100644 --- a/docs/source-class-LINE.LINEBot.Event.BeaconDetectionEvent.html +++ b/docs/source-class-LINE.LINEBot.Event.BeaconDetectionEvent.html @@ -264,7 +264,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.FollowEvent.html b/docs/source-class-LINE.LINEBot.Event.FollowEvent.html index 5aaeb7e1..77f19e64 100644 --- a/docs/source-class-LINE.LINEBot.Event.FollowEvent.html +++ b/docs/source-class-LINE.LINEBot.Event.FollowEvent.html @@ -244,7 +244,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.JoinEvent.html b/docs/source-class-LINE.LINEBot.Event.JoinEvent.html index 6302bb7c..51f5d234 100644 --- a/docs/source-class-LINE.LINEBot.Event.JoinEvent.html +++ b/docs/source-class-LINE.LINEBot.Event.JoinEvent.html @@ -244,7 +244,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.LeaveEvent.html b/docs/source-class-LINE.LINEBot.Event.LeaveEvent.html index 576b55fd..31d0ea3e 100644 --- a/docs/source-class-LINE.LINEBot.Event.LeaveEvent.html +++ b/docs/source-class-LINE.LINEBot.Event.LeaveEvent.html @@ -244,7 +244,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.MessageEvent.AudioMessage.html b/docs/source-class-LINE.LINEBot.Event.MessageEvent.AudioMessage.html index f52dd06b..5143a90f 100644 --- a/docs/source-class-LINE.LINEBot.Event.MessageEvent.AudioMessage.html +++ b/docs/source-class-LINE.LINEBot.Event.MessageEvent.AudioMessage.html @@ -246,7 +246,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.MessageEvent.ImageMessage.html b/docs/source-class-LINE.LINEBot.Event.MessageEvent.ImageMessage.html index e2db484a..1eda6dd8 100644 --- a/docs/source-class-LINE.LINEBot.Event.MessageEvent.ImageMessage.html +++ b/docs/source-class-LINE.LINEBot.Event.MessageEvent.ImageMessage.html @@ -246,7 +246,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.MessageEvent.LocationMessage.html b/docs/source-class-LINE.LINEBot.Event.MessageEvent.LocationMessage.html index a5756e3e..6a91042e 100644 --- a/docs/source-class-LINE.LINEBot.Event.MessageEvent.LocationMessage.html +++ b/docs/source-class-LINE.LINEBot.Event.MessageEvent.LocationMessage.html @@ -286,7 +286,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.MessageEvent.StickerMessage.html b/docs/source-class-LINE.LINEBot.Event.MessageEvent.StickerMessage.html index de0d1bcc..c3198c1b 100644 --- a/docs/source-class-LINE.LINEBot.Event.MessageEvent.StickerMessage.html +++ b/docs/source-class-LINE.LINEBot.Event.MessageEvent.StickerMessage.html @@ -266,7 +266,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.MessageEvent.TextMessage.html b/docs/source-class-LINE.LINEBot.Event.MessageEvent.TextMessage.html index 1f8c8a28..a5d0f8fa 100644 --- a/docs/source-class-LINE.LINEBot.Event.MessageEvent.TextMessage.html +++ b/docs/source-class-LINE.LINEBot.Event.MessageEvent.TextMessage.html @@ -256,7 +256,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.MessageEvent.VideoMessage.html b/docs/source-class-LINE.LINEBot.Event.MessageEvent.VideoMessage.html index 413d4812..3f6e06f0 100644 --- a/docs/source-class-LINE.LINEBot.Event.MessageEvent.VideoMessage.html +++ b/docs/source-class-LINE.LINEBot.Event.MessageEvent.VideoMessage.html @@ -246,7 +246,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.MessageEvent.html b/docs/source-class-LINE.LINEBot.Event.MessageEvent.html index 9b0121ed..2829d681 100644 --- a/docs/source-class-LINE.LINEBot.Event.MessageEvent.html +++ b/docs/source-class-LINE.LINEBot.Event.MessageEvent.html @@ -271,7 +271,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.Parser.EventRequestParser.html b/docs/source-class-LINE.LINEBot.Event.Parser.EventRequestParser.html index 7c699fb4..83b87864 100644 --- a/docs/source-class-LINE.LINEBot.Event.Parser.EventRequestParser.html +++ b/docs/source-class-LINE.LINEBot.Event.Parser.EventRequestParser.html @@ -314,7 +314,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.PostbackEvent.html b/docs/source-class-LINE.LINEBot.Event.PostbackEvent.html index 3dcbddd3..46a89f41 100644 --- a/docs/source-class-LINE.LINEBot.Event.PostbackEvent.html +++ b/docs/source-class-LINE.LINEBot.Event.PostbackEvent.html @@ -254,7 +254,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Event.UnfollowEvent.html b/docs/source-class-LINE.LINEBot.Event.UnfollowEvent.html index 6345f965..b8cd3c45 100644 --- a/docs/source-class-LINE.LINEBot.Event.UnfollowEvent.html +++ b/docs/source-class-LINE.LINEBot.Event.UnfollowEvent.html @@ -244,7 +244,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Exception.CurlExecutionException.html b/docs/source-class-LINE.LINEBot.Exception.CurlExecutionException.html index 28942a07..5849a1f3 100644 --- a/docs/source-class-LINE.LINEBot.Exception.CurlExecutionException.html +++ b/docs/source-class-LINE.LINEBot.Exception.CurlExecutionException.html @@ -235,7 +235,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Exception.InvalidEventRequestException.html b/docs/source-class-LINE.LINEBot.Exception.InvalidEventRequestException.html index 4deece2a..bb73528a 100644 --- a/docs/source-class-LINE.LINEBot.Exception.InvalidEventRequestException.html +++ b/docs/source-class-LINE.LINEBot.Exception.InvalidEventRequestException.html @@ -235,7 +235,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Exception.InvalidEventSourceException.html b/docs/source-class-LINE.LINEBot.Exception.InvalidEventSourceException.html index 387164d7..f04d0ea4 100644 --- a/docs/source-class-LINE.LINEBot.Exception.InvalidEventSourceException.html +++ b/docs/source-class-LINE.LINEBot.Exception.InvalidEventSourceException.html @@ -235,7 +235,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Exception.InvalidSignatureException.html b/docs/source-class-LINE.LINEBot.Exception.InvalidSignatureException.html index 8d80f105..40aabac6 100644 --- a/docs/source-class-LINE.LINEBot.Exception.InvalidSignatureException.html +++ b/docs/source-class-LINE.LINEBot.Exception.InvalidSignatureException.html @@ -234,7 +234,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Exception.UnknownEventTypeException.html b/docs/source-class-LINE.LINEBot.Exception.UnknownEventTypeException.html index 061b7ecd..a5f5ce37 100644 --- a/docs/source-class-LINE.LINEBot.Exception.UnknownEventTypeException.html +++ b/docs/source-class-LINE.LINEBot.Exception.UnknownEventTypeException.html @@ -235,7 +235,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Exception.UnknownMessageTypeException.html b/docs/source-class-LINE.LINEBot.Exception.UnknownMessageTypeException.html index 60794018..2ce61564 100644 --- a/docs/source-class-LINE.LINEBot.Exception.UnknownMessageTypeException.html +++ b/docs/source-class-LINE.LINEBot.Exception.UnknownMessageTypeException.html @@ -235,7 +235,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.HTTPClient.Curl.html b/docs/source-class-LINE.LINEBot.HTTPClient.Curl.html index 3f7d5626..47522b35 100644 --- a/docs/source-class-LINE.LINEBot.HTTPClient.Curl.html +++ b/docs/source-class-LINE.LINEBot.HTTPClient.Curl.html @@ -304,7 +304,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html b/docs/source-class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html index 811bef71..e7eff48b 100644 --- a/docs/source-class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html +++ b/docs/source-class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html @@ -199,7 +199,7 @@

Exceptions

-
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 
+
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 
<?php
 
 /**
@@ -237,7 +237,7 @@ 

Exceptions

/** @var array */ private $authHeaders; /** @var array */ - private $userAgentHeader = ['User-Agent: LINE-BotSDK-PHP/' . Meta::VERSION]; + private $userAgentHeader; /** * CurlHTTPClient constructor. @@ -249,98 +249,101 @@

Exceptions

$this->authHeaders = [ "Authorization: Bearer $channelToken", ]; - } - - /** - * Sends GET request to LINE Messaging API. - * - * @param string $url Request URL. - * @return Response Response of API request. - */ - public function get($url) - { - return $this->sendRequest('GET', $url, [], []); - } - - /** - * Sends POST request to LINE Messaging API. - * - * @param string $url Request URL. - * @param array $data Request body. - * @return Response Response of API request. - */ - public function post($url, array $data) - { - return $this->sendRequest('POST', $url, ['Content-Type: application/json; charset=utf-8'], $data); - } - - /** - * @param string $method - * @param string $url - * @param array $additionalHeader - * @param array $reqBody - * @return Response - * @throws CurlExecutionException - */ - private function sendRequest($method, $url, array $additionalHeader, array $reqBody) - { - $curl = new Curl($url); - - $headers = array_merge($this->authHeaders, $this->userAgentHeader, $additionalHeader); - - $options = [ - CURLOPT_CUSTOMREQUEST => $method, - CURLOPT_HTTPHEADER => $headers, - CURLOPT_HEADER => false, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_BINARYTRANSFER => true, - CURLOPT_HEADER => true, - ]; - - if ($method === 'POST') { - if (empty($reqBody)) { - // Rel: https://github.com/line/line-bot-sdk-php/issues/35 - $options[CURLOPT_HTTPHEADER][] = 'Content-Length: 0'; - } else { - $options[CURLOPT_POSTFIELDS] = json_encode($reqBody); - } - } - - $curl->setoptArray($options); - - $result = $curl->exec(); - - if ($curl->errno()) { - throw new CurlExecutionException($curl->error()); - } - - $info = $curl->getinfo(); - $httpStatus = $info['http_code']; + $this->userAgentHeader = [ + 'User-Agent: LINE-BotSDK-PHP/' . Meta::VERSION, + ]; + } + + /** + * Sends GET request to LINE Messaging API. + * + * @param string $url Request URL. + * @return Response Response of API request. + */ + public function get($url) + { + return $this->sendRequest('GET', $url, [], []); + } + + /** + * Sends POST request to LINE Messaging API. + * + * @param string $url Request URL. + * @param array $data Request body. + * @return Response Response of API request. + */ + public function post($url, array $data) + { + return $this->sendRequest('POST', $url, ['Content-Type: application/json; charset=utf-8'], $data); + } + + /** + * @param string $method + * @param string $url + * @param array $additionalHeader + * @param array $reqBody + * @return Response + * @throws CurlExecutionException + */ + private function sendRequest($method, $url, array $additionalHeader, array $reqBody) + { + $curl = new Curl($url); + + $headers = array_merge($this->authHeaders, $this->userAgentHeader, $additionalHeader); + + $options = [ + CURLOPT_CUSTOMREQUEST => $method, + CURLOPT_HTTPHEADER => $headers, + CURLOPT_HEADER => false, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_BINARYTRANSFER => true, + CURLOPT_HEADER => true, + ]; + + if ($method === 'POST') { + if (empty($reqBody)) { + // Rel: https://github.com/line/line-bot-sdk-php/issues/35 + $options[CURLOPT_HTTPHEADER][] = 'Content-Length: 0'; + } else { + $options[CURLOPT_POSTFIELDS] = json_encode($reqBody); + } + } + + $curl->setoptArray($options); + + $result = $curl->exec(); + + if ($curl->errno()) { + throw new CurlExecutionException($curl->error()); + } - $responseHeaderSize = $info['header_size']; - - $responseHeaderStr = substr($result, 0, $responseHeaderSize); - $responseHeaders = []; - foreach (explode("\r\n", $responseHeaderStr) as $responseHeader) { - $kv = explode(':', $responseHeader, 2); - if (count($kv) === 2) { - $responseHeaders[$kv[0]] = trim($kv[1]); - } - } - - $body = substr($result, $responseHeaderSize); - - return new Response($httpStatus, $body, $responseHeaders); - } -} -
+ $info = $curl->getinfo(); + $httpStatus = $info['http_code']; + + $responseHeaderSize = $info['header_size']; + + $responseHeaderStr = substr($result, 0, $responseHeaderSize); + $responseHeaders = []; + foreach (explode("\r\n", $responseHeaderStr) as $responseHeader) { + $kv = explode(':', $responseHeader, 2); + if (count($kv) === 2) { + $responseHeaders[$kv[0]] = trim($kv[1]); + } + } + + $body = substr($result, $responseHeaderSize); + + return new Response($httpStatus, $body, $responseHeaders); + } +} + - + diff --git a/docs/source-class-LINE.LINEBot.HTTPClient.html b/docs/source-class-LINE.LINEBot.HTTPClient.html index e060b19b..d18d5f36 100644 --- a/docs/source-class-LINE.LINEBot.HTTPClient.html +++ b/docs/source-class-LINE.LINEBot.HTTPClient.html @@ -253,7 +253,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.AreaBuilder.html b/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.AreaBuilder.html index a111520d..830aca3d 100644 --- a/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.AreaBuilder.html +++ b/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.AreaBuilder.html @@ -274,7 +274,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.ImagemapMessageActionBuilder.html b/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.ImagemapMessageActionBuilder.html index 45ef9519..99ad3079 100644 --- a/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.ImagemapMessageActionBuilder.html +++ b/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.ImagemapMessageActionBuilder.html @@ -268,7 +268,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.ImagemapUriActionBuilder.html b/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.ImagemapUriActionBuilder.html index 8d890b0a..dbb1d0f8 100644 --- a/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.ImagemapUriActionBuilder.html +++ b/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.ImagemapUriActionBuilder.html @@ -266,7 +266,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.html b/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.html index 46dda34f..40bbbbc6 100644 --- a/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.html +++ b/docs/source-class-LINE.LINEBot.ImagemapActionBuilder.html @@ -241,7 +241,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.AudioMessageBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.AudioMessageBuilder.html index 5e203e92..0fe0863e 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.AudioMessageBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.AudioMessageBuilder.html @@ -269,7 +269,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.ImageMessageBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.ImageMessageBuilder.html index 4face36a..527e3175 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.ImageMessageBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.ImageMessageBuilder.html @@ -270,7 +270,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.Imagemap.BaseSizeBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.Imagemap.BaseSizeBuilder.html index fb09ca9d..889fb43c 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.Imagemap.BaseSizeBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.Imagemap.BaseSizeBuilder.html @@ -264,7 +264,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.ImagemapMessageBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.ImagemapMessageBuilder.html index 68b6ace7..676486d6 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.ImagemapMessageBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.ImagemapMessageBuilder.html @@ -294,7 +294,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.LocationMessageBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.LocationMessageBuilder.html index 72b7d785..15dfea0d 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.LocationMessageBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.LocationMessageBuilder.html @@ -280,7 +280,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.MultiMessageBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.MultiMessageBuilder.html index 1fdd33ed..b0f262b8 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.MultiMessageBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.MultiMessageBuilder.html @@ -263,7 +263,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.StickerMessageBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.StickerMessageBuilder.html index 7d4eec10..7ac7dbc8 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.StickerMessageBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.StickerMessageBuilder.html @@ -270,7 +270,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.ButtonTemplateBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.ButtonTemplateBuilder.html index ebf42658..030e95c2 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.ButtonTemplateBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.ButtonTemplateBuilder.html @@ -293,7 +293,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.CarouselColumnTemplateBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.CarouselColumnTemplateBuilder.html index d02022ff..a76207e4 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.CarouselColumnTemplateBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.CarouselColumnTemplateBuilder.html @@ -291,7 +291,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.CarouselTemplateBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.CarouselTemplateBuilder.html index 7fd743a0..508ff213 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.CarouselTemplateBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.CarouselTemplateBuilder.html @@ -277,7 +277,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.ConfirmTemplateBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.ConfirmTemplateBuilder.html index e3cf99d6..f237047f 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.ConfirmTemplateBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.ConfirmTemplateBuilder.html @@ -283,7 +283,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.html index e0069e94..48152e0c 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateBuilder.html @@ -241,7 +241,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateMessageBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateMessageBuilder.html index cc6a4106..10438788 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateMessageBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.TemplateMessageBuilder.html @@ -269,7 +269,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.TextMessageBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.TextMessageBuilder.html index c51d197b..60114d8f 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.TextMessageBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.TextMessageBuilder.html @@ -199,7 +199,7 @@

Exceptions

-
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 
+
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 
<?php
 
 /**
@@ -238,43 +238,56 @@ 

Exceptions

/** * TextMessageBuilder constructor. * - * @param string $text - * @param string[] $extraTexts - */ - public function __construct($text, ...$extraTexts) - { - $this->texts = array_merge([$text], $extraTexts); - } - - /** - * Builds text message structure. - * - * @return array - */ - public function buildMessage() - { - if (!empty($this->message)) { - return $this->message; +
* Exact signature of this constructor is <code>new TextMessageBuilder(string $text, string[] $extraTexts)</code>. + * + * Means, this constructor can also receive multiple messages like so; + * + * <code> + * $textBuilder = new TextMessageBuilder('text', 'extra text1', 'extra text2', ...); + * </code> + * + * @param string $text + * @param string[]|null $extraTexts + */ + public function __construct($text, $extraTexts = null) + { + $extra = []; + if (!is_null($extraTexts)) { + $args = func_get_args(); + $extra = array_slice($args, 1); } - - foreach ($this->texts as $text) { - $this->message[] = [ - 'type' => MessageType::TEXT, - 'text' => $text, - ]; - } - - return $this->message; - } -} -
+ $this->texts = array_merge([$text], $extra); + } + + /** + * Builds text message structure. + * + * @return array + */ + public function buildMessage() + { + if (!empty($this->message)) { + return $this->message; + } + + foreach ($this->texts as $text) { + $this->message[] = [ + 'type' => MessageType::TEXT, + 'text' => $text, + ]; + } + + return $this->message; + } +} + - + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.VideoMessageBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.VideoMessageBuilder.html index 2dc5c264..80c48ce3 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.VideoMessageBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.VideoMessageBuilder.html @@ -270,7 +270,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.MessageBuilder.html b/docs/source-class-LINE.LINEBot.MessageBuilder.html index 807dd039..5fef2a0f 100644 --- a/docs/source-class-LINE.LINEBot.MessageBuilder.html +++ b/docs/source-class-LINE.LINEBot.MessageBuilder.html @@ -241,7 +241,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.Response.html b/docs/source-class-LINE.LINEBot.Response.html index 49447db2..a6969e55 100644 --- a/docs/source-class-LINE.LINEBot.Response.html +++ b/docs/source-class-LINE.LINEBot.Response.html @@ -319,7 +319,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.SignatureValidator.html b/docs/source-class-LINE.LINEBot.SignatureValidator.html index 542ee534..e55c5699 100644 --- a/docs/source-class-LINE.LINEBot.SignatureValidator.html +++ b/docs/source-class-LINE.LINEBot.SignatureValidator.html @@ -254,7 +254,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.TemplateActionBuilder.MessageTemplateActionBuilder.html b/docs/source-class-LINE.LINEBot.TemplateActionBuilder.MessageTemplateActionBuilder.html index 8ba7dcbd..4830960e 100644 --- a/docs/source-class-LINE.LINEBot.TemplateActionBuilder.MessageTemplateActionBuilder.html +++ b/docs/source-class-LINE.LINEBot.TemplateActionBuilder.MessageTemplateActionBuilder.html @@ -268,7 +268,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.TemplateActionBuilder.PostbackTemplateActionBuilder.html b/docs/source-class-LINE.LINEBot.TemplateActionBuilder.PostbackTemplateActionBuilder.html index 92147c3e..e8578809 100644 --- a/docs/source-class-LINE.LINEBot.TemplateActionBuilder.PostbackTemplateActionBuilder.html +++ b/docs/source-class-LINE.LINEBot.TemplateActionBuilder.PostbackTemplateActionBuilder.html @@ -279,7 +279,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.TemplateActionBuilder.UriTemplateActionBuilder.html b/docs/source-class-LINE.LINEBot.TemplateActionBuilder.UriTemplateActionBuilder.html index 3dc9bd64..52c34055 100644 --- a/docs/source-class-LINE.LINEBot.TemplateActionBuilder.UriTemplateActionBuilder.html +++ b/docs/source-class-LINE.LINEBot.TemplateActionBuilder.UriTemplateActionBuilder.html @@ -268,7 +268,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.TemplateActionBuilder.html b/docs/source-class-LINE.LINEBot.TemplateActionBuilder.html index 2f116d54..1039c84f 100644 --- a/docs/source-class-LINE.LINEBot.TemplateActionBuilder.html +++ b/docs/source-class-LINE.LINEBot.TemplateActionBuilder.html @@ -241,7 +241,7 @@

Exceptions

- + diff --git a/docs/source-class-LINE.LINEBot.html b/docs/source-class-LINE.LINEBot.html index 08b61509..1057d456 100644 --- a/docs/source-class-LINE.LINEBot.html +++ b/docs/source-class-LINE.LINEBot.html @@ -199,7 +199,7 @@

Exceptions

-
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 
+
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 
<?php
 
 /**
@@ -226,177 +226,195 @@ 

Exceptions

use LINE\LINEBot\MessageBuilder\TextMessageBuilder; use LINE\LINEBot\Response; use LINE\LINEBot\SignatureValidator; - -/** - * A client class of LINE Messaging API. - * - * @package LINE - */ -class LINEBot -{ - const DEFAULT_ENDPOINT_BASE = 'https://api.line.me'; - - /** @var string */ - private $channelSecret; - /** @var string */ - private $endpointBase; - /** @var HTTPClient */ - private $httpClient; - - /** - * LINEBot constructor. - * - * @param HTTPClient $httpClient HTTP client instance to use API calling. - * @param array $args Configurations. - */ - public function __construct(HTTPClient $httpClient, array $args) - { - $this->httpClient = $httpClient; - $this->channelSecret = $args['channelSecret']; - - $this->endpointBase = LINEBot::DEFAULT_ENDPOINT_BASE; - if (array_key_exists('endpointBase', $args) && !empty($args['endpointBase'])) { - $this->endpointBase = $args['endpointBase']; - } - } - - /** - * Gets specified user's profile through API calling. - * - * @param string $userId The user ID to retrieve profile. - * @return Response - */ - public function getProfile($userId) - { - return $this->httpClient->get($this->endpointBase . '/v2/bot/profile/' . urlencode($userId)); - } - - /** - * Gets message content which is associated with specified message ID. - * - * @param string $messageId The message ID to retrieve content. - * @return Response - */ - public function getMessageContent($messageId) - { - return $this->httpClient->get($this->endpointBase . '/v2/bot/message/' . urlencode($messageId) . '/content'); - } - - /** - * Replies arbitrary message to destination which is associated with reply token. - * - * @param string $replyToken Identifier of destination. - * @param MessageBuilder $messageBuilder Message builder to send. - * @return Response - */ - public function replyMessage($replyToken, MessageBuilder $messageBuilder) - { - return $this->httpClient->post($this->endpointBase . '/v2/bot/message/reply', [ - 'replyToken' => $replyToken, - 'messages' => $messageBuilder->buildMessage(), - ]); - } - - /** - * Replies text message(s) to destination which is associated with reply token. - * - * This method receives variable texts. It can send text(s) message as bulk. - * - * @param string $replyToken Identifier of destination. - * @param string $text Text of message. - * @param string[] $extraTexts Extra text of message. - * @return Response - */ - public function replyText($replyToken, $text, ...$extraTexts) - { - $textMessageBuilder = new TextMessageBuilder($text, ...$extraTexts); - return $this->replyMessage($replyToken, $textMessageBuilder); - } - - /** - * Sends arbitrary message to destination. - * - * @param string $to Identifier of destination. - * @param MessageBuilder $messageBuilder Message builder to send. - * @return Response - */ - public function pushMessage($to, MessageBuilder $messageBuilder) - { - return $this->httpClient->post($this->endpointBase . '/v2/bot/message/push', [ - 'to' => $to, - 'messages' => $messageBuilder->buildMessage(), - ]); - } +use ReflectionClass; + +/** + * A client class of LINE Messaging API. + * + * @package LINE + */ +class LINEBot +{ + const DEFAULT_ENDPOINT_BASE = 'https://api.line.me'; + + /** @var string */ + private $channelSecret; + /** @var string */ + private $endpointBase; + /** @var HTTPClient */ + private $httpClient; + + /** + * LINEBot constructor. + * + * @param HTTPClient $httpClient HTTP client instance to use API calling. + * @param array $args Configurations. + */ + public function __construct(HTTPClient $httpClient, array $args) + { + $this->httpClient = $httpClient; + $this->channelSecret = $args['channelSecret']; + + $this->endpointBase = LINEBot::DEFAULT_ENDPOINT_BASE; + if (array_key_exists('endpointBase', $args) && !empty($args['endpointBase'])) { + $this->endpointBase = $args['endpointBase']; + } + } + + /** + * Gets specified user's profile through API calling. + * + * @param string $userId The user ID to retrieve profile. + * @return Response + */ + public function getProfile($userId) + { + return $this->httpClient->get($this->endpointBase . '/v2/bot/profile/' . urlencode($userId)); + } + + /** + * Gets message content which is associated with specified message ID. + * + * @param string $messageId The message ID to retrieve content. + * @return Response + */ + public function getMessageContent($messageId) + { + return $this->httpClient->get($this->endpointBase . '/v2/bot/message/' . urlencode($messageId) . '/content'); + } + + /** + * Replies arbitrary message to destination which is associated with reply token. + * + * @param string $replyToken Identifier of destination. + * @param MessageBuilder $messageBuilder Message builder to send. + * @return Response + */ + public function replyMessage($replyToken, MessageBuilder $messageBuilder) + { + return $this->httpClient->post($this->endpointBase . '/v2/bot/message/reply', [ + 'replyToken' => $replyToken, + 'messages' => $messageBuilder->buildMessage(), + ]); + } + + /** + * Replies text message(s) to destination which is associated with reply token. + * + * This method receives variable texts. It can send text(s) message as bulk. + * + * Exact signature of this method is <code>replyText(string $replyToken, string $text, string[] $extraTexts)</code>. + * + * Means, this method can also receive multiple texts like so; + * + * <code> + * $bot->replyText('reply-text', 'text', 'extra text1', 'extra text2', ...) + * </code> + * + * @param string $replyToken Identifier of destination. + * @param string $text Text of message. + * @param string[]|null $extraTexts Extra text of message. + * @return Response + */ + public function replyText($replyToken, $text, $extraTexts = null) + { + $extra = []; + if (!is_null($extraTexts)) { + $args = func_get_args(); + $extra = array_slice($args, 2); + } + + /** @var TextMessageBuilder $textMessageBuilder */ + $ref = new ReflectionClass('LINE\LINEBot\MessageBuilder\TextMessageBuilder'); + $textMessageBuilder = $ref->newInstanceArgs(array_merge([$text], $extra)); - /** - * Sends arbitrary message to multi destinations. - * - * @param array $tos Identifiers of destination. - * @param MessageBuilder $messageBuilder Message builder to send. - * @return Response - */ - public function multicast(array $tos, MessageBuilder $messageBuilder) - { - return $this->httpClient->post($this->endpointBase . '/v2/bot/message/multicast', [ - 'to' => $tos, - 'messages' => $messageBuilder->buildMessage(), - ]); - } - - /** - * Leaves from group. - * - * @param string $groupId Identifier of group to leave. - * @return Response - */ - public function leaveGroup($groupId) - { - return $this->httpClient->post($this->endpointBase . '/v2/bot/group/' . urlencode($groupId) . '/leave', []); - } - - /** - * Leaves from room. - * - * @param string $roomId Identifier of room to leave. - * @return Response - */ - public function leaveRoom($roomId) - { - return $this->httpClient->post($this->endpointBase . '/v2/bot/room/' . urlencode($roomId) . '/leave', []); - } - - /** - * Parse event request to Event objects. - * - * @param string $body Request body. - * @param string $signature Signature of request. - * @return LINEBot\Event\BaseEvent[] - */ - public function parseEventRequest($body, $signature) - { - return EventRequestParser::parseEventRequest($body, $this->channelSecret, $signature); - } - - /** - * Validate request with signature. - * - * @param string $body Request body. - * @param string $signature Signature of request. - * @return bool Request is valid or not. - */ - public function validateSignature($body, $signature) - { - return SignatureValidator::validateSignature($body, $this->channelSecret, $signature); - } -} -
+ return $this->replyMessage($replyToken, $textMessageBuilder); + } + + /** + * Sends arbitrary message to destination. + * + * @param string $to Identifier of destination. + * @param MessageBuilder $messageBuilder Message builder to send. + * @return Response + */ + public function pushMessage($to, MessageBuilder $messageBuilder) + { + return $this->httpClient->post($this->endpointBase . '/v2/bot/message/push', [ + 'to' => $to, + 'messages' => $messageBuilder->buildMessage(), + ]); + } + + /** + * Sends arbitrary message to multi destinations. + * + * @param array $tos Identifiers of destination. + * @param MessageBuilder $messageBuilder Message builder to send. + * @return Response + */ + public function multicast(array $tos, MessageBuilder $messageBuilder) + { + return $this->httpClient->post($this->endpointBase . '/v2/bot/message/multicast', [ + 'to' => $tos, + 'messages' => $messageBuilder->buildMessage(), + ]); + } + + /** + * Leaves from group. + * + * @param string $groupId Identifier of group to leave. + * @return Response + */ + public function leaveGroup($groupId) + { + return $this->httpClient->post($this->endpointBase . '/v2/bot/group/' . urlencode($groupId) . '/leave', []); + } + + /** + * Leaves from room. + * + * @param string $roomId Identifier of room to leave. + * @return Response + */ + public function leaveRoom($roomId) + { + return $this->httpClient->post($this->endpointBase . '/v2/bot/room/' . urlencode($roomId) . '/leave', []); + } + + /** + * Parse event request to Event objects. + * + * @param string $body Request body. + * @param string $signature Signature of request. + * @return LINEBot\Event\BaseEvent[] + */ + public function parseEventRequest($body, $signature) + { + return EventRequestParser::parseEventRequest($body, $this->channelSecret, $signature); + } + + /** + * Validate request with signature. + * + * @param string $body Request body. + * @param string $signature Signature of request. + * @return bool Request is valid or not. + */ + public function validateSignature($body, $signature) + { + return SignatureValidator::validateSignature($body, $this->channelSecret, $signature); + } +} + - +