A console controller consists of one or several actions known as sub-commands. Users call a console command by specifying the corresponding route which identifies a controller action. The yii program is used when calling a console command, like the following: ~~~ yii [--param1=value1 --param2 ...] ~~~ where is a route to a controller action and the params will be populated as properties of a command. See Controller::options for details.
С версии: 2.0
Автор: Qiang Xue (qiang.xue@gmail.com)
Наследование: extends yii\base\Controller
 public function init()
 {
     parent::init();
     if (empty(Yii::$app->params['hook_secret'])) {
         throw new Exception('Config param "hook_secret" is not configured!');
     }
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     $this->apiKey = trim($this->apiKey);
     $this->apiLanguage = strtolower(trim($this->apiLanguage));
     $this->apiFormat = strtoupper(trim($this->apiFormat));
     $this->verbose = !!$this->verbose;
     // check API key
     if (empty($this->apiKey)) {
         throw new Exception('Operation failed. Steam API key is empty.');
     }
     // check language
     if (strlen(utf8_decode($this->apiLanguage)) !== 5 || strpos($this->apiLanguage, '_') === false) {
         $this->apiLanguage = self::DEFAULT_API_LANG;
         if ($this->verbose) {
             $this->stderr('Language is invalid. Default language "' . $this->apiLanguage . '" is used.' . PHP_EOL, Console::FG_YELLOW);
         }
     }
     // check format
     if (!in_array($this->apiFormat, self::$_apiFormats)) {
         $this->apiFormat = self::DEFAULT_API_FORMAT;
         if ($this->verbose) {
             $this->stderr('Format is invalid. Default format "' . $this->apiFormat . '" is used.' . PHP_EOL, Console::FG_YELLOW);
         }
     }
     // check result type
     if (empty($this->resultType)) {
         $this->stderr('Result type is empty.' . PHP_EOL, Console::FG_RED);
         return self::EXIT_CODE_ERROR;
     }
     $this->apiUrlSuffix = '/?key=' . $this->apiKey . '&language=' . $this->apiLanguage . '&format=' . $this->apiFormat;
     return true;
 }
Пример #3
0
 public function confirm($message, $default = false)
 {
     if (!$this->interactive) {
         return true;
     }
     return parent::confirm($message, $default);
 }
Пример #4
0
 public function beforeAction($action)
 {
     $this->fdb = Yii::$app->mysql;
     $this->db = Yii::$app->db;
     return parent::beforeAction($action);
     // TODO: Change the autogenerated stub
 }
 public function beforeAction($action)
 {
     $this->interpreterPath = Yii::$app->controllerMap['cron']['interpreterPath'];
     $this->bootstrapScript = Yii::$app->controllerMap['cron']['bootstrapScript'];
     return parent::beforeAction($action);
     // TODO: Change the autogenerated stub
 }
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * It checks the existence of the [[migrationPath]].
  * @param \yii\base\Action $action the action to be executed.
  * @throws InvalidConfigException if directory specified in migrationPath doesn't exist and action isn't "create".
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if (empty($this->migrationNamespaces) && empty($this->migrationPath)) {
             throw new InvalidConfigException('At least one of `migrationPath` or `migrationNamespaces` should be specified.');
         }
         foreach ($this->migrationNamespaces as $key => $value) {
             $this->migrationNamespaces[$key] = trim($value, '\\');
         }
         if ($this->migrationPath !== null) {
             $path = Yii::getAlias($this->migrationPath);
             if (!is_dir($path)) {
                 if ($action->id !== 'create') {
                     throw new InvalidConfigException("Migration failed. Directory specified in migrationPath doesn't exist: {$this->migrationPath}");
                 }
                 FileHelper::createDirectory($path);
             }
             $this->migrationPath = $path;
         }
         $version = Yii::getVersion();
         $this->stdout("Yii Migration Tool (based on Yii v{$version})\n\n");
         return true;
     } else {
         return false;
     }
 }
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action) || !substr(gethostname(), strlen(gethostname()) - 6) == ".local") {
         return false;
     }
     return true;
 }
Пример #8
0
 public function init()
 {
     parent::init();
     $this->token = (require __DIR__ . '/token.php');
     $this->datePath = __DIR__ . "/dateLastQuery.txt";
     $this->dateLastQuery = $this->getDateLastQuery();
 }
Пример #9
0
 public function beforeAction($action)
 {
     if (false === parent::beforeAction($action)) {
         return false;
     }
     return $this->module->has('importer');
 }
Пример #10
0
 /**
  * Init
  */
 public function init()
 {
     parent::init();
     // Support cyrillic on windows
     if ($this->isWindows()) {
         system("chcp 65001");
     }
 }
Пример #11
0
 /**
  * 选项
  * @param string $actionID
  * @return array
  */
 public function options($actionID)
 {
     if ($actionID == 'index') {
         return array_merge(parent::options($actionID), ['phpEnv', 'processMaxNum']);
     } else {
         return parent::options($actionID);
     }
 }
Пример #12
0
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         return Yii::$app->id == "mqg-proxy-agg-console";
     } else {
         return false;
     }
 }
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         $this->db = Instance::ensure($this->db, Connection::className());
         return true;
     }
     return false;
 }
