1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-11-16 16:30:09 +00:00
Tims-Chat/files/lib/data/command/CommandCache.class.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
2.4 KiB
PHP
Raw Normal View History

2018-08-16 22:30:59 +00:00
<?php
2022-03-04 17:10:24 +00:00
2018-08-16 22:30:59 +00:00
/*
2024-01-13 20:03:36 +00:00
* Copyright (c) 2010-2024 Tim Düsterhus.
2018-08-16 22:30:59 +00:00
*
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
2024-01-13 20:03:36 +00:00
* Change Date: 2028-01-13
2018-08-16 22:30:59 +00:00
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
* or later of the General Public License.
*/
namespace chat\data\command;
2022-03-04 17:10:24 +00:00
use chat\system\cache\builder\CommandCacheBuilder;
use wcf\data\package\Package;
use wcf\system\SingletonFactory;
2018-08-16 22:30:59 +00:00
/**
* Manages the command cache.
*/
2022-03-04 18:35:31 +00:00
final class CommandCache extends SingletonFactory
2022-03-04 17:10:24 +00:00
{
/**
* list of cached commands
* @var Command[]
*/
protected $commands = [ ];
/**
* list of cached commands by package
* @var Command[][]
*/
protected $packages = [ ];
/**
* list of cached triggers
* @var int[]
*/
protected $triggers = [ ];
/**
* @inheritDoc
*/
protected function init()
{
$data = CommandCacheBuilder::getInstance()->getData();
$this->commands = $data['commands'];
$this->packages = $data['packages'];
$this->triggers = $data['triggers'];
}
/**
* Returns a specific command.
*/
2022-03-04 17:47:19 +00:00
public function getCommand(int $commandID): ?Command
2022-03-04 17:10:24 +00:00
{
if (isset($this->commands[$commandID])) {
return $this->commands[$commandID];
}
return null;
}
/**
* Returns a specific command defined by a trigger.
*/
2022-03-04 17:47:19 +00:00
public function getCommandByTrigger(string $trigger): ?Command
2022-03-04 17:10:24 +00:00
{
if (isset($this->triggers[$trigger])) {
return $this->commands[$this->triggers[$trigger]];
}
return null;
}
/**
* Returns the command defined by the given package and identifier.
*/
2022-03-04 17:47:19 +00:00
public function getCommandByPackageAndIdentifier(Package $package, string $identifier): ?Command
2022-03-04 17:10:24 +00:00
{
if (isset($this->packages[$package->packageID][$identifier])) {
return $this->packages[$package->packageID][$identifier];
}
return null;
}
/**
* Returns all commands.
*
* @return Command[]
*/
public function getCommands()
{
return $this->commands;
}
/**
* Returns all triggers.
*
* @return int[]
*/
public function getTriggers()
{
return $this->triggers;
}
2018-08-16 22:30:59 +00:00
}