Example #1
0
 public function init()
 {
     parent::init();
     $this->token = (require __DIR__ . '/token.php');
     $this->datePath = __DIR__ . "/dateLastQuery.txt";
     $this->dateLastQuery = $this->getDateLastQuery();
 }
 public function init()
 {
     if (strncmp($this->filename, './', 2) == 0) {
         $this->filename = Yii::$app->getBasePath() . substr($this->filename, 1);
     }
     parent::init();
 }
 public function init()
 {
     parent::init();
     if (empty(Yii::$app->params['hook_secret'])) {
         throw new Exception('Config param "hook_secret" is not configured!');
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     foreach ($this->generators as $id => $config) {
         $this->generators[$id] = Yii::createObject($config);
     }
 }
Example #5
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);
 }
Example #6
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();
 }
Example #7
0
 public function init()
 {
     parent::init();
     $this->api = Module::getInstance()->api;
     foreach ($this->allowedApiOptions as $option) {
         $this->{$option} = null;
     }
 }
 public function init()
 {
     if (!\Yii::$app instanceof ConsoleApplication) {
         throw new Exception('Yii::$app is not an instance of ConsoleApplication.');
         return Controller::EXIT_CODE_ERROR;
     }
     parent::init();
 }
Example #9
0
 /**
  * Init
  */
 public function init()
 {
     parent::init();
     // Support cyrillic on windows
     if ($this->isWindows()) {
         system("chcp 65001");
     }
 }
Example #10
0
 public function init()
 {
     pcntl_signal(SIGTERM, [$this, 'signalHandler']);
     pcntl_signal_dispatch();
     parent::init();
     if (self::$queue === null) {
         self::$queue = Yii::$app->{$this->queueObjectName};
     }
 }
 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();
 }
Example #12
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();
 }
Example #13
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');
 }
Example #14
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();
 }
 /**
  * {@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();
 }
Example #16
0
 /**
  * @return void
  */
 public function init()
 {
     parent::init();
     if (!is_numeric($this->sleepTimeout)) {
         throw new InvalidParamException('($sleepTimeout) must be an number');
     }
     if ($this->sleepTimeout < 0) {
         throw new InvalidParamException('($sleepTimeout) must be greater or equal than 0');
     }
     $this->queue = \yii\di\Instance::ensure($this->queue, Queue::className());
 }
Example #17
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']]);
     }
 }
 public function init()
 {
     parent::init();
     $faker = $faker = \Faker\Factory::create();
     $faker->addProvider(new \Faker\Provider\en_US\Person($faker));
     $faker->addProvider(new \Faker\Provider\en_US\Address($faker));
     $faker->addProvider(new \Faker\Provider\en_US\PhoneNumber($faker));
     $faker->addProvider(new \Faker\Provider\en_US\Company($faker));
     $faker->addProvider(new \Faker\Provider\Lorem($faker));
     $faker->addProvider(new \Faker\Provider\Internet($faker));
     $this->faker = $faker;
 }
Example #19
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $alias = $this->filePath;
     $filePath = $this->filePath = \Yii::getAlias($alias);
     if (empty($filePath)) {
         throw new \yii\base\InvalidConfigException(sprintf('Alias `%s` not exists', $alias));
     }
     if (!file_exists($filePath) && !is_writable(dirname($filePath))) {
         throw new \yii\base\Exception(sprintf('Directory `%s` is not writable', dirname($filePath)));
     }
 }