Пример #14
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     // allow console requests only
     if (!Yii::$app->request->isConsoleRequest) {
         throw new HttpException(404, 'The requested page does not exist.');
     }
     parent::init();
 }
Пример #15
0
 public function options($id)
 {
     $options = [];
     if (in_array($id, ['start', 'restart'])) {
         $options = ['fork'];
     }
     return array_merge(parent::options($id), $options);
 }
Пример #16
0
 public function options($id)
 {
     $options = parent::options($id);
     $options[] = 'fake_steal';
     $options[] = 'file_report';
     $options[] = 'continue';
     return $options;
 }
Пример #17
0
 public function init()
 {
     parent::init();
     $this->gman_worker = new \GearmanWorker();
     $this->gman_worker->addServers($this->module->gman_server);
     $this->gman_client = new \GearmanClient();
     $this->gman_client->addServers($this->module->gman_server);
 }
 /**
  * Checks for write permissions in outputDirectory
  * @throws Exception
  */
 public function beforeAction($action)
 {
     parent::beforeAction($action);
     if (!is_writable(\Yii::getAlias($this->outputDirectory))) {
         throw new Exception("Invalid outputDirectory: '{$this->outputDirectory}' is not writable");
     } else {
         return true;
     }
 }
 public function beforeAction($action)
 {
     if (strtolower($this->verbose) === "false" || $this->verbose === "0") {
         $this->verbose = false;
     } else {
         $this->verbose = true;
     }
     return parent::beforeAction($action);
 }
Пример #20
0
 public function init()
 {
     if (\Yii::$app->has($this->schedule)) {
         $this->schedule = Instance::ensure($this->schedule, Schedule::className());
     } else {
         $this->schedule = \Yii::createObject(Schedule::className());
     }
     parent::init();
 }
Пример #21
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::class);
     if (empty($this->db_driver)) {
         $this->db_driver = $this->db->driverName;
     }
     $this->prepareCredentials();
 }
Пример #22
0
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if (empty($this->path)) {
             throw new InvalidConfigException('`path` should be specified');
         }
     }
     return true;
 }
Пример #23
0
 /**
  * Init function
  */
 public function init()
 {
     parent::init();
     //set PCNTL signal handlers
     pcntl_signal(SIGTERM, ['vyants\\daemon\\DaemonController', 'signalHandler']);
     pcntl_signal(SIGHUP, ['vyants\\daemon\\DaemonController', 'signalHandler']);
     pcntl_signal(SIGUSR1, ['vyants\\daemon\\DaemonController', 'signalHandler']);
     pcntl_signal(SIGCHLD, ['vyants\\daemon\\DaemonController', 'signalHandler']);
     $this->shortName = $this->shortClassName();
 }
Пример #24
0
 public function init()
 {
     parent::init();
     $this->token = (require __DIR__ . '/token.php');
     $this->datePath = __DIR__ . "/dateLastQuery.txt";
     $this->dateLastQuery = $this->getDateLastQuery();
     set_time_limit(0);
     //0表示没有限制
     ini_set('memory_limit', '500M');
 }
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * @param \yii\base\Action $action the action to be executed.
  * @throws Exception if directory specified in migrationPath doesn't exist and action isn't "create".
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         $version = Yii::getVersion();
         $this->stdout("Yii PubSub Tool (based on Yii v{$version})\n\n");
         return true;
     } else {
         return false;
     }
 }
Пример #26
0
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     if (Yii::$app instanceof \yii\web\Application) {
         throw new ForbiddenHttpException('You are not allowed to access this page.');
     }
     return true;
 }
 /**
  * extending parent
  * @access public
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($this->db === null) {
             $this->db = Yii::$app->db;
         }
         return 1;
     } else {
         return 0;
     }
 }
Пример #28
0
 public function init()
 {
     parent::init();
     $this->formUser = Yii::$app->params['supportEmail'];
     $this->siteName = Yii::$app->name;
     if (Yii::$app->has('setting')) {
         $this->formUser = Yii::$app->setting->get('smtpUser');
         $this->siteName = Yii::$app->setting->get('siteName');
         Yii::$app->set('mailer', ['class' => 'yii\\swiftmailer\\Mailer', 'viewPath' => '@common/mail', 'transport' => ['class' => 'Swift_SmtpTransport', 'host' => Yii::$app->setting->get('smtpHost'), 'username' => Yii::$app->setting->get('smtpUser'), 'password' => Yii::$app->setting->get('smtpPassword'), 'port' => Yii::$app->setting->get('smtpPort'), 'encryption' => 'tls']]);
     }
 }
Пример #29
0
 /**
  * {@inheritDoc}
  */
 public function init()
 {
     try {
         if (!isset(Yii::$app->getI18n()->translations['udokmeci.beanstalkd'])) {
             Yii::$app->getI18n()->translations['udokmeci.beanstalkd'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@app/messages', 'sourceLanguage' => 'en', 'fileMap' => []];
         }
     } catch (\Pheanstalk\Exception\ConnectionException $e) {
         Yii::error($e);
     }
     return parent::init();
 }
Пример #30
-1
 /**
  * @inheritdoc
  */
 public function init()
 {
     // check if this is being run via console only
     if (!\Yii::$app->request->isConsoleRequest) {
         throw new HttpException(404, 'The requested page does not exist.');
     }
     parent::init();
 }