1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-11-14 16:10:08 +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.

78 lines
1.8 KiB
PHP
Raw Normal View History

2018-08-16 22:30:59 +00:00
<?php
/*
* Copyright (c) 2010-2018 Tim Düsterhus.
*
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
2020-11-01 16:09:27 +00:00
* Change Date: 2024-11-01
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;
use \chat\data\room\Room;
use \wcf\data\object\type\ObjectTypeCache;
use \wcf\data\user\UserProfile;
2018-10-23 20:01:53 +00:00
use \wcf\system\exception\UserInputException;
2018-08-16 22:30:59 +00:00
/**
* Default implemention for command processors.
*/
abstract class AbstractCommand extends \wcf\data\DatabaseObjectDecorator implements ICommand
, \wcf\data\IDatabaseObjectProcessor {
/**
* @inheritDoc
*/
protected static $baseClass = \chat\data\command\Command::class;
/**
* @inheritDoc
*/
public function isAvailable(Room $room, UserProfile $user = null) {
return true;
}
/**
* @inheritDoc
*/
public function allowWithoutTrigger() {
return false;
}
/**
* 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);
if (!$objectType) {
throw new \LogicException('Missing object type');
}
return $objectTypeID;
}
/**
* 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];
}
throw new UserInputException('message');
}
}