本文整理汇总了PHP中yii\base\Application::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::get方法的具体用法?PHP Application::get怎么用?PHP Application::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Application
的用法示例。
在下文中一共展示了Application::get方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bootstrap
/**
* 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__);
}
示例2: bootstrap
/**
* 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'];
}
}
}
示例3: bootstrap
/**
* 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']);
}
}
示例4: bootstrap
/**
* Bootstrap method to be called during application bootstrap stage.
* @param Application $app the application currently running
*/
public function bootstrap($app)
{
$app->i18n->translations['admin/export'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@yz/admin/export/common/messages', 'sourceLanguage' => 'en-US'];
if ($app instanceof \yii\console\Application) {
if ($app->has('schedule')) {
/** @var omnilight\scheduling\Schedule $schedule */
$schedule = $app->get('schedule');
// Place all your shedule command below
$schedule->command('admin-export/export/process');
}
}
}
示例5: registerSearchableTypes
/**
* Registers searchable types.
*
* @param Application $app
*/
public function registerSearchableTypes($app)
{
/** @var \im\search\components\SearchManager $searchManager */
$searchManager = $app->get('searchManager');
$searchManager->registerSearchableType(['class' => 'im\\search\\components\\service\\db\\IndexedSearchableType', 'type' => 'product', 'modelClass' => 'im\\catalog\\models\\Product']);
// $searchManager->registerSearchableType([
// 'class' => 'im\search\components\service\db\SearchableType',
// 'modelClass' => 'im\catalog\models\Product',
// 'type' => 'product',
// 'searchServiceId' => 'db'
// ]);
}
示例6: bootstrap
/**
* 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();
});
}
}
示例7: getInstance
/**
* Get workbench compoment
* @param yii\base\Application $app
* @return \johnitvn\workbench\Workbench|null return Workbench or null if working directory is not exist
*/
public static function getInstance(Application $app)
{
if (!$app->has("workbench")) {
$workbench = new Workbench();
} else {
$workbench = $app->get("workbench");
}
if ($workbench->workingDir === null) {
$workbench->workingDir = dirname(dirname(dirname(__DIR__))) . '/workbench';
}
// If workbench workspace not exist. return null
if (!file_exists($workbench->workingDir)) {
return null;
}
return $workbench;
}
示例8: bootstrap
/**
*
* @param \yii\base\Application $app
*/
public function bootstrap($app)
{
$dbs = ArrayHelper::getValue($app->params, 'mdm.logger.attach', 'db');
if (!empty($dbs)) {
foreach ((array) $dbs as $db) {
if (is_string($db) && strpos($db, '\\') === false) {
$db = $app->get($db, false);
} elseif (!$db instanceof Connection) {
$db = Yii::createObject($db);
}
if ($db !== null) {
$db->on(Connection::EVENT_BEGIN_TRANSACTION, ['mdm\\logger\\RecordLogger', 'begin']);
$db->on(Connection::EVENT_COMMIT_TRANSACTION, ['mdm\\logger\\RecordLogger', 'commit']);
$db->on(Connection::EVENT_ROLLBACK_TRANSACTION, ['mdm\\logger\\RecordLogger', 'rollback']);
}
}
}
}
示例9: registerLayouts
/**
* @param Application $app
*/
public function registerLayouts($app)
{
$layoutManager = $app->get('layoutManager');
$layoutManager->registerLayout(Yii::createObject(['class' => 'im\\cms\\components\\Layout', 'id' => 'main', 'name' => 'Main layout', 'default' => true, 'availableWidgetAreas' => [['class' => 'im\\cms\\components\\WidgetAreaDescriptor', 'code' => 'sidebar', 'title' => 'Sidebar'], ['class' => 'im\\cms\\components\\WidgetAreaDescriptor', 'code' => 'footer', 'title' => 'Footer']]]));
$layoutManager->registerLayout(Yii::createObject(['class' => 'im\\cms\\components\\Layout', 'id' => 'home', 'name' => 'Home', 'availableWidgetAreas' => [['class' => 'im\\cms\\components\\WidgetAreaDescriptor', 'code' => 'footer', 'title' => 'Footer']]]));
}
示例10: registerSearchService
/**
* Registers search service.
*
* @param \yii\base\Application $app
*/
public function registerSearchService($app)
{
/** @var \im\search\components\SearchManager $searchManager */
$searchManager = $app->get('searchManager');
$searchManager->registerSearchService('db', ['class' => 'im\\search\\components\\service\\db\\SearchService', 'name' => 'Database']);
}
示例11: bootstrap
/**
* Bootstrap method to be called during application bootstrap stage.
* @param Application $app the application currently running
*/
public function bootstrap($app)
{
/** @var Module $module */
if (($module = $app->getModule('admin')) == null || !$module instanceof Module) {
return;
}
$class = 'nullref\\admin\\models\\Admin';
$definition = $module->adminModel;
if ($module->enableRbac) {
$module->setComponents(['authManager' => $module->authManager, 'roleContainer' => $module->roleContainer]);
}
Yii::$container->set($class, $definition);
$className = is_array($definition) ? $definition['class'] : $definition;
Event::on(AdminQuery::className(), AdminQuery::EVENT_INIT, function (Event $e) use($class, $className) {
if ($e->sender->modelClass == $class) {
$e->sender->modelClass = $className;
}
});
/** I18n */
if (!isset($app->get('i18n')->translations['admin*'])) {
$app->i18n->translations['admin*'] = ['class' => PhpMessageSource::className(), 'basePath' => '@nullref/admin/messages'];
}
if ($app instanceof WebApplication) {
Yii::$app->setComponents(['admin' => ['class' => 'nullref\\admin\\components\\User', 'identityClass' => $className, 'loginUrl' => ['admin/login']]]);
$app->urlManager->addRules(['/admin/login' => '/admin/main/login']);
$app->urlManager->addRules(['/admin/logout' => '/admin/main/logout']);
Event::on(BaseModule::className(), BaseModule::EVENT_BEFORE_ACTION, function () use($module) {
if (Yii::$app->controller instanceof IAdminController) {
/** @var Controller $controller */
$controller = Yii::$app->controller;
$controller->layout = $module->layout;
if ($controller->module != $module) {
$controller->module->setLayoutPath($module->getLayoutPath());
}
if (!isset($controller->behaviors()['access'])) {
$controller->attachBehavior('access', AccessControl::className());
}
Yii::$app->errorHandler->errorAction = $module->errorAction;
}
});
} elseif ($app instanceof ConsoleApplication) {
if ($module !== null) {
/** @var Module $module */
if ($module->enableRbac) {
$module->controllerMap['rbac'] = ['class' => 'nullref\\admin\\console\\RbacController'];
}
}
}
Event::on(Module::className(), Module::EVENT_BEFORE_INIT, function (Event $event) use($app) {
$module = $event->sender;
/** @var Module $module */
if ($module->enableRbac) {
if ($app instanceof ConsoleApplication) {
$module->controllerMap['rbac'] = ['class' => 'nullref\\admin\\console\\RbacController'];
}
$module->setComponents(['authManager' => $module->authManager, 'roleContainer' => $module->roleContainer]);
}
});
if (YII_ENV_DEV && class_exists('yii\\gii\\Module')) {
Event::on(Gii::className(), Gii::EVENT_BEFORE_ACTION, function (Event $event) {
/** @var Gii $gii */
$gii = $event->sender;
$gii->generators['crud'] = ['class' => 'yii\\gii\\generators\\crud\\Generator', 'templates' => ['admin-crud' => '@nullref/admin/generators/crud/admin']];
$gii->generators['stuff'] = ['class' => 'nullref\\admin\\generators\\stuff\\Generator', 'templates' => ['default' => '@nullref/admin/generators/stuff/default']];
});
}
}
示例12: registerSearchService
/**
* Registers search service.
*
* @param Application $app
*/
public function registerSearchService($app)
{
/** @var \im\search\components\SearchManager $searchManager */
$searchManager = $app->get('searchManager');
$searchManager->registerSearchService('elastic', ['class' => 'im\\elasticsearch\\components\\SearchService', 'name' => 'ElasticSearch']);
}
示例13: registerWidgets
/**
* Registers widgets.
*
* @param Application $app
*/
public function registerWidgets($app)
{
$layoutManager = $app->get('layoutManager');
$layoutManager->registerWidget('im\\cms\\models\\widgets\\ContentWidget');
$layoutManager->registerWidget('im\\cms\\models\\widgets\\BannerWidget');
}