For more details and usage information on Application, see the guide article on applications.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends Module
Example #1
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     \Yii::setAlias('@cornernote/dashboard', __DIR__);
     if ($app->has('i18n')) {
         $app->i18n->translations['dashboard'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'sourceLanguage' => 'en', 'basePath' => '@cornernote/dashboard/messages'];
     }
 }
Example #2
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if (!isset($app->get('i18n')->translations['roxy*'])) {
         $app->get('i18n')->translations['roxy*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages', 'sourceLanguage' => 'en-US'];
     }
     Yii::setAlias('roxymce', __DIR__);
 }
Example #3
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);
                         }
                     }
                 }
             }
         }
     }
 }
Example #4
0
 /**
  * Rook gii templates
  *
  * @param Application $app the application currently running
  * @return array
  */
 public function registryGenerators($app)
 {
     $gii = $app->getModule('gii');
     if (!is_null($gii)) {
         $gii->generators = ArrayHelper::merge($gii->generators, ['model' => ['class' => \yii\gii\generators\model\Generator::class, 'templates' => ['skeleton' => '@skeleton/gii/generators/model/skeleton']], 'crud' => ['class' => \yii\gii\generators\crud\Generator::class, 'templates' => ['skeleton' => '@skeleton/gii/generators/crud/skeleton']], 'controller' => ['class' => \yii\gii\generators\controller\Generator::class, 'templates' => ['skeleton' => '@skeleton/gii/generators/controller/skeleton']], 'form' => ['class' => \yii\gii\generators\form\Generator::class, 'templates' => ['skeleton' => '@skeleton/gii/generators/form/skeleton']], 'module' => ['class' => \skeleton\gii\generators\module\Generator::class, 'templates' => ['skeleton' => '@skeleton/gii/generators/module/skeleton']], 'extension' => ['class' => \yii\gii\generators\extension\Generator::class, 'templates' => ['skeleton' => '@skeleton/gii/generators/extension/skeleton']]]);
     }
 }
 /**
  * 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}";
                     }
                 }
             }
         });
     }
 }
Example #6
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     /** @var Module $module */
     /** @var \yii\db\ActiveRecord $modelName */
     if ($app->hasModule('activeuser') && ($module = $app->getModule('activeuser')) instanceof Module) {
         $this->_modelMap = array_merge($this->_modelMap, $module->modelMap);
         foreach ($this->_modelMap as $name => $definition) {
             $class = "inblank\\activeuser\\models\\" . $name;
             Yii::$container->set($class, $definition);
             $modelName = is_array($definition) ? $definition['class'] : $definition;
             $module->modelMap[$name] = $modelName;
         }
         if ($app instanceof ConsoleApplication) {
             $app->controllerMap['activeuser'] = ['class' => 'inblank\\activeuser\\commands\\DefaultController'];
         } else {
             // init user
             Yii::$container->set('yii\\web\\User', ['loginUrl' => ['/activeuser/account/login'], 'identityClass' => self::di('User')]);
             $configUrlRule = ['prefix' => $module->urlPrefix, 'rules' => defined('IS_BACKEND') ? $module->urlRulesBackend : $module->urlRulesFrontend];
             if ($module->urlPrefix != 'activeuser') {
                 $configUrlRule['routePrefix'] = 'activeuser';
             }
             $app->urlManager->addRules([new GroupUrlRule($configUrlRule)], false);
             if (defined('IS_BACKEND')) {
                 // is backend, and controller have other namespace
                 $module->controllerNamespace = 'inblank\\activeuser\\controllers\\backend';
                 $module->frontendUrlManager = new yii\web\UrlManager(['baseUrl' => '/', 'enablePrettyUrl' => true, 'showScriptName' => false]);
                 $configUrlRule['rules'] = $module->urlRulesFrontend;
                 $module->frontendUrlManager->addRules([new GroupUrlRule($configUrlRule)], false);
             }
         }
         if (!isset($app->get('i18n')->translations['activeuser*'])) {
             $app->get('i18n')->translations['activeuser*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages'];
         }
     }
 }
Example #7
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     /**
      * @var Module $gii
      */
     \Yii::setAlias('@carono', '@vendor/carono/yii2-components');
     if ($app instanceof \yii\console\Application) {
         $commands = ['city' => 'CityController', 'currency' => 'CurrencyController', 'dumper' => 'DumperController', 'carono' => 'CaronoController'];
         foreach ($commands as $name => $command) {
             $name = file_exists(\Yii::getAlias("@app/commands/{$command}.php")) ? "carono" . ucfirst($name) : $name;
             $app->controllerMap[$name] = 'carono\\components\\commands\\' . $command;
         }
         if (!isset($app->controllerMap['giix'])) {
             if (($gii = $app->getModule('gii')) && isset($gii->generators["giiant-model"])) {
                 if (!isset($gii->generators["giiant-model"]["templates"])) {
                     if (is_array($gii->generators["giiant-model"])) {
                         $gii->generators["giiant-model"]["templates"] = [];
                     } else {
                         $gii->generators["giiant-model"] = ["class" => 'schmunk42\\giiant\\generators\\model\\Generator', "templates" => []];
                     }
                 }
                 $template = '@vendor/carono/yii2-components/templates/giiant-model';
                 $gii->generators["giiant-model"]["templates"]["caronoModel"] = $template;
                 $app->controllerMap['giix'] = 'carono\\components\\commands\\GiixController';
             }
         }
     }
 }
