Longman\TelegramBot\Telegram::getCommandsList PHP Method

getCommandsList() public method

Get commands list
public getCommandsList ( ) : array
return array $commands
    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;
    }

Usage Example

コード例 #1
0
 /**
  * setUp
  */
 public function setUp()
 {
     $this->telegram = new Telegram('apikey', 'testbot');
     $this->telegram->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands');
     $this->telegram->getCommandsList();
 }
All Usage Examples Of Longman\TelegramBot\Telegram::getCommandsList