1 | <?php |
||
24 | class Feed { |
||
25 | |||
26 | /** string $version */ |
||
27 | protected $version; |
||
28 | |||
29 | /** string $versionString */ |
||
30 | protected $versionString; |
||
31 | |||
32 | /** string $url */ |
||
33 | protected $url; |
||
34 | |||
35 | /** string $web */ |
||
36 | protected $web; |
||
37 | |||
38 | /** array $requiredFeedEntries */ |
||
39 | protected $requiredFeedEntries = [ |
||
40 | 'version', |
||
41 | 'versionstring', |
||
42 | 'url' |
||
43 | ]; |
||
44 | |||
45 | /** bool $isValid */ |
||
46 | protected $isValid = true; |
||
47 | |||
48 | /** |
||
49 | * |
||
50 | * @param array $data |
||
51 | */ |
||
52 | 12 | public function __construct($data){ |
|
53 | 12 | $missingEntries = []; |
|
54 | 12 | foreach ($this->requiredFeedEntries as $index){ |
|
55 | 12 | if (!isset($data[$index]) || empty($data[$index])){ |
|
56 | 5 | $missingEntries[] = $index; |
|
57 | 12 | $data[$index] = ''; |
|
58 | } |
||
59 | } |
||
60 | |||
61 | 12 | if (count($missingEntries)){ |
|
62 | 5 | $this->isValid = false; |
|
63 | //'Got missing or empty fileds for: ' . implode(',', $missingEntries) . '. No updates found.'; |
||
64 | } |
||
65 | 12 | $this->version = $data['version']; |
|
66 | 12 | $this->versionString = $data['versionstring']; |
|
67 | 12 | $this->url = $data['url']; |
|
68 | 12 | } |
|
69 | |||
70 | /** |
||
71 | * Build filename to download as a.b.c.d.zip |
||
72 | * @return string |
||
73 | */ |
||
74 | 2 | public function getDownloadedFileName(){ |
|
75 | 2 | $extension = preg_replace('|.*?((\.tar)?\.[^.]*)$|s', '\1', $this->getUrl()); |
|
76 | 2 | return $this->getVersion() . $extension; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Does feed contain all the data required? |
||
81 | * @return bool |
||
82 | */ |
||
83 | 7 | public function isValid(){ |
|
86 | |||
87 | /** |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | 3 | public function getVersion(){ |
|
94 | |||
95 | /** |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | public function getVersionString(){ |
||
102 | |||
103 | /** |
||
104 | * Get url to download a new version from |
||
105 | * @return string |
||
106 | */ |
||
107 | 2 | public function getUrl(){ |
|
108 | 2 | return $this->url; |
|
109 | } |
||
110 | |||
111 | /** |
||
112 | * Get url to download a checksum from |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getChecksumUrl(){ |
||
118 | |||
119 | } |
||
120 |