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|null Application summary. */ |
44
|
|
|
private $summary; |
45
|
|
|
|
46
|
|
|
/** @var Developer Application developer. */ |
47
|
|
|
private $developer; |
48
|
|
|
|
49
|
|
|
/** @var GoogleImage Application icon. */ |
50
|
|
|
private $icon; |
51
|
|
|
|
52
|
|
|
/** @var float Application rating on a five-point scale. */ |
53
|
|
|
private $score; |
54
|
|
|
|
55
|
|
|
/** @var string|null Price of the application or null if it is free. */ |
56
|
|
|
private $priceText; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Creates an object containing basic information about the Android application. |
60
|
|
|
* |
61
|
|
|
* @param AppBuilder $builder application builder |
62
|
|
|
* |
63
|
|
|
* @ignore |
64
|
|
|
*/ |
65
|
38 |
|
public function __construct(AppBuilder $builder) |
66
|
|
|
{ |
67
|
38 |
|
if (empty($builder->getId())) { |
68
|
1 |
|
throw new \InvalidArgumentException( |
69
|
|
|
'Application ID cannot be null or empty. Solution: $appBuilder->setId(...);' |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
38 |
|
if (empty($builder->getLocale())) { |
74
|
1 |
|
throw new \InvalidArgumentException( |
75
|
|
|
'Locale cannot be null or empty. Solution: $appBuilder->setLocale(...);' |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
38 |
|
if (empty($builder->getCountry())) { |
80
|
1 |
|
throw new \InvalidArgumentException( |
81
|
|
|
'Country cannot be null or empty. Solution: $appBuilder->setCountry(...);' |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
38 |
|
if (empty($builder->getName())) { |
86
|
1 |
|
throw new \InvalidArgumentException( |
87
|
|
|
'The application name cannot be null or empty. Solution: $appBuilder->setName(...);' |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
38 |
|
if ($builder->getDeveloper() === null) { |
92
|
1 |
|
throw new \InvalidArgumentException( |
93
|
|
|
'Application developer cannot be null. Solution: $appBuilder->setDeveloper(...);' |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
38 |
|
if ($builder->getIcon() === null) { |
98
|
1 |
|
throw new \InvalidArgumentException( |
99
|
|
|
'Application icon cannot be null. Solution: $appBuilder->setIcon(...);' |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
38 |
|
parent::__construct( |
104
|
38 |
|
$builder->getId(), |
105
|
38 |
|
$builder->getLocale(), |
106
|
38 |
|
$builder->getCountry() |
107
|
|
|
); |
108
|
|
|
|
109
|
38 |
|
$this->name = $builder->getName(); |
110
|
38 |
|
$this->summary = $builder->getSummary(); |
111
|
38 |
|
$this->developer = $builder->getDeveloper(); |
112
|
38 |
|
$this->icon = $builder->getIcon(); |
113
|
38 |
|
$this->score = $builder->getScore(); |
114
|
38 |
|
$this->priceText = $builder->getPriceText(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Returns application name. |
119
|
|
|
* |
120
|
|
|
* @return string application name |
121
|
|
|
*/ |
122
|
15 |
|
public function getName(): string |
123
|
|
|
{ |
124
|
15 |
|
return $this->name; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Returns application summary. |
129
|
|
|
* |
130
|
|
|
* @return string|null application summary |
131
|
|
|
*/ |
132
|
1 |
|
public function getSummary(): ?string |
133
|
|
|
{ |
134
|
1 |
|
return $this->summary; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns application developer. |
139
|
|
|
* |
140
|
|
|
* @return Developer application developer |
141
|
|
|
*/ |
142
|
3 |
|
public function getDeveloper(): Developer |
143
|
|
|
{ |
144
|
3 |
|
return $this->developer; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Returns application icon. |
149
|
|
|
* |
150
|
|
|
* @return GoogleImage application icon |
151
|
|
|
*/ |
152
|
14 |
|
public function getIcon(): GoogleImage |
153
|
|
|
{ |
154
|
14 |
|
return $this->icon; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Returns application rating on a five-point scale. |
159
|
|
|
* |
160
|
|
|
* @return float rating application |
161
|
|
|
*/ |
162
|
1 |
|
public function getScore(): float |
163
|
|
|
{ |
164
|
1 |
|
return $this->score; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Returns the price of the application. |
169
|
|
|
* |
170
|
|
|
* @return string|null application price or null if it is free |
171
|
|
|
*/ |
172
|
1 |
|
public function getPriceText(): ?string |
173
|
|
|
{ |
174
|
1 |
|
return $this->priceText; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Checks that this application is free. |
179
|
|
|
* |
180
|
|
|
* @return bool `true` if the application is free and `false` if paid |
181
|
|
|
*/ |
182
|
1 |
|
public function isFree(): bool |
183
|
|
|
{ |
184
|
1 |
|
return $this->priceText === null; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Creates a new application builder. |
189
|
|
|
* |
190
|
|
|
* @return AppBuilder application builder |
191
|
|
|
* @ignore |
192
|
|
|
*/ |
193
|
38 |
|
public static function newBuilder(): AppBuilder |
194
|
|
|
{ |
195
|
38 |
|
return new AppBuilder(); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Returns class properties as an array. |
200
|
|
|
* |
201
|
|
|
* @return array class properties as an array |
202
|
|
|
*/ |
203
|
|
|
public function asArray(): array |
204
|
|
|
{ |
205
|
|
|
return [ |
206
|
|
|
'id' => $this->getId(), |
207
|
|
|
'url' => $this->getUrl(), |
208
|
|
|
'locale' => $this->getLocale(), |
209
|
|
|
'country' => $this->getCountry(), |
210
|
|
|
'name' => $this->name, |
211
|
|
|
'summary' => $this->summary, |
212
|
|
|
'developer' => $this->developer->asArray(), |
213
|
|
|
'icon' => $this->icon->getUrl(), |
214
|
|
|
'score' => $this->score, |
215
|
|
|
'priceText' => $this->priceText, |
216
|
|
|
]; |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|