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