Skip to content

Commit eccfbf2

Browse files
authored
Update documents and examples to use the constructor which sets the discriminator value automatically (#755)
Update documents and examples related to #752
1 parent 6b04844 commit eccfbf2

16 files changed

+9
-117
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ You can call an API through the messagingApi instance.
5757
A very simple example:
5858

5959
```php
60-
$message = new TextMessage(['type' => 'text','text' => 'hello!']);
60+
$message = new TextMessage(['text' => 'hello!']);
6161
$request = new ReplyMessageRequest([
6262
'replyToken' => '<reply token>',
6363
'messages' => [$message],
@@ -71,7 +71,6 @@ We also support setter style.
7171

7272
```php
7373
$message = (new TextMessage())
74-
->setType(\LINE\Constants\MessageType::TEXT)
7574
->setText('hello!');
7675
$request = (new ReplyMessageRequest)
7776
->setReplyToken('<reply token>')
@@ -92,7 +91,7 @@ You may need to store the `x-line-request-id` header obtained as a response from
9291
```php
9392
$request = new ReplyMessageRequest([
9493
'replyToken' => $replyToken,
95-
'messages' => [$textMessage = (new TextMessage(['text' => 'reply with http info', 'type' => MessageType::TEXT]))],
94+
'messages' => [$textMessage = (new TextMessage(['text' => 'reply with http info']))],
9695
]);
9796
$response = $messagingApi->replyMessageWithHttpInfo($request);
9897
$this->logger->info('body:' . $response[0]);

examples/EchoBot/src/LINEBot/EchoBot/Route.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function register(\Slim\App $app)
6767
$bot->replyMessage(new ReplyMessageRequest([
6868
'replyToken' => $event->getReplyToken(),
6969
'messages' => [
70-
(new TextMessage(['text' => $replyText]))->setType('text'),
70+
(new TextMessage(['text' => $replyText])),
7171
],
7272
]));
7373
}

examples/KitchenSink/src/LINEBot/KitchenSink/EventHandler/AccountLinkEventHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use LINE\Clients\MessagingApi\Api\MessagingApiApi;
2222
use LINE\Clients\MessagingApi\Model\ReplyMessageRequest;
2323
use LINE\Clients\MessagingApi\Model\TextMessage;
24-
use LINE\Constants\MessageType;
2524
use LINE\Webhook\Model\AccountLinkEvent;
2625

2726
class AccountLinkEventHandler
@@ -56,7 +55,6 @@ public function handle()
5655
'replyToken' => $this->accountLinkEvent->getReplyToken(),
5756
'messages' => [
5857
new TextMessage([
59-
'type' => MessageType::TEXT,
6058
'text' => 'Got account link event ' . $link->getNonce(),
6159
]),
6260
],

examples/KitchenSink/src/LINEBot/KitchenSink/EventHandler/BeaconEventHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use LINE\Clients\MessagingApi\Api\MessagingApiApi;
2222
use LINE\Clients\MessagingApi\Model\ReplyMessageRequest;
2323
use LINE\Clients\MessagingApi\Model\TextMessage;
24-
use LINE\Constants\MessageType;
2524
use LINE\LINEBot\KitchenSink\EventHandler;
2625
use LINE\Webhook\Model\BeaconEvent;
2726

@@ -55,7 +54,7 @@ public function handle()
5554
$request = new ReplyMessageRequest([
5655
'replyToken' => $this->beaconEvent->getReplyToken(),
5756
'messages' => [
58-
new TextMessage(['type' => MessageType::TEXT, 'text' => 'Got beacon message ' . $this->beaconEvent->getHwid()]),
57+
new TextMessage(['text' => 'Got beacon message ' . $this->beaconEvent->getHwid()]),
5958
],
6059
]);
6160
$this->bot->replyMessage($request);

examples/KitchenSink/src/LINEBot/KitchenSink/EventHandler/FollowEventHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use LINE\Clients\MessagingApi\Api\MessagingApiApi;
2222
use LINE\Clients\MessagingApi\Model\ReplyMessageRequest;
2323
use LINE\Clients\MessagingApi\Model\TextMessage;
24-
use LINE\Constants\MessageType;
2524
use LINE\LINEBot\KitchenSink\EventHandler;
2625
use LINE\Webhook\Model\FollowEvent;
2726

@@ -55,7 +54,7 @@ public function handle()
5554
$request = new ReplyMessageRequest([
5655
'replyToken' => $this->followEvent->getReplyToken(),
5756
'messages' => [
58-
new TextMessage(['type' => MessageType::TEXT, 'text' => 'Got followed event']),
57+
new TextMessage(['text' => 'Got followed event']),
5958
],
6059
]);
6160
$this->bot->replyMessage($request);

examples/KitchenSink/src/LINEBot/KitchenSink/EventHandler/JoinEventHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use LINE\Clients\MessagingApi\Api\MessagingApiApi;
2222
use LINE\Clients\MessagingApi\Model\ReplyMessageRequest;
2323
use LINE\Clients\MessagingApi\Model\TextMessage;
24-
use LINE\Constants\MessageType;
2524
use LINE\LINEBot\KitchenSink\EventHandler;
2625
use LINE\Webhook\Model\GroupSource;
2726
use LINE\Webhook\Model\JoinEvent;
@@ -69,7 +68,6 @@ public function handle()
6968
'replyToken' => $this->joinEvent->getReplyToken(),
7069
'messages' => [
7170
new TextMessage([
72-
'type' => MessageType::TEXT,
7371
'text' => sprintf('Joined %s %s', $this->joinEvent->getType(), $id),
7472
]),
7573
],

examples/KitchenSink/src/LINEBot/KitchenSink/EventHandler/MemberJoinedEventHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use LINE\Clients\MessagingApi\Api\MessagingApiApi;
2222
use LINE\Clients\MessagingApi\Model\ReplyMessageRequest;
2323
use LINE\Clients\MessagingApi\Model\TextMessage;
24-
use LINE\Constants\MessageType;
2524
use LINE\LINEBot\KitchenSink\EventHandler;
2625
use LINE\Webhook\Model\GroupSource;
2726
use LINE\Webhook\Model\MemberJoinedEvent;
@@ -74,7 +73,6 @@ public function handle()
7473
'replyToken' => $this->memberJoinedEvent->getReplyToken(),
7574
'messages' => [
7675
new TextMessage([
77-
'type' => MessageType::TEXT,
7876
'text' => sprintf('%s joined. %s %s', implode(", ", $joinedMemberIds), $this->memberJoinedEvent->getType(), $id),
7977
]),
8078
],

examples/KitchenSink/src/LINEBot/KitchenSink/EventHandler/MessageHandler/AudioMessageHandler.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323
use LINE\Clients\MessagingApi\Model\AudioMessage;
2424
use LINE\Clients\MessagingApi\Model\ReplyMessageRequest;
2525
use LINE\Constants\MessageContentProviderType;
26-
use LINE\Constants\MessageType;
2726
use LINE\LINEBot\KitchenSink\EventHandler;
2827
use LINE\LINEBot\KitchenSink\EventHandler\MessageHandler\Util\UrlBuilder;
2928
use LINE\Webhook\Model\AudioMessageContent;
3029
use LINE\Webhook\Model\MessageEvent;
31-
use SplFileObject;
3230

3331
class AudioMessageHandler implements EventHandler
3432
{
@@ -94,7 +92,6 @@ public function handle()
9492
private function replyAudioMessage(string $replyToken, string $url, int $duration)
9593
{
9694
$message = new AudioMessage([
97-
'type' => MessageType::AUDIO,
9895
'originalContentUrl' => $url,
9996
'duration' => $duration,
10097
]);

examples/KitchenSink/src/LINEBot/KitchenSink/EventHandler/MessageHandler/Flex/FlexSampleRestaurant.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use LINE\Clients\MessagingApi\Model\FlexSpan;
3131
use LINE\Clients\MessagingApi\Model\FlexText;
3232
use LINE\Clients\MessagingApi\Model\URIAction;
33-
use LINE\Constants\ActionType;
3433
use LINE\Constants\Flex\BubbleContainerSize;
3534
use LINE\Constants\Flex\ComponentButtonHeight;
3635
use LINE\Constants\Flex\ComponentButtonStyle;
@@ -44,9 +43,6 @@
4443
use LINE\Constants\Flex\ComponentMargin;
4544
use LINE\Constants\Flex\ComponentSpaceSize;
4645
use LINE\Constants\Flex\ComponentSpacing;
47-
use LINE\Constants\Flex\ComponentType;
48-
use LINE\Constants\Flex\ContainerType;
49-
use LINE\Constants\MessageType;
5046

5147
/**
5248
* @SuppressWarnings("PHPMD.CouplingBetweenObjects")
@@ -61,10 +57,8 @@ class FlexSampleRestaurant
6157
public static function get(): FlexMessage
6258
{
6359
return new FlexMessage([
64-
'type' => MessageType::FLEX,
6560
'altText' => 'Restaurant',
6661
'contents' => new FlexBubble([
67-
'type' => ContainerType::BUBBLE,
6862
'hero' => self::createHeroBlock(),
6963
'body' => self::createBodyBlock(),
7064
'footer' => self::createFooterBlock(),
@@ -76,13 +70,11 @@ public static function get(): FlexMessage
7670
private static function createHeroBlock(): FlexComponent
7771
{
7872
return new FlexImage([
79-
'type' => ComponentType::IMAGE,
8073
'url' => 'https://example.com/cafe.png',
8174
'size' => ComponentImageSize::FULL,
8275
'aspectRatio' => ComponentImageAspectRatio::R20TO13,
8376
'aspectMode' => ComponentImageAspectMode::COVER,
8477
'action' => new URIAction([
85-
'type' => ActionType::URI,
8678
'label' => 'cafe hero',
8779
'uri' => 'https://example.com',
8880
'altUri' => new AltUri(['desktop' => 'https://example.com#desktop']),
@@ -93,14 +85,12 @@ private static function createHeroBlock(): FlexComponent
9385
private static function createBodyBlock()
9486
{
9587
return new FlexBox([
96-
'type' => ComponentType::BOX,
9788
'layout' => ComponentLayout::VERTICAL,
9889
'backgroundColor' => '#fafafa',
9990
'paddingAll' => '8%',
10091
'contents' => [
10192
// Title
10293
new FlexText([
103-
'type' => ComponentType::TEXT,
10494
'text' => 'Brown Cafe',
10595
'weight' => ComponentFontWeight::BOLD,
10696
'size' => ComponentFontSize::XL,
@@ -114,17 +104,14 @@ private static function createBodyBlock()
114104
private static function createBodyReview(): FlexBox
115105
{
116106
$goldStar = new FlexIcon([
117-
'type' => ComponentType::ICON,
118107
'url' => 'https://example.com/gold_star.png',
119108
'size' => ComponentIconSize::SM,
120109
]);
121110
$grayStar = new FlexIcon([
122-
'type' => ComponentType::ICON,
123111
'url' => 'https://example.com/gray_star.png',
124112
'size' => ComponentIconSize::SM,
125113
]);
126114
$point = new FlexText([
127-
'type' => ComponentType::TEXT,
128115
'text' => '4.0',
129116
'size' => ComponentFontSize::SM,
130117
'color' => '#999999',
@@ -133,7 +120,6 @@ private static function createBodyReview(): FlexBox
133120
]);
134121

135122
return new FlexBox([
136-
'type' => ComponentType::BOX,
137123
'layout' => ComponentLayout::BASELINE,
138124
'margin' => ComponentMargin::MD,
139125
'contents' => [$goldStar, $goldStar, $goldStar, $goldStar, $grayStar, $point],
@@ -143,19 +129,16 @@ private static function createBodyReview(): FlexBox
143129
private static function createBodyInfoBlock(): FlexBox
144130
{
145131
$place = new FlexBox([
146-
'type' => ComponentType::BOX,
147132
'layout' => ComponentLayout::BASELINE,
148133
'spacing' => ComponentSpacing::SM,
149134
'contents' => [
150135
new FlexText([
151-
'type' => ComponentType::TEXT,
152136
'text' => 'Place',
153137
'color' => '#aaaaaa',
154138
'size' => ComponentFontSize::SM,
155139
'flex' => 1,
156140
]),
157141
new FlexText([
158-
'type' => ComponentType::TEXT,
159142
'text' => 'Miraina Tower, 4-1-6 Shinjuku, Tokyo',
160143
'wrap' => true,
161144
'color' => '#666666',
@@ -165,37 +148,31 @@ private static function createBodyInfoBlock(): FlexBox
165148
],
166149
]);
167150
$time = new FlexBox([
168-
'type' => ComponentType::BOX,
169151
'layout' => ComponentLayout::BASELINE,
170152
'spacing' => ComponentSpacing::SM,
171153
'contents' => [
172154
new FlexText([
173-
'type' => ComponentType::TEXT,
174155
'text' => 'Time',
175156
'color' => '#aaaaaa',
176157
'size' => ComponentFontSize::SM,
177158
'flex' => 1,
178159
]),
179160
new FlexText([
180-
'type' => ComponentType::TEXT,
181161
'text' => '10:00 - 23:00',
182162
'wrap' => true,
183163
'color' => '#666666',
184164
'size' => ComponentFontSize::SM,
185165
'flex' => 5,
186166
'contents' => [
187167
new FlexSpan([
188-
'type' => ComponentType::SPAN,
189168
'text' => '10:00',
190169
]),
191170
new FlexSpan([
192-
'type' => ComponentType::SPAN,
193171
'text' => '-',
194172
'color' => '#a0a0a0',
195173
'size' => ComponentFontSize::XS,
196174
]),
197175
new FlexSpan([
198-
'type' => ComponentType::SPAN,
199176
'text' => '23:00',
200177
]),
201178
],
@@ -204,7 +181,6 @@ private static function createBodyInfoBlock(): FlexBox
204181
]);
205182

206183
return new FlexBox([
207-
'type' => ComponentType::BOX,
208184
'layout' => ComponentLayout::VERTICAL,
209185
'margin' => ComponentMargin::LG,
210186
'spacing' => ComponentSpacing::SM,
@@ -215,31 +191,26 @@ private static function createBodyInfoBlock(): FlexBox
215191
private static function createFooterBlock()
216192
{
217193
$callButton = new FlexButton([
218-
'type' => ComponentType::BUTTON,
219194
'style' => ComponentButtonStyle::LINK,
220195
'height' => ComponentButtonHeight::SM,
221196
'action' => new URIAction([
222-
'type' => ActionType::URI,
223197
'label' => 'CALL',
224198
'uri' => 'https://example.com',
225199
'altUri' => new AltUri(['desktop' => 'https://example.com#desktop']),
226200
]),
227201
]);
228202
$websiteButton = new FlexButton([
229-
'type' => ComponentType::BUTTON,
230203
'style' => ComponentButtonStyle::LINK,
231204
'height' => ComponentButtonHeight::SM,
232205
'action' => new URIAction([
233-
'type' => ActionType::URI,
234206
'label' => 'WEBSITE',
235207
'uri' => 'https://example.com',
236208
'altUri' => new AltUri(['desktop' => 'https://example.com#desktop']),
237209
]),
238210
]);
239-
$spacer = new FlexSpacer(['type' => ComponentType::SPACER, 'size' => ComponentSpaceSize::SM]);
211+
$spacer = new FlexSpacer(['size' => ComponentSpaceSize::SM]);
240212

241213
return new FlexBox([
242-
'type' => ComponentType::BOX,
243214
'layout' => ComponentLayout::VERTICAL,
244215
'spacing' => ComponentSpacing::SM,
245216
'flex' => 0,

0 commit comments

Comments
 (0)