2018-09-22 17:06:13 +01:00
|
|
|
<?php
|
2025-03-29 10:50:03 +00:00
|
|
|
|
2022-02-14 20:48:15 -08:00
|
|
|
/**
|
|
|
|
|
* Provides static access to manage and get Collections.
|
2018-09-22 17:06:13 +01:00
|
|
|
*
|
2022-02-14 20:48:15 -08:00
|
|
|
* @package NamelessMC\Collections
|
|
|
|
|
* @see Collection
|
|
|
|
|
* @author Samerton
|
|
|
|
|
* @version 2.0.0-pr8
|
|
|
|
|
* @license MIT
|
2018-09-22 17:06:13 +01:00
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
class CollectionManager
|
|
|
|
|
{
|
2021-10-07 14:02:46 -07:00
|
|
|
/** @var Collection[] */
|
2021-10-29 22:00:05 -07:00
|
|
|
private static array $_collections = [];
|
2018-09-22 17:06:13 +01:00
|
|
|
|
2024-03-09 03:19:55 -08:00
|
|
|
public static function addItemToCollection(string $collection, CollectionItemBase $item): void
|
|
|
|
|
{
|
2020-12-13 20:42:04 -08:00
|
|
|
if (!isset(self::$_collections[$collection])) {
|
2020-12-13 19:38:04 +01:00
|
|
|
self::$_collections[$collection] = new Collection();
|
2020-12-13 20:42:04 -08:00
|
|
|
}
|
2018-09-22 17:06:13 +01:00
|
|
|
|
2020-12-13 19:38:04 +01:00
|
|
|
self::$_collections[$collection]->addItem($item);
|
|
|
|
|
}
|
2018-09-22 17:06:13 +01:00
|
|
|
|
2022-03-30 21:15:17 -07:00
|
|
|
/**
|
2024-03-09 03:19:55 -08:00
|
|
|
* @param string $collection
|
2022-03-30 21:15:17 -07:00
|
|
|
* @return CollectionItemBase[]
|
|
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
public static function getFullCollection(string $collection): array
|
|
|
|
|
{
|
2021-11-02 23:37:19 -07:00
|
|
|
return isset(self::$_collections[$collection])
|
2021-12-07 22:14:12 -08:00
|
|
|
? self::$_collections[$collection]->getAllItems()
|
|
|
|
|
: [];
|
2020-12-13 19:38:04 +01:00
|
|
|
}
|
2018-09-22 17:06:13 +01:00
|
|
|
|
2022-03-30 21:15:17 -07:00
|
|
|
/**
|
2024-03-09 03:19:55 -08:00
|
|
|
* @param string $collection
|
2022-03-30 21:15:17 -07:00
|
|
|
* @return CollectionItemBase[]
|
|
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
public static function getEnabledCollection(string $collection): array
|
|
|
|
|
{
|
2021-11-02 23:37:19 -07:00
|
|
|
return isset(self::$_collections[$collection])
|
2021-12-07 22:14:12 -08:00
|
|
|
? self::$_collections[$collection]->getEnabledItems()
|
|
|
|
|
: [];
|
2020-12-13 19:38:04 +01:00
|
|
|
}
|
|
|
|
|
}
|