public function getCommandsList()
{
$commands = [];
foreach ($this->commands_paths as $path) {
try {
//Get all "*Command.php" files
$files = new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)), '/^.+Command.php$/');
foreach ($files as $file) {
//Remove "Command.php" from filename
$command = $this->sanitizeCommand(substr($file->getFilename(), 0, -11));
$command_name = strtolower($command);
if (array_key_exists($command_name, $commands)) {
continue;
}
require_once $file->getPathname();
$command_obj = $this->getCommandObject($command);
if ($command_obj instanceof Command) {
$commands[$command_name] = $command_obj;
}
}
} catch (Exception $e) {
throw new TelegramException('Error getting commands from path: ' . $path);
}
}
return $commands;
}