Skip to content

Commit 452c344

Browse files
committed
Merge branch 'develop' of https://github.com/akalongman/php-telegram-bot into develop
2 parents 51c9c2a + 1cb65a1 commit 452c344

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/Telegram.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function getCommandObject($command)
252252
$which[] = 'User';
253253

254254
foreach ($which as $auth) {
255-
$command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands\\' . ucfirst($command) . 'Command';
255+
$command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands\\' . $this->ucfirstUnicode($command) . 'Command';
256256
if (class_exists($command_namespace)) {
257257
return new $command_namespace($this, $this->update);
258258
}
@@ -430,7 +430,7 @@ public function handle()
430430
*/
431431
private function getCommandFromType($type)
432432
{
433-
return ucfirst(str_replace('_', '', $type));
433+
return $this->ucfirstUnicode(str_replace('_', '', $type));
434434
}
435435

436436
/**
@@ -521,7 +521,7 @@ public function executeCommand($command)
521521
*/
522522
protected function sanitizeCommand($command)
523523
{
524-
return str_replace(' ', '', ucwords(str_replace('_', ' ', $command)));
524+
return str_replace(' ', '', $this->ucwordsUnicode(str_replace('_', ' ', $command)));
525525
}
526526

527527
/**
@@ -759,4 +759,30 @@ public function unsetWebHook()
759759

760760
return $result;
761761
}
762+
763+
/**
764+
* Replace function `ucwords` for UTF-8 characters in the class definition and commands
765+
*
766+
* @param string $str
767+
* @param string $encoding (default = 'UTF-8')
768+
*
769+
* @return string
770+
*/
771+
protected function ucwordsUnicode($str, $encoding = 'UTF-8')
772+
{
773+
return mb_convert_case($str, MB_CASE_TITLE, $encoding);
774+
}
775+
776+
/**
777+
* Replace function `ucfirst` for UTF-8 characters in the class definition and commands
778+
*
779+
* @param string $str
780+
* @param string $encoding (default = 'UTF-8')
781+
*
782+
* @return string
783+
*/
784+
protected function ucfirstUnicode($str, $encoding = 'UTF-8')
785+
{
786+
return mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_strtolower(mb_substr($str, 1, mb_strlen($str), $encoding), $encoding);
787+
}
762788
}

0 commit comments

Comments
 (0)