Commit a5a91335 authored by Armando Lüscher's avatar Armando Lüscher

Initial code cleanup of `Command.php`.

No functional changes, only modifications of documentation and code layout.
parent 6eef53dc
<?php
/*
* This file is part of the TelegramBot package.
*
......@@ -7,37 +6,117 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
*/
namespace Longman\TelegramBot;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\User;
use Longman\TelegramBot\Entities\Chat;
abstract class Command
{
/**
* Telegram object
*
* @var Telegram
*/
protected $telegram;
/**
* Update object
*
* @var Entities\Update
*/
protected $update;
/**
* Message object
*
* @var Entities\Message
*/
protected $message;
/**
* Command
*
* @var string
*/
protected $command;
protected $public = false;
/**
* Name
*
* @var string
*/
protected $name = '';
/**
* Description
*
* @var string
*/
protected $description = 'Command help';
/**
* Usage
*
* @var string
*/
protected $usage = 'Command usage';
/**
* Version
*
* @var string
*/
protected $version = '1.0.0';
protected $need_mysql = false;
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
protected $name = '';
/**
* If this command is public
*
* @var boolean
*/
protected $public = false;
/**
* If this command needs mysql
*
* @var boolean
*/
protected $need_mysql = false;
/**
* Command config
*
* @var array
*/
protected $config;
/**
* Constructor
*
* @param Telegram $telegram
*/
public function __construct(Telegram $telegram)
{
$this->telegram = $telegram;
$this->config = $telegram->getCommandConfig($this->name);
}
/**
* Set update object
*
* @param Entities\Update $update
* @return Command
*/
public function setUpdate(Update $update)
{
$this->update = $update;
......@@ -45,6 +124,11 @@ abstract class Command
return $this;
}
/**
* Pre-execute command
*
* @return mixed
*/
public function preExecute()
{
if (!$this->need_mysql |
......@@ -55,25 +139,48 @@ abstract class Command
return $this->executeNoDB();
}
/**
* Execute command
*/
abstract public function execute();
// this methods is executed if $need_mysql is true
// but DB connection for some reason is not avaiable
/**
* This methods is executed if $need_mysql is true
* but DB connection for some reason is not avaiable
*/
public function executeNoDB()
{
}
/**
* Get update object
*
* @return Entities\Update
*/
public function getUpdate()
{
return $this->update;
}
/**
* Get message object
*
* @return Entities\Message
*/
public function getMessage()
{
return $this->message;
}
/**
* Get command config
*
* @todo Returns need looking at!
*
* @param string $name
* @return mixed
*/
public function getConfig($name = null)
{
if (isset($this->config[$name])) {
......@@ -85,42 +192,83 @@ abstract class Command
return $this->config;
}
/**
* Get telegram object
*
* @return Telegram
*/
public function getTelegram()
{
return $this->telegram;
}
/**
* Set command
*
* @param string $command
* @return Command
*/
public function setCommand($command)
{
$this->command = $command;
return $this;
}
/**
* Get usage
*
* @return string
*/
public function getUsage()
{
return $this->usage;
}
/**
* Get version
*
* @return string
*/
public function getVersion()
{
return $this->version;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Check if command is enabled
*
* @return boolean
*/
public function isEnabled()
{
return $this->enabled;
}
/**
* Check if command is public
*
* @return boolean
*/
public function isPublic()
{
return $this->public;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment