|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SurajAdsul\AppMarket; |
|
4
|
|
|
|
|
5
|
|
|
abstract class AbstractStoreInfo |
|
6
|
|
|
{ |
|
7
|
|
|
const ANDROID_SUBSTRING = '://play.google.com'; |
|
8
|
|
|
const IOS_REGEX = '/https?:\/\/itunes\.apple\.com\/((?<country>[a-zA-Z]{2})\/)?.+\/id(?<id>\d+)/'; |
|
9
|
|
|
const APP_STORE_ID_ANDROID = 1; |
|
10
|
|
|
const APP_STORE_ID_APPLE = 2; |
|
11
|
|
|
|
|
12
|
|
|
protected $previewUrl; |
|
13
|
|
|
protected $platform; |
|
14
|
|
|
protected $country; |
|
15
|
|
|
protected $storeId; |
|
16
|
|
|
protected $data; |
|
17
|
|
|
protected $name; |
|
18
|
|
|
protected $ratingStars = 0; |
|
19
|
|
|
protected $ratingCount = 0; |
|
20
|
|
|
protected $screenshots = []; |
|
21
|
|
|
protected $icon; |
|
22
|
|
|
protected $contentRating = ''; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param array $details |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(array $details) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->platform = $details['platform']; |
|
30
|
|
|
$this->storeId = $details['storeId']; |
|
31
|
|
|
$this->data = $this->lookup(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
abstract protected function lookup(); |
|
35
|
|
|
|
|
36
|
|
|
final public function name() |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->name; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
final public function icon() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->icon; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
final public function rating() |
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
|
|
'stars' => $this->ratingStars, |
|
50
|
|
|
'count' => $this->ratingCount, |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
final public function screenshots() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->screenshots; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
final public function contentRating() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->contentRating; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
final public function previewUrl() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->previewUrl; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function addScheme($url, $scheme = 'http://') |
|
70
|
|
|
{ |
|
71
|
|
|
if (! preg_match('~^(?:f|ht)tps?://~i', $url)) { |
|
72
|
|
|
$url = ltrim($url, '/'); //handle this url '//google.com' |
|
73
|
|
|
$url = $scheme.$url; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $url; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|