1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the overtrue/wechat. |
||
5 | * |
||
6 | * (c) overtrue <[email protected]> |
||
7 | * |
||
8 | * This source file is subject to the MIT license that is bundled |
||
9 | * with this source code in the file LICENSE. |
||
10 | */ |
||
11 | |||
12 | namespace EasyWeChat\Kernel\Messages; |
||
13 | |||
14 | use EasyWeChat\Kernel\Contracts\MediaInterface; |
||
15 | use EasyWeChat\Kernel\Support\Str; |
||
16 | |||
17 | /** |
||
18 | * Class Media. |
||
19 | */ |
||
20 | class Media extends Message implements MediaInterface |
||
21 | { |
||
22 | /** |
||
23 | * Properties. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $properties = ['media_id']; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $required = [ |
||
33 | 'media_id', |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * MaterialClient constructor. |
||
38 | * |
||
39 | * @param string $mediaId |
||
40 | * @param string $type |
||
41 | * @param array $attributes |
||
42 | */ |
||
43 | 12 | public function __construct(string $mediaId, $type = null, array $attributes = []) |
|
44 | { |
||
45 | 12 | parent::__construct(array_merge(['media_id' => $mediaId], $attributes)); |
|
46 | |||
47 | 12 | !empty($type) && $this->setType($type); |
|
48 | 12 | } |
|
49 | |||
50 | /** |
||
51 | * @return string |
||
52 | * |
||
53 | * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
||
54 | */ |
||
55 | 1 | public function getMediaId(): string |
|
56 | { |
||
57 | 1 | $this->checkRequiredAttributes(); |
|
58 | |||
59 | 1 | return $this->get('media_id'); |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
60 | } |
||
61 | |||
62 | 2 | public function toXmlArray() |
|
63 | { |
||
64 | return [ |
||
65 | 2 | Str::studly($this->getType()) => [ |
|
66 | 2 | 'MediaId' => $this->get('media_id'), |
|
67 | ], |
||
68 | ]; |
||
69 | } |
||
70 | } |
||
71 |