Fix isCrewSelected method to handle undefined crew value
[allerta-vvf.git] / backend / .discovery / Discovery.php
blobdb92a7c906b67c6a73e3a63446bef48a0379966e
1 <?php
4 namespace TheCodingMachine\Discovery;
6 /**
7 * Use this class to access data stored in the discovery.json files at the root of your packages.
8 */
9 class Discovery implements DiscoveryInterface
11 private static $instance;
13 /**
14 * @var string[]
16 private $values;
17 /**
18 * @var AssetType[]
20 private $assetTypes;
21 /**
22 * @var array[]
24 private $assetTypesArray;
26 /**
27 * Singleton. Noone creates this object directly.
29 private function __construct()
31 $this->values = require __DIR__.'/discovery_values.php';
32 $this->assetTypesArray = require __DIR__.'/discovery_asset_types.php';
35 /**
36 * Returns the unique instance of this class (singleton).
38 * @return self
40 public static function getInstance(): self
42 if (!self::$instance) {
43 self::$instance = new self();
45 return self::$instance;
48 /**
49 * Returns the asset values of the requested type.
51 * If no assets are found, an empty array is returned.
53 * @param string $assetType
54 * @return string[]
56 public function get(string $assetType) : array
58 return $this->values[$assetType] ?? [];
61 /**
62 * Returns an asset type object for the requested type.
64 * If no assets are found, an AssetType object containing no assets is returned.
66 * @param string $assetType
67 * @return AssetTypeInterface
69 public function getAssetType(string $assetType) : AssetTypeInterface
71 if (!isset($this->assetTypes[$assetType])) {
72 if (isset($this->assetTypesArray[$assetType])) {
73 $this->assetTypes[$assetType] = ImmutableAssetType::fromArray($assetType, $this->assetTypesArray[$assetType]);
74 } else {
75 $this->assetTypes[$assetType] = ImmutableAssetType::fromArray($assetType, []);
78 return $this->assetTypes[$assetType];