コード例 #1
0
ファイル: Module.php プロジェクト: gogl92/yii2-teleduino
 public function init()
 {
     parent::init();
     if (count($this->getApiKeys()) === 0) {
         throw new InvalidConfigException('You must provide at least one apiKey in the application configuration.');
     }
     $this->set('api', Yii::createObject(Api::className()));
     if ($this->inWebContext()) {
         // In web mode we store overriding values in session.
         $session = Yii::$app->session;
         if (isset($session[self::SESSION_API_ENDPOINT])) {
             $this->api->setApiEndpoint($session[self::SESSION_API_ENDPOINT]);
         }
         if (isset($session[self::SESSION_CURRENT_API_KEY])) {
             $this->api->setApiKey($session[self::SESSION_CURRENT_API_KEY]);
         }
     } else {
         // In console mode we override controllers with commands
         $this->controllerNamespace = __NAMESPACE__ . '\\commands';
         Yii::$app->controllerMap['help'] = HelpController::className();
     }
 }
コード例 #2
0
 public function options($actionID)
 {
     return ArrayHelper::merge(['responseFormat'], $this->allowedApiOptions, $this->api->getMethodParams($actionID));
 }
コード例 #3
0
ファイル: console.php プロジェクト: gogl92/yii2-teleduino
<?php

// *** API component config *** //
// These parameters are useful for console command, since if set, you can omit setting
// corresponding options in the command line.
Yii::$container->set(\gogl92\teleduino\components\Api::className(), ['apiEndpoint' => 'https://my-endpoint.com', 'apiKey' => '00000000000000000000000000000000']);
Yii::setAlias('@tests', dirname(__DIR__) . '/tests');
$params = (require __DIR__ . '/params.php');
$db = (require __DIR__ . '/db.php');
return ['id' => 'basic-console', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log', 'gii', 'teleduino'], 'controllerNamespace' => 'app\\commands', 'modules' => ['gii' => 'yii\\gii\\Module', 'teleduino' => ['class' => 'gogl92\\teleduino\\Module']], 'components' => ['cache' => ['class' => 'yii\\caching\\FileCache'], 'log' => ['targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'db' => $db], 'params' => $params];