Example #20
0
 /**
  * Initialize
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     $this->authManager = Instance::ensure($this->authManager, BaseManager::className());
     $this->user = Instance::ensure($this->user, User::className());
     if (empty($this->cache)) {
         $this->cache = $this->createCacheComponent();
     } else {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }
 /**
  * Init function
  */
 public function init()
 {
     parent::init();
     //set PCNTL signal handlers
     pcntl_signal(SIGSYS, [__CLASS__, 'signalHandler']);
     pcntl_signal(SIGTERM, [__CLASS__, 'signalHandler']);
     pcntl_signal(SIGHUP, [__CLASS__, 'signalHandler']);
     pcntl_signal(SIGUSR1, [__CLASS__, 'signalHandler']);
     pcntl_signal(SIGUSR2, [__CLASS__, 'signalHandler']);
     pcntl_signal(SIGCHLD, [__CLASS__, 'signalHandler']);
     $this->shortName = $this->getConfigName($this->shortClassName(), ['Daemon']);
     $this->setConfigName();
 }
 public function init()
 {
     parent::init();
     foreach ($this->composerExecutables as $cmd) {
         // TODO: improve check
         exec($cmd . ' 2>&1', $output, $return);
         if ($return == 0) {
             $this->_composerExecutable = $cmd;
             return;
         }
     }
     throw new Exception('Composer executable not found.');
 }
 /**
  * Init.
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (!is_numeric($this->interval) || $this->interval < 0) {
         throw new InvalidConfigException('Interval must be integer greater than 0.');
     }
     if ($this->testRun && (!is_numeric($this->testTime) || $this->testTime < 0)) {
         throw new InvalidConfigException('TestRun must be integer greater than 0.');
     }
     if (empty($this->name)) {
         $this->name = $this->id;
     }
 }
Example #24
0
 public function init()
 {
     parent::init();
     $this->parseParams();
     //初始化解析参数
     //重写exception handler
     set_exception_handler(function ($e) {
         //捕获错误信息
         $this->exception = \yii\base\ErrorHandler::convertExceptionToString($e);
     });
     //重写register_shutdown
     register_shutdown_function(function () {
         //非致命错误脚本结束写日志
         $task = isset($this->data['task']) ? $this->data['task'] : '';
         $task_id = isset($this->data['info']['task_id']) ? $this->data['info']['task_id'] : 0;
         $orgcode = isset($this->data['info']['orgcode']) ? $this->data['info']['orgcode'] : '';
         $task_type = isset($this->data['info']['task_type']) ? $this->data['info']['task_type'] : '';
         $start_time = isset($this->data['info']['start_time']) ? $this->data['info']['start_time'] : '';
         $msg = [];
         $msg['info'] = $this->loginfo['info'];
         $msg['exitStatus'] = \Yii::$app->response->exitStatus;
         if (isset($this->data['retry_times'])) {
             $msg['retry_times'] = $this->data['retry_times'];
         }
         $end_time = date('Y-m-d H:i:s');
         if ($this->exception) {
             $msg['exitStatus'] = 1;
             $IsSuccess = 0;
         } elseif ($msg['exitStatus'] == 0) {
             $IsSuccess = 1;
         } elseif ($msg['exitStatus'] == 1) {
             $IsSuccess = 0;
         }
         $this->task_log($task_id, $orgcode, $task, $task_type, $start_time, $end_time, $msg, $IsSuccess, $this->exception);
         if ($IsSuccess) {
             //成功则更细
             $this->updateTaskStatus($task_id, ['progress' => 0, 'retry_times' => 0]);
             //更新任务状态
         } else {
             //失败则更新
             $retry_times = isset($this->data['retry_times']) ? $this->data['retry_times'] : 0;
             //                 $this->updateTaskStatus($task_id,['retry_times'=>$retry_times]); //更新任务状态,重试次数
             $this->updateTaskStatus($task_id, ['progress' => 0, 'retry_times' => 0]);
             //更新任务状态
         }
         if ($this->exception) {
             echo $this->exception, PHP_EOL;
             exit(1);
         }
     });
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $exclude = ['module' => ['debug', 'gii', 'metadata', 'queue']];
     foreach (Yii::$app->getModules() as $id => $child) {
         if (($child = Yii::$app->getModule($id)) !== null) {
             if (!in_array($child->id, $exclude['module'])) {
                 $path = '@' . str_replace('\\', '/', trim($child->controllerNamespace, '\\'));
                 $path = str_replace('commands', '[PUBSUB]', $path);
                 $path = str_replace('controllers', '[PUBSUB]', $path);
                 $this->workerPath[] = str_replace('[PUBSUB]', 'workers', $path);
                 $this->producerPath[] = str_replace('[PUBSUB]', 'producers', $path);
             }
         }
     }
 }
Example #26
0
 public function init()
 {
     parent::init();
     $this->parseParams();
     //初始化解析参数
     //重写exception handler
     set_exception_handler(function ($e) {
         //捕获错误信息,stack信息
         $this->exception = \yii\base\ErrorHandler::convertExceptionToString($e);
     });
     //重写register_shutdown
     register_shutdown_function(function () {
         //非致命错误脚本结束写日志
         //完成处理log对象
         if ($this->exception) {
             //异常处理模式跟`return 1`一样
             echo $this->exception, PHP_EOL;
             exit(1);
         }
     });
 }
Example #27
0
 /**
  * Initialize empty config parameters.
  */
 public function init()
 {
     parent::init();
     //Checking PHP interpriter path
     if ($this->interpreterPath === null) {
         if ($this->isWindowsOS()) {
             //Windows OS
             $this->interpreterPath = 'php.exe';
         } else {
             //nix based OS
             $this->interpreterPath = '/usr/bin/env php';
         }
     }
     //Checking logs directory
     if ($this->logsDir === null) {
         $this->logsDir = Yii::$app->getRuntimePath();
     }
     //Checking bootstrap script
     if ($this->bootstrapScript === null) {
         $this->bootstrapScript = Yii::getAlias('@runnerScript');
     }
 }
 public function init()
 {
     parent::init();
     if ($this->module->path == "") {
         throw new Exception("You should set path to app");
     }
     if ($this->module->versionFilePath == "") {
         throw new Exception("You should set path to version file");
     }
     if ($this->module->currentVersion == 0.0) {
         Console::output("Maybe you forget to set current version. Trying to get from version file");
         if (file_exists($this->module->versionFilePath)) {
             require_once $this->module->versionFilePath;
             if (defined($this->module->versionConstant)) {
                 $this->module->currentVersion = constant($this->module->versionConstant);
             }
         }
     }
     if ($this->module->assetsCommands == []) {
         Console::output("Maybe you forget to set assets commands");
     }
     Console::output("Starting process. Current version is " . $this->module->currentVersion);
 }
