/** @inheritdoc */ public function init() { $this->finder = \Yii::$container->get(Finder::className()); $this->mailer = \Yii::$container->get(Mailer::className()); $this->module = \Yii::$app->getModule('users'); parent::init(); }
/** @inheritdoc */ public function bootstrap($app) { /** @var $module Module */ if ($app->hasModule('users') && ($module = $app->getModule('users')) instanceof Module) { $this->_modelMap = array_merge($this->_modelMap, $module->modelMap); foreach ($this->_modelMap as $name => $definition) { $class = "mii\\modules\\users\\models\\" . $name; \Yii::$container->set($class, $definition); $modelName = is_array($definition) ? $definition['class'] : $definition; $module->modelMap[$name] = $modelName; if (in_array($name, ['User', 'Profile', 'Token', 'Account'])) { \Yii::$container->set($name . 'Query', function () use($modelName) { return $modelName::find(); }); } } \Yii::$container->setSingleton(Finder::className(), ['userQuery' => \Yii::$container->get('UserQuery'), 'profileQuery' => \Yii::$container->get('ProfileQuery'), 'tokenQuery' => \Yii::$container->get('TokenQuery'), 'accountQuery' => \Yii::$container->get('AccountQuery')]); if ($app instanceof ConsoleApplication) { $module->controllerNamespace = 'mii\\modules\\users\\commands'; $app->get('i18n')->translations['users*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages']; } else { try { $app->user->enableAutoLogin = true; $app->user->loginUrl = ['/users/security/login']; $app->user->identityClass = $module->modelMap['User']; } catch (InvalidConfigException $e) { $app->set('user', ['class' => User::className(), 'enableAutoLogin' => true, 'loginUrl' => ['/users/security/login'], 'identityClass' => $module->modelMap['User']]); } $configUrlRule = ['prefix' => $module->urlPrefix, 'rules' => $module->urlRules]; if ($module->urlPrefix != 'users') { $configUrlRule['routePrefix'] = 'users'; } $app->get('urlManager')->rules[] = new GroupUrlRule($configUrlRule); $app->get('urlManager')->addRules(['PUT,PATCH /' . $this->id . '/apis/<id>' => $this->id . '/api/update', 'DELETE /' . $this->id . '/apis/<id>' => $this->id . '/api/delete', 'GET,HEAD /' . $this->id . '/apis/<id>' => $this->id . '/api/view', 'POST /' . $this->id . '/apis' => $this->id . '/api/create', 'GET,HEAD /' . $this->id . '/apis' => $this->id . '/api/index', 'OPTIONS /' . $this->id . '/apis/<id>' => $this->id . '/api/options', 'OPTIONS /' . $this->id . '/apis' => $this->id . '/api/options'], false); if (!$app->has('authClientCollection')) { $app->set('authClientCollection', ['class' => Collection::className()]); } } $app->get('i18n')->translations['users*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages']; $defaults = ['welcomeSubject' => \Yii::t('users', 'Welcome to {0}', \Yii::$app->name), 'confirmationSubject' => \Yii::t('users', 'Confirm account on {0}', \Yii::$app->name), 'reconfirmationSubject' => \Yii::t('users', 'Confirm email change on {0}', \Yii::$app->name), 'recoverySubject' => \Yii::t('users', 'Complete password reset on {0}', \Yii::$app->name)]; \Yii::$container->set('mii\\modules\\users\\Mailer', array_merge($defaults, $module->mailer)); } }