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
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Contains application category information in the Google Play store. |
20
|
|
|
* |
21
|
|
|
* @see GPlayApps::getCategories() Returns an array of application categories |
22
|
|
|
* from the Google Play store. |
23
|
|
|
* @see GPlayApps::getCategoriesForLocales() Returns an array of application |
24
|
|
|
* categories from the Google Play store for the locale array. |
25
|
|
|
* @see GPlayApps::getCategoriesForAvailableLocales() Returns an array of |
26
|
|
|
* categories from the Google Play store for all available locales. |
27
|
|
|
*/ |
28
|
|
|
class Category implements \JsonSerializable |
29
|
|
|
{ |
30
|
|
|
use JsonSerializableTrait; |
31
|
|
|
|
32
|
|
|
/** @var string Category id. */ |
33
|
|
|
private $id; |
34
|
|
|
|
35
|
|
|
/** @var string Category name. */ |
36
|
|
|
private $name; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Creates an object with application category information. |
40
|
|
|
* |
41
|
|
|
* @param string $id category id |
42
|
|
|
* @param string $name category name |
43
|
|
|
*/ |
44
|
11 |
|
public function __construct(string $id, string $name) |
45
|
|
|
{ |
46
|
11 |
|
$this->id = $id; |
47
|
11 |
|
$this->name = $name; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns category id. |
52
|
|
|
* |
53
|
|
|
* @return string category id |
54
|
|
|
*/ |
55
|
|
|
public function getId(): string |
56
|
|
|
{ |
57
|
|
|
return $this->id; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns category name. |
62
|
|
|
* |
63
|
|
|
* @return string category name |
64
|
|
|
*/ |
65
|
|
|
public function getName(): string |
66
|
|
|
{ |
67
|
|
|
return $this->name; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Checks if a category is a category with games. |
72
|
|
|
* |
73
|
|
|
* @return bool `true` if this is a category with games and `false` if not |
74
|
|
|
*/ |
75
|
|
|
public function isGamesCategory(): bool |
76
|
|
|
{ |
77
|
|
|
return strpos($this->id, 'GAME') === 0; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Checks if a category is a family category. |
82
|
|
|
* |
83
|
|
|
* @return bool `true` if this is a family category and `false` if not |
84
|
|
|
*/ |
85
|
|
|
public function isFamilyCategory(): bool |
86
|
|
|
{ |
87
|
|
|
return strpos($this->id, 'FAMILY') === 0; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Checks whether a category is a category with applications. |
92
|
|
|
* |
93
|
|
|
* @return bool `true` if this is a category with applications and `false` if not |
94
|
|
|
*/ |
95
|
|
|
public function isApplicationCategory(): bool |
96
|
|
|
{ |
97
|
|
|
return !$this->isGamesCategory() && !$this->isFamilyCategory(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns class properties as an array. |
102
|
|
|
* |
103
|
|
|
* @return array class properties as an array |
104
|
|
|
*/ |
105
|
|
|
public function asArray(): array |
106
|
|
|
{ |
107
|
|
|
return [ |
108
|
|
|
'id' => $this->id, |
109
|
|
|
'name' => $this->name, |
110
|
|
|
]; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|