Example #29
0
 public function init()
 {
     parent::init();
     if (!isset($date)) {
         $date = date("Y-m-d");
     }
     $this->soapUrl = Yii::$app->params['cbrfSOAPURL'];
     $client = new \SoapClient($this->soapUrl);
     $curs = $client->GetCursOnDate(array("On_date" => $date));
     $rates = new \SimpleXMLElement($curs->GetCursOnDateResult->any);
     foreach ($rates->ValuteData->ValuteCursOnDate as $rate) {
         $rateArray = [];
         $rateArray['name'] = (string) $rate->Vname;
         $rateArray['code'] = (int) $rate->Vcode;
         $rateArray['chCode'] = (string) $rate->VchCode;
         $this->currency[] = $rateArray;
         $r = (double) $rate->Vcurs / (int) $rate->Vnom;
         $this->rates['byChCode'][(string) $rate->VchCode] = ['rate' => $r, 'curs' => (double) $rate->Vcurs, 'nom' => (int) $rate->Vnom];
         $this->rates['byCode'][(int) $rate->Vcode] = ['rate' => $r, 'curs' => (double) $rate->Vcurs, 'nom' => (int) $rate->Vnom];
     }
     // Adding an exchange rate of Russian Ruble
     $this->rates['byChCode']['RUB'] = 1;
     $this->rates['byCode'][643] = 1;
 }
Example #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();
 }