setContainer() public static method

Set the IoC Container.
public static setContainer ( Illuminate\Contracts\Container\Container $container ) : void
$container Illuminate\Contracts\Container\Container Container instance
return void
コード例 #1
0
 /**
  * Initialize Telegram Bot SDK Library with Default Config.
  *
  * @param Application $app
  */
 protected function registerTelegram(Application $app)
 {
     $app->singleton(Api::class, function ($app) {
         $config = $app['config'];
         $telegram = new Api($config->get('telegram.bot_token', false), $config->get('telegram.async_requests', false), $config->get('telegram.http_client_handler', null));
         // Register Commands
         $telegram->addCommands($config->get('telegram.commands', []));
         // Check if DI needs to be enabled for Commands
         if ($config->get('telegram.inject_command_dependencies', false)) {
             $telegram->setContainer($app);
         }
         return $telegram;
     });
     $app->alias(Api::class, 'telegram');
 }
コード例 #2
0
 /**
  * Make the bot instance.
  *
  * @param string $name
  *
  * @return Api
  */
 protected function makeBot($name)
 {
     $config = $this->getBotConfig($name);
     $token = array_get($config, 'token');
     $commands = array_get($config, 'commands', []);
     $telegram = new Api($token, $this->getConfig('async_requests', false), $this->getConfig('http_client_handler', null));
     // Check if DI needs to be enabled for Commands
     if ($this->getConfig('resolve_command_dependencies', true)) {
         $telegram->setContainer($this->app);
     }
     $commands = $this->parseBotCommands($commands);
     // Register Commands
     $telegram->addCommands($commands);
     return $telegram;
 }