activityReport/src/Groups.php

67 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2023-10-17 20:47:35 +00:00
declare(strict_types=1);
namespace Dotclear\Plugin\activityReport;
/**
2023-10-17 20:47:35 +00:00
* @brief activityReport actions groups stack class.
* @ingroup activityReport
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Groups
{
/** @var array<string, Group> $stack The actions groups stack */
private array $stack = [];
/**
* Chek if a group exists.
*
* @param string $id The group ID
*
* @return bool True if it exists
*/
public function has(string $id): bool
{
return isset($this->stack[$id]);
}
/**
* Add a group.
*
* @param Group $group The group object
*
* @return Groups The groups instance
*/
public function add(Group $group): Groups
{
$this->stack[$group->id] = $group;
return $this;
}
/**
* Get a group.
*
* @param string $id The group ID
*
* @return Group The group descriptor
*/
public function get(string $id): Group
{
return $this->stack[$id] ?? new Group($id, 'undefined');
}
/**
* Get all groups.
*
* @return array<string, Group> The groups stack
*/
public function dump(): array
{
return $this->stack;
}
}