/** * Add a command to the commands list. * * @param CommandInterface|string $command Either an object or full path to the command class. * * @return CommandBus * * @throws TelegramSDKException */ public function addCommand($command) { if (!is_object($command)) { if (!class_exists($command)) { throw new TelegramSDKException(sprintf('Command class "%s" not found! Please make sure the class exists.', $command)); } if ($this->telegram->hasContainer()) { $command = $this->buildDependencyInjectedCommand($command); } else { $command = new $command(); } } if ($command instanceof CommandInterface) { /** * At this stage we definitely have a proper command to use. * @var Command $command */ $this->commands[$command->getName()] = $command; return $this; } throw new TelegramSDKException(sprintf('Command class "%s" should be an instance of "Telegram\\Bot\\Commands\\CommandInterface"', get_class($command))); }