Example #8
0
 /**
  * @param \yii\base\Application $app
  * @throws ModuleBootstrapException
  * @throws ModuleUndefinedClassException
  */
 public function bootstrap($app)
 {
     $this->app = $app;
     $modules = array_diff(scandir($this->getModulesPath()), array('..', '.'));
     $modulesOrder = [];
     foreach ($modules as $module) {
         $className = 'modules\\' . $module . '\\Module';
         if (!class_exists($className)) {
             throw new ModuleUndefinedClassException('Can\'t load module ' . $className);
         }
         $interfaces = class_implements($className);
         // since PHP 5.5
         // if (!isset($interfaces[ModuleBootstrapInterface::class])) {
         if (!isset($interfaces['common\\interfaces\\ModuleBootstrapInterface'])) {
             throw new ModuleBootstrapException('Module ' . $className . ' must implement common\\ModuleBootstrapInterface interface');
         }
         if (!$app->hasModule($module)) {
             $app->setModule($module, $className);
         }
         // configure some properties
         $config = $this->getConfig($module);
         $this->configure($config);
         $modulesOrder[$className] = isset($config['bootOrder']) ? (int) $config['bootOrder'] : self::BOOT_ORDER_DEFAULT;
     }
     asort($modulesOrder);
     foreach ($modulesOrder as $className => $order) {
         $className::bootstrap($app);
     }
 }
Example #9
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['migen'])) {
             $app->getModule('gii')->generators['migen'] = 'sirroland\\migen\\gii\\Generator';
         }
     }
 }
 /**
  * Bootstrap method to be called during application bootstrap stage.
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['fixture-generator'])) {
             $app->getModule('gii')->generators['fixture-generator'] = ['class' => __NAMESPACE__ . '\\FixtureGenerator'];
         }
     }
 }
Example #11
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['ajaxcrud'])) {
             $app->getModule('gii')->generators['ajaxcrud'] = 'johnitvn\\ajaxcrud\\generators\\Generator';
         }
     }
 }
Example #12
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['hii-model'])) {
             $app->getModule('gii')->generators['hii-model'] = 'grzegorzpierzakowski\\hii\\model\\Generator';
         }
     }
 }
Example #13
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['doubleModel'])) {
             $app->getModule('gii')->generators['doubleModel'] = 'claudejanz\\mygii\\generators\\model\\Generator';
         }
     }
 }
Example #14
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if ($app instanceof \yii\console\Application) {
             $app->controllerMap['gii-batch'] = 'cornernote\\gii\\commands\\BatchController';
         }
     }
 }
 /**
  * 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);
         });
     }
 }
Example #16
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['fixturegii'])) {
             $app->getModule('gii')->generators['fixturegii'] = 'insolita\\fixturegii\\gii\\FixtureTemplateGenerator';
         }
     }
 }
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if ($app instanceof \yii\console\Application) {
             $app->controllerMap['giic'] = 'dmstr\\console\\controllers\\GiiController';
         }
     }
 }
Example #18
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['migrik'])) {
             $app->getModule('gii')->generators['migrik'] = 'insolita\\migrik\\gii\\Generator';
         }
     }
 }
Example #19
0
 /**
  * Add default url rules of this module to custom urlManager of application
  * @param \yii\base\Application $app
  */
 public function addUrlRules(\yii\base\Application $app)
 {
     if ($app instanceof \yii\web\Application) {
         $app->getUrlManager()->addRules([['prefix' => $this->urlRulePrefix, 'class' => $this->urlRuleClass, 'controller' => [$this->id . '/user'], 'extraPatterns' => ['POST current' => 'current', 'POST extend' => 'extend'], 'pluralize' => false]]);
     } elseif ($app instanceof \yii\console\Application) {
         $app->controllerMap[$this->id] = ['class' => 'gbksoft\\modules\\tokens\\console\\AppController', 'module' => $this];
     }
 }
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app instanceof \yii\console\Application) {
         // add deferred module
         $app->setModule('deferred', new DeferredTasksModule('deferred', $app));
         // this will automatically add deferred controller to console app
         $app->controllerMap['deferred'] = ['class' => DeferredController::className()];
     }
 }
