1 | <?php |
||
10 | class PackageFilter |
||
11 | { |
||
12 | private $pkgList; |
||
13 | /** @var bool|string[] $filterArch Array of allowed architectures, or FALSE to ignore. */ |
||
14 | private $filterArch = false; |
||
15 | /** @var bool|string $filterFwVersion Target firmware version, or FALSE to ignore. */ |
||
16 | private $filterFwVersion = false; |
||
17 | /** @var bool|string $filterChannel Channel 'stable' or 'beta', or FALSE to ignore. */ |
||
18 | private $filterChannel = false; |
||
19 | /** @var bool $filterOldVersions TRUE to return unique packages with latest version only. */ |
||
20 | private $filterOldVersions = false; |
||
21 | |||
22 | /** |
||
23 | * @param \SSpkS\Package\Package[] $pkgList List of Package objects to filter |
||
24 | */ |
||
25 | 5 | public function __construct(array $pkgList) |
|
29 | |||
30 | /** |
||
31 | * Sets the architecture to filter for. |
||
32 | * |
||
33 | * @param string $arch Architecture. |
||
34 | */ |
||
35 | 1 | public function setArchitectureFilter($arch) |
|
39 | |||
40 | /** |
||
41 | * Sets the firmware version to filter for. |
||
42 | * |
||
43 | * @param string|bool $version Firmware version in dotted notation ('1.2.3456') or FALSE to ignore. |
||
44 | */ |
||
45 | 1 | public function setFirmwareVersionFilter($version) |
|
49 | |||
50 | /** |
||
51 | * Sets the channel to filter for. |
||
52 | * |
||
53 | * @param string $channel Channel ('stable' or 'beta') |
||
54 | */ |
||
55 | 1 | public function setChannelFilter($channel) |
|
59 | |||
60 | /** |
||
61 | * Enables or disables omitting older versions of the same package from the result set. |
||
62 | * |
||
63 | * @param bool $status TRUE to enable the filter, FALSE to disable. |
||
64 | */ |
||
65 | 1 | public function setOldVersionFilter($status) |
|
69 | |||
70 | /** |
||
71 | * If filter is enabled, checks if architecture of $package is compatible to requested one. |
||
72 | * |
||
73 | * @param \SSpkS\Package\Package $package Package to test. |
||
74 | * @return bool TRUE if matching, or FALSE. |
||
75 | */ |
||
76 | 5 | public function isMatchingArchitecture($package) |
|
84 | |||
85 | /** |
||
86 | * If filter is enabled, checks if minimal firmware required of $package is |
||
87 | * smaller or equal to system firmware. |
||
88 | * |
||
89 | * @param \SSpkS\Package\Package $package Package to test. |
||
90 | * @return bool TRUE if matching, or FALSE. |
||
91 | */ |
||
92 | 5 | public function isMatchingFirmwareVersion($package) |
|
99 | |||
100 | /** |
||
101 | * If filter is enabled, checks if channel of $package matches requested one. |
||
102 | * 'beta' will show ALL packages, also those from 'stable'. |
||
103 | * |
||
104 | * @param \SSpkS\Package\Package $package Package to test. |
||
105 | * @return bool TRUE if matching, or FALSE. |
||
106 | */ |
||
107 | 5 | public function isMatchingChannel($package) |
|
119 | |||
120 | /** |
||
121 | * Removes older versions of same package from $pkgList. |
||
122 | * |
||
123 | * @param \SSpkS\Package\Package[] $pkgList List of packages |
||
124 | * @return \SSpkS\Package\Package[] List of unique packages |
||
125 | */ |
||
126 | 1 | public function removeObsoleteVersions($pkgList) |
|
138 | |||
139 | /** |
||
140 | * Returns the list of packages matching the currently set filters. |
||
141 | * |
||
142 | * @return \SSpkS\Package\Package[] List of Package objects matching filters. |
||
143 | */ |
||
144 | 5 | public function getFilteredPackageList() |
|
165 | } |
||
166 |