1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Yproximite\Api\Message\Article; |
5
|
|
|
|
6
|
|
|
use Yproximite\Api\Util\Helper; |
7
|
|
|
use Yproximite\Api\Model\Article\Article; |
8
|
|
|
use Yproximite\Api\Message\MessageInterface; |
9
|
|
|
use Yproximite\Api\Message\SiteAwareMessageTrait; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class AbstractArticleMessage |
13
|
|
|
*/ |
14
|
|
|
abstract class AbstractArticleMessage implements MessageInterface |
15
|
|
|
{ |
16
|
|
|
use SiteAwareMessageTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var ArticleTranslationMessage[] |
20
|
|
|
*/ |
21
|
|
|
private $translations = []; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string|null |
25
|
|
|
*/ |
26
|
|
|
private $status; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int[] |
30
|
|
|
*/ |
31
|
|
|
private $categoryIds = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ArticleMediaMessage[] |
35
|
|
|
*/ |
36
|
|
|
private $medias = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var int|null |
40
|
|
|
*/ |
41
|
|
|
private $mediaLimit; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var bool|null |
45
|
|
|
*/ |
46
|
|
|
private $shareOnFacebook; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return ArticleTranslationMessage[] |
50
|
|
|
*/ |
51
|
|
|
public function getTranslations(): array |
52
|
|
|
{ |
53
|
|
|
return $this->translations; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param ArticleTranslationMessage $translation |
58
|
|
|
*/ |
59
|
|
|
public function addTranslation(ArticleTranslationMessage $translation) |
60
|
|
|
{ |
61
|
|
|
$this->translations[] = $translation; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param ArticleTranslationMessage $translation |
66
|
|
|
*/ |
67
|
|
|
public function removeTranslation(ArticleTranslationMessage $translation) |
68
|
|
|
{ |
69
|
|
|
array_splice($this->translations, array_search($translation, $this->translations), 1); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @see Article::getStatuses() |
74
|
|
|
* |
75
|
|
|
* @return null|string |
76
|
|
|
*/ |
77
|
|
|
public function getStatus() |
78
|
|
|
{ |
79
|
|
|
return $this->status; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param null|string $status |
84
|
|
|
*/ |
85
|
|
|
public function setStatus(string $status = null) |
86
|
|
|
{ |
87
|
|
|
$this->status = $status; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return \int[] |
92
|
|
|
*/ |
93
|
|
|
public function getCategoryIds(): array |
94
|
|
|
{ |
95
|
|
|
return $this->categoryIds; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param \int[] $categoryIds |
100
|
|
|
*/ |
101
|
|
|
public function setCategoryIds(array $categoryIds) |
102
|
|
|
{ |
103
|
|
|
$this->categoryIds = $categoryIds; |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return ArticleMediaMessage[] |
108
|
|
|
*/ |
109
|
|
|
public function getMedias(): array |
110
|
|
|
{ |
111
|
|
|
return $this->medias; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param ArticleMediaMessage $media |
116
|
|
|
*/ |
117
|
|
|
public function addMedia(ArticleMediaMessage $media) |
118
|
|
|
{ |
119
|
|
|
$this->medias[] = $media; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param ArticleMediaMessage $media |
124
|
|
|
*/ |
125
|
|
|
public function removeMedia(ArticleMediaMessage $media) |
126
|
|
|
{ |
127
|
|
|
array_splice($this->medias, array_search($media, $this->medias), 1); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return int|null |
132
|
|
|
*/ |
133
|
|
|
public function getMediaLimit() |
134
|
|
|
{ |
135
|
|
|
return $this->mediaLimit; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param int|null $mediaLimit |
140
|
|
|
*/ |
141
|
|
|
public function setMediaLimit(int $mediaLimit = null) |
142
|
|
|
{ |
143
|
|
|
$this->mediaLimit = $mediaLimit; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return bool|null |
148
|
|
|
*/ |
149
|
|
|
public function isShareOnFacebook() |
150
|
|
|
{ |
151
|
|
|
return $this->shareOnFacebook; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param bool|null $shareOnFacebook |
156
|
|
|
*/ |
157
|
|
|
public function setShareOnFacebook(bool $shareOnFacebook = null) |
158
|
|
|
{ |
159
|
|
|
$this->shareOnFacebook = $shareOnFacebook; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* {@inheritdoc} |
164
|
|
|
*/ |
165
|
|
|
public function build() |
166
|
|
|
{ |
167
|
|
|
return [ |
168
|
|
|
'translations' => Helper::buildMessages($this->getTranslations(), 'locale'), |
169
|
|
|
'status' => $this->getStatus(), |
170
|
|
|
'categories' => $this->getCategoryIds(), |
171
|
|
|
'articleMedias' => Helper::buildMessages($this->getMedias()), |
172
|
|
|
'mediaLimit' => $this->getMediaLimit(), |
173
|
|
|
'shareOnFacebook' => $this->isShareOnFacebook(), |
174
|
|
|
]; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..