4 namespace TheCodingMachine\Discovery
;
7 * Use this class to access data stored in the discovery.json files at the root of your packages.
9 class Discovery
implements DiscoveryInterface
11 private static $instance;
24 private $assetTypesArray;
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';
36 * Returns the unique instance of this class (singleton).
40 public static function getInstance(): self
42 if (!self
::$instance) {
43 self
::$instance = new self();
45 return self
::$instance;
49 * Returns the asset values of the requested type.
51 * If no assets are found, an empty array is returned.
53 * @param string $assetType
56 public function get(string $assetType) : array
58 return $this->values
[$assetType] ??
[];
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]);
75 $this->assetTypes
[$assetType] = ImmutableAssetType
::fromArray($assetType, []);
78 return $this->assetTypes
[$assetType];