Example #21
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['singletonn-gii'])) {
             $app->getModule('gii')->generators['singletonn-gii-model'] = 'singletonn\\gii\\model\\Generator';
             $app->getModule('gii')->generators['singletonn-gii-crud'] = 'singletonn\\gii\\crud\\Generator';
         }
     }
 }
Example #22
0
 /**
  *
  * @param \yii\base\Application $app
  * @param array                 $config
  */
 protected function initialize($app, $config)
 {
     if ($app instanceof \yii\web\Application) {
         $app->attachBehaviors([PriceHook::className() => PriceHook::className(), StockHook::className() => StockHook::className()]);
         if (ArrayHelper::getValue($config, 'attach_user_behavior', true)) {
             $this->attachUserProperty($app->getUser());
         }
     }
 }
Example #23
0
 /**
  * Initialize application before process request
  * @param \yii\base\Application $app
  */
 public function bootstrap($app)
 {
     $definitions = (require __DIR__ . '/definitions.php');
     foreach ($definitions as $name => $definition) {
         Yii::$container->set($name, $definition);
     }
     $hooks = (require __DIR__ . '/hooks.php');
     $app->attachBehaviors(array_combine($hooks, $hooks));
 }
Example #24
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['enhanced-gii'])) {
             $app->getModule('gii')->generators['enhanced-gii-model'] = 'mootensai\\enhancedgii\\model\\Generator';
             $app->getModule('gii')->generators['enhanced-gii-crud'] = 'mootensai\\enhancedgii\\crud\\Generator';
         }
     }
 }
Example #25
0
 /**
  * @param \yii\base\Application $app
  */
 public function registerRules($app)
 {
     $app->getUrlManager()->addRules(['<language:\\w+\\-\\w+>/cp/' . $this->id => 'cp/' . $this->id, '<language:\\w+\\-\\w+>/cp/' . $this->id . '/<controller:\\w+>' => 'cp/' . $this->id . '/<controller>', '<language:\\w+\\-\\w+>/cp/' . $this->id . '/<controller:\\w+>/<action:\\w+>' => 'cp/' . $this->id . '/<controller>/<action>'], false);
     /**
      * magic/default/download.html?id=1
      * ru-RU/magic/default/download.html?id=1
      */
     $app->getUrlManager()->addRules([$this->id . '/<controller:\\w+>/<action:\\w+>' => $this->id . '/<controller>/<action>', '<language:\\w+\\-\\w+>/' . $this->id . '/<controller:\\w+>/<action:\\w+>' => $this->id . '/<controller>/<action>'], false);
 }
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     /**@var Module $gii */
     if ($app->hasModule('gii') && ($gii = $app->getModule('gii'))) {
         if (!isset($gii->generators['migration'])) {
             $gii->generators['migration'] = 'navatech\\migration\\gii\\Generator';
         }
     }
 }
Example #27
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     Yii::setAlias("@ajaxcrud", __DIR__);
     Yii::setAlias("@johnitvn/ajaxcrud", __DIR__);
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['ajaxcrud'])) {
             $app->getModule('gii')->generators['ajaxcrud'] = 'johnitvn\\ajaxcrud\\generators\\Generator';
         }
     }
 }
Example #28
0
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         $app->getModule('gii')->generators['giiant-model'] = 'pafnow\\giiant\\model\\Generator';
         $app->getModule('gii')->generators['giiant-crud'] = 'pafnow\\giiant\\crud\\Generator';
         if ($app instanceof \yii\console\Application) {
             $app->controllerMap['giiant-batch'] = 'pafnow\\giiant\\commands\\BatchController';
         }
     }
 }
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     // register migration
     $app->params['yii.migrations'][] = '@vendor/dmstr/yii2-pages-module/migrations';
     // register module
     if (!\Yii::$app->hasModule('pages')) {
         $app->setModule('pages', ['class' => 'dmstr\\modules\\pages\\Module']);
     }
     // provide default page url rule
     $app->urlManager->addRules(['<parentLeave:[a-zA-Z0-9_\\-\\.]*>/<pageName:[a-zA-Z0-9_\\-\\.]*>-<id:[0-9]*>' => 'pages/default/page', '<pageName:[a-zA-Z0-9_\\-\\.]*>-<id:[0-9]*>' => 'pages/default/page'], true);
 }
 /**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app->hasModule('gii')) {
         if (!isset($app->getModule('gii')->generators['giiant-crud']['templates']['twig'])) {
             $app->getModule('gii')->generators['giiant-crud'] = ['class' => 'schmunk42\\giiant\\crud\\Generator', 'templates' => ['twig' => '@vendor/esquire900/yii2-giiant-twig/crud']];
         }
         if ($app instanceof \yii\console\Application) {
             $app->controllerMap['giiant-twig'] = 'esquire900\\giianttwig\\commands\\ConvertController';
         }
     }
 }