Skip to content

Commit 4eff309

Browse files
authored
Merge pull request #320 from moririnson/feature/flex-update2
Flex Update 2
2 parents 7b598bc + 79e7909 commit 4eff309

15 files changed

+341
-148
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2020 LINE Corporation
5+
*
6+
* LINE Corporation licenses this file to you under the Apache License,
7+
* version 2.0 (the "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at:
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
namespace LINE\LINEBot\Constant\Flex;
20+
21+
class ComponentAdjustMode
22+
{
23+
const SHRINK_TO_FIT = 'shrink-to-fit';
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2020 LINE Corporation
5+
*
6+
* LINE Corporation licenses this file to you under the Apache License,
7+
* version 2.0 (the "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at:
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
namespace LINE\LINEBot\Constant\Flex;
20+
21+
class ComponentAlignItems
22+
{
23+
const FLEX_START = 'flex-start';
24+
const FLEX_END = 'flex-end';
25+
const CENTER = 'center';
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2020 LINE Corporation
5+
*
6+
* LINE Corporation licenses this file to you under the Apache License,
7+
* version 2.0 (the "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at:
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
namespace LINE\LINEBot\Constant\Flex;
20+
21+
class ComponentBackgroundType
22+
{
23+
const LINEAR_GRADIENT = 'linearGradient';
24+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2020 LINE Corporation
5+
*
6+
* LINE Corporation licenses this file to you under the Apache License,
7+
* version 2.0 (the "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at:
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
* License for the specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
namespace LINE\LINEBot\Constant\Flex;
20+
21+
class ComponentJustifyContent
22+
{
23+
const FLEX_START = 'flex-start';
24+
const FLEX_END = 'flex-end';
25+
const CENTER = 'center';
26+
const SPACE_BETWEEN = 'space-between';
27+
const SPACE_AROUND = 'space-around';
28+
const SPACE_EVENLY = 'space-evenly';
29+
}

src/LINEBot/MessageBuilder/Flex/ComponentBuilder/BoxComponentBuilder.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
use LINE\LINEBot\Constant\Flex\ComponentSpacing;
2525
use LINE\LINEBot\Constant\Flex\ComponentType;
2626
use LINE\LINEBot\Constant\Flex\ComponentPosition;
27+
use LINE\LINEBot\Constant\Flex\ComponentJustifyContent;
28+
use LINE\LINEBot\Constant\Flex\ComponentAlignItems;
29+
use LINE\LINEBot\Constant\Flex\ComponentBackgroundType;
2730
use LINE\LINEBot\MessageBuilder\Flex\ComponentBuilder;
2831
use LINE\LINEBot\Util\BuildUtil;
2932

@@ -82,6 +85,24 @@ class BoxComponentBuilder implements ComponentBuilder
8285
/** @var string */
8386
private $offsetEnd;
8487

88+
/** @var ComponentJustifyContent */
89+
private $justifyContent;
90+
/** @var ComponentAlignItems */
91+
private $alignItems;
92+
93+
/** @var ComponentBackgroundType */
94+
private $backgroundType;
95+
/** @var string */
96+
private $backgroundAngle;
97+
/** @var string */
98+
private $backgroundStartColor;
99+
/** @var string */
100+
private $backgroundEndColor;
101+
/** @var string */
102+
private $backgroundCenterColor;
103+
/** @var string */
104+
private $backgroundCenterPosition;
105+
85106
/** @var array */
86107
private $component;
87108

@@ -470,6 +491,114 @@ public function setHeight($height)
470491
return $this;
471492
}
472493

494+
/**
495+
* Set justifyContent
496+
*
497+
* @param string|ComponentJustifyContent|null $justifyContent
498+
* @return $this
499+
*/
500+
public function setJustifyContent($justifyContent)
501+
{
502+
$this->justifyContent = $justifyContent;
503+
return $this;
504+
}
505+
506+
/**
507+
* Set alignItems
508+
*
509+
* @param string|ComponentAlignItems|null $alignItems
510+
* @return $this
511+
*/
512+
public function setAlignItems($alignItems)
513+
{
514+
$this->alignItems = $alignItems;
515+
return $this;
516+
}
517+
518+
/**
519+
* Set backgroundType
520+
*
521+
* @param string|ComponentBackgroundType|null $backgroundType
522+
* @return $this
523+
*/
524+
public function setBackgroundType($backgroundType)
525+
{
526+
$this->backgroundType = $backgroundType;
527+
return $this;
528+
}
529+
530+
/**
531+
* Set backgroundAngle
532+
*
533+
* specifiable "**deg".
534+
* (e.g. 90deg, 23.5deg
535+
*
536+
* @param string $backgroundAngle
537+
* @return $this
538+
*/
539+
public function setBackgroundAngle($backgroundAngle)
540+
{
541+
$this->backgroundAngle = $backgroundAngle;
542+
return $this;
543+
}
544+
545+
/**
546+
* Set backgroundStartColor
547+
*
548+
* Hex color string: #RRGGBB or #RRGGBBAA
549+
*
550+
* @param string $backgroundStartColor
551+
* @return $this
552+
*/
553+
public function setBackgroundStartColor($backgroundStartColor)
554+
{
555+
$this->backgroundStartColor = $backgroundStartColor;
556+
return $this;
557+
}
558+
559+
/**
560+
* Set backgroundEndColor
561+
*
562+
* Hex color string: #RRGGBB or #RRGGBBAA
563+
*
564+
* @param string $backgroundEndColor
565+
* @return $this
566+
*/
567+
public function setBackgroundEndColor($backgroundEndColor)
568+
{
569+
$this->backgroundEndColor = $backgroundEndColor;
570+
return $this;
571+
}
572+
573+
/**
574+
* Set backgroundCenterColor
575+
*
576+
* Hex color string: #RRGGBB or #RRGGBBAA
577+
*
578+
* @param string $backgroundCenterColor
579+
* @return $this
580+
*/
581+
public function setBackgroundCenterColor($backgroundCenterColor)
582+
{
583+
$this->backgroundCenterColor = $backgroundCenterColor;
584+
return $this;
585+
}
586+
587+
/**
588+
* Set backgroundCenterPosition
589+
*
590+
* specifiable percentage (0%~100%).
591+
* (e.g. 5%, 10.1%, 100%
592+
*
593+
* @param string $backgroundCenterPosition
594+
* @return $this
595+
*/
596+
public function setBackgroundCenterPosition($backgroundCenterPosition)
597+
{
598+
$this->backgroundCenterPosition = $backgroundCenterPosition;
599+
return $this;
600+
}
601+
473602
/**
474603
* Builds box component structure.
475604
*
@@ -481,6 +610,15 @@ public function build()
481610
return $this->component;
482611
}
483612

613+
$background = BuildUtil::removeNullElements([
614+
'type' => $this->backgroundType,
615+
'angle' => $this->backgroundAngle,
616+
'startColor' => $this->backgroundStartColor,
617+
'endColor' => $this->backgroundEndColor,
618+
'centerColor' => $this->backgroundCenterColor,
619+
'centerPosition' => $this->backgroundCenterPosition,
620+
]);
621+
484622
$contents = array_map(function ($componentBuilder) {
485623
/** @var ComponentBuilder $componentBuilder */
486624
return $componentBuilder->build();
@@ -510,6 +648,9 @@ public function build()
510648
'offsetBottom' => $this->offsetBottom,
511649
'offsetStart' => $this->offsetStart,
512650
'offsetEnd' => $this->offsetEnd,
651+
'justifyContent' => $this->justifyContent,
652+
'alignItems' => $this->alignItems,
653+
'background' => empty($background) ? null : $background,
513654
]);
514655

515656
return $this->component;

src/LINEBot/MessageBuilder/Flex/ComponentBuilder/ButtonComponentBuilder.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use LINE\LINEBot\Constant\Flex\ComponentGravity;
2525
use LINE\LINEBot\Constant\Flex\ComponentMargin;
2626
use LINE\LINEBot\Constant\Flex\ComponentType;
27+
use LINE\LINEBot\Constant\Flex\ComponentAdjustMode;
2728
use LINE\LINEBot\MessageBuilder\Flex\ComponentBuilder;
2829
use LINE\LINEBot\Util\BuildUtil;
2930

@@ -60,6 +61,9 @@ class ButtonComponentBuilder implements ComponentBuilder
6061
/** @var string */
6162
private $offsetEnd;
6263

64+
/** @var ComponentAdjustMode */
65+
private $adjustMode;
66+
6367
/** @var array */
6468
private $component;
6569

@@ -272,6 +276,18 @@ public function setOffsetEnd($offsetEnd)
272276
return $this;
273277
}
274278

279+
/**
280+
* Set adjustMode
281+
*
282+
* @param ComponentAdjustMode|null $adjustMode
283+
* @return $this
284+
*/
285+
public function setAdjustMode($adjustMode)
286+
{
287+
$this->adjustMode = $adjustMode;
288+
return $this;
289+
}
290+
275291
/**
276292
* Builds button component structure.
277293
*
@@ -297,6 +313,7 @@ public function build()
297313
'offsetBottom' => $this->offsetBottom,
298314
'offsetStart' => $this->offsetStart,
299315
'offsetEnd' => $this->offsetEnd,
316+
'adjustMode' => $this->adjustMode,
300317
]);
301318

302319
return $this->component;

src/LINEBot/MessageBuilder/Flex/ComponentBuilder/IconComponentBuilder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class IconComponentBuilder implements ComponentBuilder
6060
*
6161
* @param string $url
6262
* @param ComponentMargin|null $margin
63-
* @param ComponentIconSize|null $size
63+
* @param ComponentIconSize|string|null $size
6464
* @param ComponentIconAspectRatio|null $aspectRatio
6565
*/
6666
public function __construct($url, $margin = null, $size = null, $aspectRatio = null)
@@ -108,6 +108,11 @@ public function setMargin($margin)
108108
/**
109109
* Set size.
110110
*
111+
* specifiable pixel and keyword.
112+
* (e.g.
113+
* pixel: 5px
114+
* keyword: xxs (defined in ComponentIconSize)
115+
*
111116
* @param ComponentIconSize|string|null $size
112117
* @return IconComponentBuilder
113118
*/

0 commit comments

Comments
 (0)