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

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

91 lines
2.0 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\system\command;
2022-03-04 17:10:24 +00:00
use chat\data\command\Command;
use chat\data\room\Room;
use wcf\data\DatabaseObjectDecorator;
use wcf\data\IDatabaseObjectProcessor;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\user\UserProfile;
use wcf\system\exception\UserInputException;
2018-08-16 22:30:59 +00:00
/**
* Default implemention for command processors.
*/
2022-03-04 17:10:24 +00:00
abstract class AbstractCommand extends DatabaseObjectDecorator implements
ICommand,
IDatabaseObjectProcessor
{
/**
* @inheritDoc
*/
protected static $baseClass = Command::class;
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
/**
* @inheritDoc
*/
public function isAvailable(Room $room, ?UserProfile $user = null)
{
return true;
}
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
/**
* @inheritDoc
*/
public function allowWithoutTrigger()
{
return false;
}
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
/**
* Returns the object type ID for the given message type.
*
* @param string
* @return int
*/
public function getMessageObjectTypeID($objectType)
{
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.messageType',
$objectType
);
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
if (!$objectType) {
throw new \LogicException('Missing object type');
}
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
return $objectTypeID;
}
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
/**
* Ensures that the given parameter exists in the parameter array and
* throws otherwise.
*
* @param array $parameters
* @param string $key
* @return mixed The value.
*/
public function assertParameter($parameters, $key)
{
if (\array_key_exists($key, $parameters)) {
return $parameters[$key];
}
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
throw new UserInputException('message');
}
2018-08-16 22:30:59 +00:00
}