Commit d1442fe9 authored by RedScorp's avatar RedScorp

for UTF-8 characters in the class definition and commands

parent 3b97af62
...@@ -252,7 +252,8 @@ class Telegram ...@@ -252,7 +252,8 @@ class Telegram
$which[] = 'User'; $which[] = 'User';
foreach ($which as $auth) { foreach ($which as $auth) {
$command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands\\' . ucfirst($command) . 'Command'; // $command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands\\' . ucfirst($command) . 'Command';
$command_namespace = __NAMESPACE__ . '\\Commands\\' . $auth . 'Commands\\' . $this->mb_ucfirst($command) . 'Command';
if (class_exists($command_namespace)) { if (class_exists($command_namespace)) {
return new $command_namespace($this, $this->update); return new $command_namespace($this, $this->update);
} }
...@@ -430,7 +431,8 @@ class Telegram ...@@ -430,7 +431,8 @@ class Telegram
*/ */
private function getCommandFromType($type) private function getCommandFromType($type)
{ {
return ucfirst(str_replace('_', '', $type)); // return ucfirst(str_replace('_', '', $type));
return $this->mb_ucfirst(str_replace('_', '', $type));
} }
/** /**
...@@ -521,7 +523,8 @@ class Telegram ...@@ -521,7 +523,8 @@ class Telegram
*/ */
protected function sanitizeCommand($command) protected function sanitizeCommand($command)
{ {
return str_replace(' ', '', ucwords(str_replace('_', ' ', $command))); // return str_replace(' ', '', ucwords(str_replace('_', ' ', $command)));
return str_replace(' ', '', $this->mb_ucwords(str_replace('_', ' ', $command)));
} }
/** /**
...@@ -759,4 +762,29 @@ class Telegram ...@@ -759,4 +762,29 @@ class Telegram
return $result; return $result;
} }
/**
* Replace function `ucwords` for UTF-8 characters in the class definition and commands
*
* @param string $str
* @param string $encoding (default = 'UTF-8')
*
* @return string
*/
protected function mb_ucwords($str, $encoding = 'UTF-8') {
return mb_convert_case($str, MB_CASE_TITLE, $encoding);
}
/**
* Replace function `ucfirst` for UTF-8 characters in the class definition and commands
*
* @param string $str
* @param string $encoding (default = 'UTF-8')
*
* @return string
*/
protected function mb_ucfirst($str, $encoding = 'UTF-8') {
return mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_strtolower(mb_substr($str, 1, mb_strlen($str), $encoding), $encoding);
}
} }
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