| @@ 12-57 (lines=46) @@ | ||
| 9 | /** |
|
| 10 | * @deprecated Since version 3.2.0 and will be removed in version 4.0.0. |
|
| 11 | */ |
|
| 12 | class OpenGraphTemplate extends AbstractTemplate |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * @var \Kerox\Messenger\Model\Message\Attachment\Template\Element\OpenGraphElement[] |
|
| 16 | */ |
|
| 17 | protected $elements = []; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * OpenGraph constructor. |
|
| 21 | * |
|
| 22 | * @param \Kerox\Messenger\Model\Message\Attachment\Template\Element\OpenGraphElement[] $elements |
|
| 23 | * |
|
| 24 | * @throws \Kerox\Messenger\Exception\MessengerException |
|
| 25 | */ |
|
| 26 | public function __construct(array $elements) |
|
| 27 | { |
|
| 28 | parent::__construct(); |
|
| 29 | ||
| 30 | $this->isValidArray($elements, 1); |
|
| 31 | ||
| 32 | $this->elements = $elements; |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | *@throws \Kerox\Messenger\Exception\MessengerException |
|
| 37 | * |
|
| 38 | * @return \Kerox\Messenger\Model\Message\Attachment\Template\OpenGraphTemplate |
|
| 39 | */ |
|
| 40 | public static function create(array $elements): self |
|
| 41 | { |
|
| 42 | return new self($elements); |
|
| 43 | } |
|
| 44 | ||
| 45 | public function toArray(): array |
|
| 46 | { |
|
| 47 | $array = parent::toArray(); |
|
| 48 | $array += [ |
|
| 49 | 'payload' => [ |
|
| 50 | 'template_type' => AbstractTemplate::TYPE_OPEN_GRAPH, |
|
| 51 | 'elements' => $this->elements, |
|
| 52 | ], |
|
| 53 | ]; |
|
| 54 | ||
| 55 | return $this->arrayFilter($array); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| @@ 9-48 (lines=40) @@ | ||
| 6 | ||
| 7 | use Kerox\Messenger\Model\Message\Attachment\AbstractTemplate; |
|
| 8 | ||
| 9 | class ProductTemplate extends AbstractTemplate |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var \Kerox\Messenger\Model\Message\Attachment\Template\Element\ProductElement[] |
|
| 13 | */ |
|
| 14 | private $elements; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @throws \Kerox\Messenger\Exception\InvalidArrayException |
|
| 18 | */ |
|
| 19 | public function __construct(array $elements) |
|
| 20 | { |
|
| 21 | parent::__construct(); |
|
| 22 | ||
| 23 | $this->isValidArray($elements, 10); |
|
| 24 | ||
| 25 | $this->elements = $elements; |
|
| 26 | } |
|
| 27 | ||
| 28 | /** |
|
| 29 | * @throws \Kerox\Messenger\Exception\InvalidArrayException |
|
| 30 | */ |
|
| 31 | public static function create(array $elements): self |
|
| 32 | { |
|
| 33 | return new self($elements); |
|
| 34 | } |
|
| 35 | ||
| 36 | public function toArray(): array |
|
| 37 | { |
|
| 38 | $array = parent::toArray(); |
|
| 39 | $array += [ |
|
| 40 | 'payload' => [ |
|
| 41 | 'template_type' => AbstractTemplate::TYPE_PRODUCT, |
|
| 42 | 'elements' => $this->elements, |
|
| 43 | ], |
|
| 44 | ]; |
|
| 45 | ||
| 46 | return $this->arrayFilter($array); |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||