Longman\TelegramBot\Telegram::getCommandObject PHP Method

getCommandObject() public method

Get an object instance of the passed command
public getCommandObject ( string $command ) : Command | null
$command string
return Longman\TelegramBot\Commands\Command | null
    public function getCommandObject($command)
    {
        $which = ['System'];
        $this->isAdmin() && ($which[] = 'Admin');
        $which[] = 'User';
        foreach ($which as $auth) {
            $command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands\\' . $this->ucfirstUnicode($command) . 'Command';
            if (class_exists($command_namespace)) {
                return new $command_namespace($this, $this->update);
            }
        }
        return null;
    }

Usage Example

 public function testGetHelpCommandObject()
 {
     $command = $this->telegram->getCommandObject('help');
     $this->assertInstanceOf('Longman\\TelegramBot\\Commands\\UserCommands\\HelpCommand', $command);
 }