Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
6c03ff17
Commit
6c03ff17
authored
Feb 01, 2016
by
Marco Boretto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #80 from noplanman/code_cleanup_Command
Code cleanup of Command.php
parents
f8fd4b04
a5a91335
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
8 deletions
+156
-8
Command.php
src/Command.php
+156
-8
No files found.
src/Command.php
View file @
6c03ff17
<?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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment