Commit | Line | Data |
---|---|---|
0c7b8679 MW |
1 | <?php |
2 | namespace wcf\data\package; | |
b401cd0d | 3 | use wcf\system\cache\builder\PackageCacheBuilder; |
0c7b8679 MW |
4 | use wcf\system\SingletonFactory; |
5 | ||
6 | /** | |
7 | * Manages the package cache. | |
8 | * | |
9 | * @author Marcel Werk | |
ca4ba303 | 10 | * @copyright 2001-2014 WoltLab GmbH |
0c7b8679 MW |
11 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
12 | * @package com.woltlab.wcf | |
13 | * @subpackage data.package | |
9f959ced | 14 | * @category Community Framework |
0c7b8679 MW |
15 | */ |
16 | class PackageCache extends SingletonFactory { | |
17 | /** | |
18 | * list of cached packages | |
f1c1fc65 | 19 | * @var array<array> |
0c7b8679 MW |
20 | */ |
21 | protected $packages = array(); | |
22 | ||
23 | /** | |
0ad90fc3 | 24 | * @see \wcf\system\SingletonFactory::init() |
0c7b8679 MW |
25 | */ |
26 | protected function init() { | |
b401cd0d | 27 | $this->packages = PackageCacheBuilder::getInstance()->getData(); |
0c7b8679 MW |
28 | } |
29 | ||
30 | /** | |
31 | * Returns a specific package. | |
32 | * | |
33 | * @param integer $packageID | |
0ad90fc3 | 34 | * @return \wcf\data\package\Package |
0c7b8679 MW |
35 | */ |
36 | public function getPackage($packageID) { | |
f1c1fc65 AE |
37 | if (isset($this->packages['packages'][$packageID])) { |
38 | return $this->packages['packages'][$packageID]; | |
39 | } | |
40 | ||
41 | return null; | |
42 | } | |
43 | ||
44 | /** | |
45 | * Returns the id of a specific package or 'null' if not found. | |
59dc0db6 | 46 | * |
f1c1fc65 AE |
47 | * @param string $package |
48 | * @return string | |
49 | */ | |
50 | public function getPackageID($package) { | |
51 | if (isset($this->packages['packageIDs'][$package])) { | |
52 | return $this->packages['packageIDs'][$package]; | |
53 | } | |
0c7b8679 MW |
54 | |
55 | return null; | |
56 | } | |
c67cc7d1 MS |
57 | |
58 | /** | |
59 | * Returns all packages. | |
60 | * | |
0ad90fc3 | 61 | * @return array<\wcf\data\package\Package> |
c67cc7d1 MS |
62 | */ |
63 | public function getPackages() { | |
64 | return $this->packages; | |
65 | } | |
ddc1f8ba MW |
66 | |
67 | /** | |
68 | * Returns a specific package. | |
69 | * | |
70 | * @param string $package | |
0ad90fc3 | 71 | * @return \wcf\data\package\Package |
ddc1f8ba MW |
72 | */ |
73 | public function getPackageByIdentifier($package) { | |
74 | $packageID = $this->getPackageID($package); | |
75 | if ($packageID === null) return null; | |
76 | ||
77 | return $this->getPackage($packageID); | |
78 | } | |
0c7b8679 | 79 | } |