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
ba90f121
Unverified
Commit
ba90f121
authored
Aug 27, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A few code optimisations.
parent
98722812
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
47 deletions
+31
-47
KeyboardButton.php
src/Entities/KeyboardButton.php
+1
-1
ReplyKeyboardMarkup.php
src/Entities/ReplyKeyboardMarkup.php
+18
-16
ServerResponse.php
src/Entities/ServerResponse.php
+12
-30
No files found.
src/Entities/KeyboardButton.php
View file @
ba90f121
...
@@ -35,7 +35,7 @@ class KeyboardButton extends Entity
...
@@ -35,7 +35,7 @@ class KeyboardButton extends Entity
* @param array $data
* @param array $data
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
__construct
(
$data
=
array
()
)
public
function
__construct
(
array
$data
=
[]
)
{
{
$this
->
text
=
isset
(
$data
[
'text'
])
?
$data
[
'text'
]
:
null
;
$this
->
text
=
isset
(
$data
[
'text'
])
?
$data
[
'text'
]
:
null
;
if
(
empty
(
$this
->
text
))
{
if
(
empty
(
$this
->
text
))
{
...
...
src/Entities/ReplyKeyboardMarkup.php
View file @
ba90f121
...
@@ -40,27 +40,29 @@ class ReplyKeyboardMarkup extends Entity
...
@@ -40,27 +40,29 @@ class ReplyKeyboardMarkup extends Entity
* ReplyKeyboardMarkup constructor.
* ReplyKeyboardMarkup constructor.
*
*
* @param array $data
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
__construct
(
$data
=
array
()
)
public
function
__construct
(
array
$data
=
[]
)
{
{
if
(
isset
(
$data
[
'keyboard'
]))
{
if
(
!
isset
(
$data
[
'keyboard'
]))
{
if
(
is_array
(
$data
[
'keyboard'
]))
{
throw
new
TelegramException
(
'Keyboard field is empty!'
);
}
if
(
!
is_array
(
$data
[
'keyboard'
]))
{
throw
new
TelegramException
(
'Keyboard field is not an array!'
);
}
foreach
(
$data
[
'keyboard'
]
as
$item
)
{
foreach
(
$data
[
'keyboard'
]
as
$item
)
{
if
(
!
is_array
(
$item
))
{
if
(
!
is_array
(
$item
))
{
throw
new
TelegramException
(
'Keyboard subfield is not an array!'
);
throw
new
TelegramException
(
'Keyboard subfield is not an array!'
);
}
}
}
}
$this
->
keyboard
=
$data
[
'keyboard'
];
$this
->
keyboard
=
$data
[
'keyboard'
];
}
else
{
throw
new
TelegramException
(
'Keyboard field is not an array!'
);
}
}
else
{
throw
new
TelegramException
(
'Keyboard field is empty!'
);
}
$this
->
resize_keyboard
=
isset
(
$data
[
'resize_keyboard'
])
?
$data
[
'resize_keyboard'
]
:
false
;
//Set the object members from the passed data params
$this
->
one_time_keyboard
=
isset
(
$data
[
'one_time_keyboard'
])
?
$data
[
'one_time_keyboard'
]
:
false
;
foreach
([
'resize_keyboard'
,
'one_time_keyboard'
,
'selective'
]
as
$param
)
{
$this
->
selective
=
isset
(
$data
[
'selective'
])
?
$data
[
'selective'
]
:
false
;
$this
->
$param
=
isset
(
$data
[
$param
])
?
(
bool
)
$data
[
$param
]
:
false
;
}
}
}
}
}
src/Entities/ServerResponse.php
View file @
ba90f121
...
@@ -35,10 +35,12 @@ class ServerResponse extends Entity
...
@@ -35,10 +35,12 @@ class ServerResponse extends Entity
*
*
* @param array $data
* @param array $data
* @param $bot_name
* @param $bot_name
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
*/
public
function
__construct
(
array
$data
,
$bot_name
)
public
function
__construct
(
array
$data
,
$bot_name
)
{
{
if
(
isset
(
$data
[
'ok'
]
)
&&
isset
(
$data
[
'result'
]))
{
if
(
isset
(
$data
[
'ok'
]
,
$data
[
'result'
]))
{
if
(
is_array
(
$data
[
'result'
]))
{
if
(
is_array
(
$data
[
'result'
]))
{
if
(
$data
[
'ok'
]
&&
!
$this
->
isAssoc
(
$data
[
'result'
])
&&
!
isset
(
$data
[
'result'
][
0
][
'user'
]))
{
if
(
$data
[
'ok'
]
&&
!
$this
->
isAssoc
(
$data
[
'result'
])
&&
!
isset
(
$data
[
'result'
][
0
][
'user'
]))
{
//Get Update
//Get Update
...
@@ -49,7 +51,7 @@ class ServerResponse extends Entity
...
@@ -49,7 +51,7 @@ class ServerResponse extends Entity
//Response from getChatAdministrators
//Response from getChatAdministrators
$this
->
result
=
[];
$this
->
result
=
[];
foreach
(
$data
[
'result'
]
as
$user
)
{
foreach
(
$data
[
'result'
]
as
$user
)
{
array_push
(
$this
->
result
,
new
ChatMember
(
$user
)
);
$this
->
result
[]
=
new
ChatMember
(
$user
);
}
}
}
elseif
(
$data
[
'ok'
]
&&
$this
->
isAssoc
(
$data
[
'result'
]))
{
}
elseif
(
$data
[
'ok'
]
&&
$this
->
isAssoc
(
$data
[
'result'
]))
{
if
(
isset
(
$data
[
'result'
][
'total_count'
]))
{
if
(
isset
(
$data
[
'result'
][
'total_count'
]))
{
...
@@ -82,12 +84,7 @@ class ServerResponse extends Entity
...
@@ -82,12 +84,7 @@ class ServerResponse extends Entity
$this
->
ok
=
$data
[
'ok'
];
$this
->
ok
=
$data
[
'ok'
];
$this
->
result
=
true
;
$this
->
result
=
true
;
$this
->
error_code
=
null
;
$this
->
error_code
=
null
;
$this
->
description
=
isset
(
$data
[
'description'
])
?
$data
[
'description'
]
:
''
;
if
(
isset
(
$data
[
'description'
]))
{
$this
->
description
=
$data
[
'description'
];
}
else
{
$this
->
description
=
''
;
}
}
elseif
(
is_numeric
(
$data
[
'result'
]))
{
}
elseif
(
is_numeric
(
$data
[
'result'
]))
{
//Response from getChatMembersCount
//Response from getChatMembersCount
$this
->
result
=
$data
[
'result'
];
$this
->
result
=
$data
[
'result'
];
...
@@ -101,24 +98,9 @@ class ServerResponse extends Entity
...
@@ -101,24 +98,9 @@ class ServerResponse extends Entity
}
else
{
}
else
{
//webHook not set
//webHook not set
$this
->
ok
=
false
;
$this
->
ok
=
false
;
$this
->
result
=
isset
(
$data
[
'result'
])
?
$data
[
'result'
]
:
null
;
if
(
isset
(
$data
[
'result'
]))
{
$this
->
error_code
=
isset
(
$data
[
'error_code'
])
?
$data
[
'error_code'
]
:
null
;
$this
->
result
=
$data
[
'result'
];
$this
->
description
=
isset
(
$data
[
'description'
])
?
$data
[
'description'
]
:
null
;
}
else
{
$this
->
result
=
null
;
}
if
(
isset
(
$data
[
'error_code'
]))
{
$this
->
error_code
=
$data
[
'error_code'
];
}
else
{
$this
->
error_code
=
null
;
}
if
(
isset
(
$data
[
'description'
]))
{
$this
->
description
=
$data
[
'description'
];
}
else
{
$this
->
description
=
null
;
}
//throw new TelegramException('ok(variable) is not set!');
//throw new TelegramException('ok(variable) is not set!');
}
}
...
...
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