|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Copyright (c) Ne-Lexa |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view |
|
9
|
|
|
* the LICENSE file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @see https://github.com/Ne-Lexa/google-play-scraper |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Nelexa\GPlay\Model; |
|
15
|
|
|
|
|
16
|
|
|
use Nelexa\GPlay\GPlayApps; |
|
17
|
|
|
use Nelexa\GPlay\Model\Builder\AppBuilder; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Contains basic information about the application from the Google Play store. |
|
21
|
|
|
* |
|
22
|
|
|
* Some sections, such as search, similar applications, applications categories, etc. display |
|
23
|
|
|
* a list of applications with limited data. To get detailed information about the application, |
|
24
|
|
|
* you must call the appropriate method in the class {@see GPlayApps}. |
|
25
|
|
|
* |
|
26
|
|
|
* @see AppId Application ID, application locale and country. |
|
27
|
|
|
* @see GPlayApps::search() Returns a list of applications from the Google Play |
|
28
|
|
|
* store for a search query. |
|
29
|
|
|
* @see GPlayApps::getSimilarApps() Returns a list of similar applications in |
|
30
|
|
|
* the Google Play store. |
|
31
|
|
|
* @see GPlayApps::getDeveloperApps() Returns a list of developer applications |
|
32
|
|
|
* in the Google Play store. |
|
33
|
|
|
* @see GPlayApps::getTopApps() Returns a list of applications with basic |
|
34
|
|
|
* information from the category and collection of the Google Play store. |
|
35
|
|
|
*/ |
|
36
|
|
|
class App extends AppId implements \JsonSerializable |
|
37
|
|
|
{ |
|
38
|
|
|
use JsonSerializableTrait; |
|
39
|
|
|
|
|
40
|
|
|
/** @var string Application name. */ |
|
41
|
|
|
private $name; |
|
42
|
|
|
|
|
43
|
|
|
/** @var string Application description. */ |
|
44
|
|
|
private $description; |
|
45
|
|
|
|
|
46
|
|
|
/** @var string|null Application developer name. */ |
|
47
|
|
|
private $developerName; |
|
48
|
|
|
|
|
49
|
|
|
/** @var GoogleImage Application icon. */ |
|
50
|
|
|
private $icon; |
|
51
|
|
|
|
|
52
|
|
|
/** @var GoogleImage[] Screenshots of the application. */ |
|
53
|
|
|
private $screenshots; |
|
54
|
|
|
|
|
55
|
|
|
/** @var float Application rating on a five-point scale. */ |
|
56
|
|
|
private $score; |
|
57
|
|
|
|
|
58
|
|
|
/** @var string|null Price of the application or null if it is free. */ |
|
59
|
|
|
private $priceText; |
|
60
|
|
|
|
|
61
|
|
|
/** @var string Formatted number of installations of the application. */ |
|
62
|
|
|
private $installsText; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Creates an object containing basic information about the Android application. |
|
66
|
|
|
* |
|
67
|
|
|
* @param AppBuilder $builder application builder |
|
68
|
|
|
* |
|
69
|
|
|
* @ignore |
|
70
|
|
|
*/ |
|
71
|
32 |
|
public function __construct(AppBuilder $builder) |
|
72
|
|
|
{ |
|
73
|
32 |
|
if (empty($builder->getId())) { |
|
74
|
|
|
throw new \InvalidArgumentException( |
|
75
|
|
|
'Application ID cannot be null or empty. Solution: $appBuilder->setId(...);' |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
32 |
|
if (empty($builder->getLocale())) { |
|
80
|
|
|
throw new \InvalidArgumentException( |
|
81
|
|
|
'Locale cannot be null or empty. Solution: $appBuilder->setLocale(...);' |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
32 |
|
if (empty($builder->getCountry())) { |
|
86
|
|
|
throw new \InvalidArgumentException( |
|
87
|
|
|
'Country cannot be null or empty. Solution: $appBuilder->setCountry(...);' |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
32 |
|
if (empty($builder->getName())) { |
|
92
|
|
|
throw new \InvalidArgumentException( |
|
93
|
|
|
'The application name cannot be null or empty. Solution: $appBuilder->setName(...);' |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
32 |
|
if ($builder->getIcon() === null) { |
|
98
|
|
|
throw new \InvalidArgumentException( |
|
99
|
|
|
'Application icon cannot be null. Solution: $appBuilder->setIcon(...);' |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
32 |
|
if (empty($builder->getScreenshots())) { |
|
104
|
|
|
throw new \InvalidArgumentException( |
|
105
|
|
|
'Screenshots of the application must contain at least one screenshot. Solution: $appBuilder->setScreenshots(...); or $appBuilder->addScreenshot(...);' |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
32 |
|
parent::__construct( |
|
110
|
32 |
|
$builder->getId(), |
|
111
|
32 |
|
$builder->getLocale(), |
|
112
|
32 |
|
$builder->getCountry() |
|
113
|
|
|
); |
|
114
|
|
|
|
|
115
|
32 |
|
$this->name = $builder->getName(); |
|
116
|
32 |
|
$this->description = $builder->getDescription(); |
|
117
|
32 |
|
$this->developerName = $builder->getDeveloperName(); |
|
118
|
32 |
|
$this->installsText = $builder->getInstallsText(); |
|
119
|
32 |
|
$this->icon = $builder->getIcon(); |
|
120
|
32 |
|
$this->screenshots = $builder->getScreenshots(); |
|
121
|
32 |
|
$this->score = $builder->getScore(); |
|
122
|
32 |
|
$this->priceText = $builder->getPriceText(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Returns application name. |
|
127
|
|
|
* |
|
128
|
|
|
* @return string application name |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getName(): string |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->name; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Returns a description of the application. |
|
137
|
|
|
* |
|
138
|
|
|
* @return string description of the application |
|
139
|
|
|
*/ |
|
140
|
|
|
public function getDescription(): string |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->description; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Returns application summary. |
|
147
|
|
|
* |
|
148
|
|
|
* @return string|null application summary |
|
149
|
|
|
* |
|
150
|
|
|
* @deprecated It is no longer possible to get a summary |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getSummary(): ?string |
|
153
|
|
|
{ |
|
154
|
|
|
return null; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Returns application developer. |
|
159
|
|
|
* |
|
160
|
|
|
* @return Developer|null application developer |
|
161
|
|
|
* |
|
162
|
|
|
* @deprecated Use {@see \Nelexa\GPlay\Model\App::getDeveloperName()} |
|
163
|
|
|
*/ |
|
164
|
|
|
public function getDeveloper(): ?Developer |
|
165
|
|
|
{ |
|
166
|
|
|
return null; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Returns application developer name. |
|
171
|
|
|
* |
|
172
|
|
|
* @return string|null application developer name |
|
173
|
|
|
*/ |
|
174
|
|
|
public function getDeveloperName(): ?string |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->developerName; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Returns application icon. |
|
181
|
|
|
* |
|
182
|
|
|
* @return GoogleImage application icon |
|
183
|
|
|
*/ |
|
184
|
1 |
|
public function getIcon(): GoogleImage |
|
185
|
|
|
{ |
|
186
|
1 |
|
return $this->icon; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Returns screenshots of the application. |
|
191
|
|
|
* |
|
192
|
|
|
* The array must contain at least 2 screenshots. |
|
193
|
|
|
* |
|
194
|
|
|
* Google Play screenshots requirements: |
|
195
|
|
|
* * JPEG or 24-bit PNG (no alpha) |
|
196
|
|
|
* * Minimum dimension: 320px |
|
197
|
|
|
* * Maximum dimension: 3840px |
|
198
|
|
|
* * The maximum dimension of the screenshot can't be more than twice as long as the minimum dimension. |
|
199
|
|
|
* |
|
200
|
|
|
* @return GoogleImage[] array of screenshots |
|
201
|
|
|
*/ |
|
202
|
1 |
|
public function getScreenshots(): array |
|
203
|
|
|
{ |
|
204
|
1 |
|
return $this->screenshots; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Returns application rating on a five-point scale. |
|
209
|
|
|
* |
|
210
|
|
|
* @return float rating application |
|
211
|
|
|
*/ |
|
212
|
|
|
public function getScore(): float |
|
213
|
|
|
{ |
|
214
|
|
|
return $this->score; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* Returns the price of the application. |
|
219
|
|
|
* |
|
220
|
|
|
* @return string|null application price or null if it is free |
|
221
|
|
|
*/ |
|
222
|
|
|
public function getPriceText(): ?string |
|
223
|
|
|
{ |
|
224
|
|
|
return $this->priceText; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Checks that this application is free. |
|
229
|
|
|
* |
|
230
|
|
|
* @return bool `true` if the application is free and `false` if paid |
|
231
|
|
|
*/ |
|
232
|
|
|
public function isFree(): bool |
|
233
|
|
|
{ |
|
234
|
|
|
return $this->priceText === null; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* @return string |
|
239
|
|
|
*/ |
|
240
|
|
|
public function getInstallsText(): ?string |
|
241
|
|
|
{ |
|
242
|
|
|
return $this->installsText; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* Creates a new application builder. |
|
247
|
|
|
* |
|
248
|
|
|
* @return AppBuilder application builder |
|
249
|
|
|
* @ignore |
|
250
|
|
|
*/ |
|
251
|
32 |
|
public static function newBuilder(): AppBuilder |
|
252
|
|
|
{ |
|
253
|
32 |
|
return new AppBuilder(); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Returns class properties as an array. |
|
258
|
|
|
* |
|
259
|
|
|
* @return array class properties as an array |
|
260
|
|
|
*/ |
|
261
|
|
|
public function asArray(): array |
|
262
|
|
|
{ |
|
263
|
|
|
return [ |
|
264
|
|
|
'id' => $this->getId(), |
|
265
|
|
|
'url' => $this->getUrl(), |
|
266
|
|
|
'locale' => $this->getLocale(), |
|
267
|
|
|
'country' => $this->getCountry(), |
|
268
|
|
|
'name' => $this->name, |
|
269
|
|
|
'description' => $this->description, |
|
270
|
|
|
'developerName' => $this->getDeveloperName(), |
|
271
|
|
|
'icon' => $this->icon->getUrl(), |
|
272
|
|
|
'screenshots' => array_map( |
|
273
|
|
|
static function (GoogleImage $googleImage) { |
|
274
|
|
|
return $googleImage->getUrl(); |
|
275
|
|
|
}, |
|
276
|
|
|
$this->screenshots |
|
277
|
|
|
), |
|
278
|
|
|
'score' => $this->score, |
|
279
|
|
|
'priceText' => $this->priceText, |
|
280
|
|
|
'installsText' => $this->installsText, |
|
281
|
|
|
]; |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
|