mc-cms-namelessmc/core/classes/Collections/CollectionManager.php

48 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2018-09-22 17:06:13 +01:00
<?php
/**
* Provides static access to manage and get Collections.
2018-09-22 17:06:13 +01:00
*
* @package NamelessMC\Collections
* @see Collection
* @author Samerton
* @version 2.0.0-pr8
* @license MIT
2018-09-22 17:06:13 +01: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
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
/**
* @param string $collection
2022-03-30 21:15:17 -07:00
* @return CollectionItemBase[]
*/
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
/**
* @param string $collection
2022-03-30 21:15:17 -07:00
* @return CollectionItemBase[]
*/
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
}
}