/**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app instanceof yii\web\Application) {
         $app->on(Application::EVENT_BEFORE_REQUEST, function () use($app) {
             $app->request->attachBehavior('monsterRequest', 'DotPlant\\Monster\\behaviors\\MonsterRequest');
         });
         $app->on(Application::EVENT_BEFORE_ACTION, function () use($app) {
             /** @var Repository $repository */
             $repository = $app->get('monsterRepository');
             $repository->autoloadAssets();
         });
     }
 }
Beispiel #2
0
 /**
  * Attaches global and class-level event handlers from sub-modules
  *
  * @param \yii\base\Application $app the application currently running
  */
 public function attachEvents($app)
 {
     foreach ($this->getModules() as $moduleID => $config) {
         $module = $this->getModule($moduleID);
         if ($module instanceof EventManagerInterface) {
             /** @var EventManagerInterface $module */
             foreach ($module->attachGlobalEvents() as $eventName => $handler) {
                 $app->on($eventName, $handler);
             }
             foreach ($module->attachClassEvents() as $className => $events) {
                 foreach ($events as $eventName => $handlers) {
                     foreach ($handlers as $handler) {
                         if (is_array($handler) && is_callable($handler[0])) {
                             $data = isset($handler[1]) ? array_pop($handler) : null;
                             $append = isset($handler[2]) ? array_pop($handler) : null;
                             Event::on($className, $eventName, $handler[0], $data, $append);
                         } elseif (is_callable($handler)) {
                             Event::on($className, $eventName, $handler);
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     $app->i18n->translations['extensions-manager'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => __DIR__ . DIRECTORY_SEPARATOR . 'messages'];
     DeferredQueueEvent::on(DeferredController::className(), DeferredController::EVENT_DEFERRED_QUEUE_COMPLETE, [DeferredQueueCompleteHandler::className(), 'handleEvent']);
     if ($app instanceof \yii\console\Application) {
         $app->controllerMap['extension'] = ExtensionController::className();
         $app->on(Application::EVENT_BEFORE_ACTION, function () {
             $module = ExtensionsManager::module();
             if ($module->autoDiscoverMigrations === true) {
                 if (isset(Yii::$app->params['yii.migrations']) === false) {
                     Yii::$app->params['yii.migrations'] = [];
                 }
                 /** @var array $extensions */
                 $extensions = $module->getExtensions();
                 foreach ($extensions as $name => $ext) {
                     if ($ext['composer_type'] === Extension::TYPE_DOTPLANT && $module->discoverDotPlantMigrations === false) {
                         continue;
                     }
                     $extData = ComposerInstalledSet::get()->getInstalled($ext['composer_name']);
                     $packageMigrations = ExtensionDataHelper::getInstalledExtraData($extData, 'migrationPath', true);
                     $packagePath = '@vendor/' . $ext['composer_name'];
                     foreach ($packageMigrations as $migrationPath) {
                         Yii::$app->params['yii.migrations'][] = "{$packagePath}/{$migrationPath}";
                     }
                 }
             }
         });
     }
 }
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ((isset($_GET['_xhprof']) || isset($_COOKIE['_xhprof'])) && function_exists('xhprof_enable')) {
         $app->on(Application::EVENT_BEFORE_REQUEST, function () use($app) {
             \xhprof_enable(\XHPROF_FLAGS_CPU + \XHPROF_FLAGS_MEMORY);
         });
     }
 }
Beispiel #5
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     $app->on(Application::EVENT_BEFORE_REQUEST, function () use($app) {
         try {
             /*******************************
                /* Mailer
                /*******************************/
             // Set default transport class
             $transport = ['class' => 'Swift_MailTransport'];
             // Change transport class to SMTP if was selected
             if (isset($app->params['App.Mailer.transport']) && $app->params['App.Mailer.transport'] === 'smtp') {
                 $transport = ['class' => 'Swift_SmtpTransport', 'host' => $app->settings->get("smtp.host"), 'username' => $app->settings->get("smtp.username"), 'password' => base64_decode($app->settings->get("smtp.password")), 'port' => $app->settings->get("smtp.port"), 'encryption' => $app->settings->get("smtp.encryption") == 'none' ? null : $app->settings->get("smtp.encryption")];
             }
             // Set mail queue component as mailer
             $app->set('mailer', ['class' => 'app\\components\\queue\\MailQueue', 'mailsPerRound' => 10, 'maxAttempts' => 3, 'transport' => $transport, 'messageConfig' => ['charset' => 'UTF-8']]);
             /*******************************
                /* User session
                /*******************************/
             if (isset($app->user) && !$app->user->isGuest) {
                 /** @var \app\models\Profile $profile */
                 $profile = $app->user->identity->profile;
                 // Setting the timezone to the current users timezone
                 if (isset($profile->timezone)) {
                     $app->setTimeZone($profile->timezone);
                 }
                 // Setting the language to the current users language
                 if (isset($profile->language)) {
                     $app->language = $profile->language;
                 }
             }
         } catch (\Exception $e) {
             // Do nothing
         }
     });
     /*******************************
        /* Event Handlers
        /*******************************/
     $app->on('app.form.submission.received', ['app\\events\\handlers\\SubmissionEventHandler', 'onSubmissionReceived']);
     $app->on('app.form.submission.accepted', ['app\\events\\handlers\\SubmissionEventHandler', 'onSubmissionAccepted']);
     $app->on('app.form.submission.rejected', ['app\\events\\handlers\\SubmissionEventHandler', 'onSubmissionRejected']);
 }
Beispiel #6
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if (!$app instanceof \yii\web\Application) {
         return;
     }
     if (!$app->has('backend')) {
         $app->set('backend', static::className());
     }
     if ($app->get('backend') instanceof Component) {
         $app->on(\yii\web\Application::EVENT_BEFORE_ACTION, [self::className(), 'detectBackend']);
     }
 }
Beispiel #7
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     mb_internal_encoding($this->internalEncoding);
     if ($app instanceof \yii\web\Application === true) {
         $app->on(Application::EVENT_BEFORE_ACTION, function () use($app) {
             $controller = Yii::$app->requestedAction->controller;
             $decorators = ContentDecorator::getAllDecorators();
             foreach ($decorators as $decorator) {
                 $decorator->subscribe($app, $controller);
             }
         });
     }
 }
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     $app->on(Application::EVENT_BEFORE_REQUEST, function () {
         $this->retrieveInfo();
         $this->retrieveLanguageFromGeo();
     });
     $app->on(Application::EVENT_BEFORE_ACTION, function () {
         $this->retrieveCookieLanguage();
     });
     $this->registerTranslations();
 }