mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
Fixes #2775: Added yii\base\Application::bootstrap to support running bootstrap classes when starting an application
This commit is contained in:
@ -114,9 +114,11 @@ There are several classes provided by framework:
|
|||||||
- FileHelper
|
- FileHelper
|
||||||
- Html
|
- Html
|
||||||
- HtmlPurifier
|
- HtmlPurifier
|
||||||
|
- Image
|
||||||
- Inflector
|
- Inflector
|
||||||
- Json
|
- Json
|
||||||
- Markdown
|
- Markdown
|
||||||
- Security
|
- Security
|
||||||
- StringHelper
|
- StringHelper
|
||||||
|
- Url
|
||||||
- VarDumper
|
- VarDumper
|
||||||
|
|||||||
@ -19,7 +19,7 @@ Creating URLs
|
|||||||
-------------
|
-------------
|
||||||
|
|
||||||
The most important rule for creating URLs in your site is to always do so using the URL manager. The URL manager is a built-in application component named `urlManager`. This component is accessible from both web and console applications via
|
The most important rule for creating URLs in your site is to always do so using the URL manager. The URL manager is a built-in application component named `urlManager`. This component is accessible from both web and console applications via
|
||||||
`\Yii::$app->urlManager`. The component makes availabe the two following URL creation methods:
|
`\Yii::$app->urlManager`. The component makes available the two following URL creation methods:
|
||||||
|
|
||||||
- `createUrl($params)`
|
- `createUrl($params)`
|
||||||
- `createAbsoluteUrl($params, $schema = null)`
|
- `createAbsoluteUrl($params, $schema = null)`
|
||||||
|
|||||||
@ -148,6 +148,7 @@ Yii Framework 2 Change Log
|
|||||||
- Enh #2729: Added `FilterValidator::skipOnArray` so that filters like `trim` will not fail for array inputs (qiangxue)
|
- Enh #2729: Added `FilterValidator::skipOnArray` so that filters like `trim` will not fail for array inputs (qiangxue)
|
||||||
- Enh #2735: Added support for `DateTimeInterface` in `Formatter` (ivokund)
|
- Enh #2735: Added support for `DateTimeInterface` in `Formatter` (ivokund)
|
||||||
- Enh #2756: Added support for injecting custom `isEmpty` check for all validators (qiangxue)
|
- Enh #2756: Added support for injecting custom `isEmpty` check for all validators (qiangxue)
|
||||||
|
- Enh #2775: Added `yii\base\Application::bootstrap` to support running bootstrap classes when starting an application (qiangxue)
|
||||||
- Enh: Added support for using arrays as option values for console commands (qiangxue)
|
- Enh: Added support for using arrays as option values for console commands (qiangxue)
|
||||||
- Enh: Added `favicon.ico` and `robots.txt` to default application templates (samdark)
|
- Enh: Added `favicon.ico` and `robots.txt` to default application templates (samdark)
|
||||||
- Enh: Added `Widget::autoIdPrefix` to support prefixing automatically generated widget IDs (qiangxue)
|
- Enh: Added `Widget::autoIdPrefix` to support prefixing automatically generated widget IDs (qiangxue)
|
||||||
@ -243,6 +244,7 @@ Yii Framework 2 Change Log
|
|||||||
- Renamed `yii\web\User::returnUrlVar` to `returnUrlParam`
|
- Renamed `yii\web\User::returnUrlVar` to `returnUrlParam`
|
||||||
- Chg: Added `View::viewFile` and removed `ViewEvent::viewFile` (qiangxue)
|
- Chg: Added `View::viewFile` and removed `ViewEvent::viewFile` (qiangxue)
|
||||||
- Chg: Changed `Controller::afterAction()`, `Module::afterAction()` and `ActionFilter::afterAction()` to pass `$result` by value instead of reference (qiangxue)
|
- Chg: Changed `Controller::afterAction()`, `Module::afterAction()` and `ActionFilter::afterAction()` to pass `$result` by value instead of reference (qiangxue)
|
||||||
|
- Chg: `yii\base\Extension::init()` is renamed to `bootstrap()` (qiangxue)
|
||||||
- New #66: [Auth client library](https://github.com/yiisoft/yii2-authclient) OpenId, OAuth1, OAuth2 clients (klimov-paul)
|
- New #66: [Auth client library](https://github.com/yiisoft/yii2-authclient) OpenId, OAuth1, OAuth2 clients (klimov-paul)
|
||||||
- New #706: Added `yii\widgets\Pjax` and enhanced `GridView` to work with `Pjax` to support AJAX-update (qiangxue)
|
- New #706: Added `yii\widgets\Pjax` and enhanced `GridView` to work with `Pjax` to support AJAX-update (qiangxue)
|
||||||
- New #1393: [Codeception testing framework integration](https://github.com/yiisoft/yii2-codeception) (Ragazzo)
|
- New #1393: [Codeception testing framework integration](https://github.com/yiisoft/yii2-codeception) (Ragazzo)
|
||||||
|
|||||||
@ -132,6 +132,11 @@ abstract class Application extends Module
|
|||||||
* ~~~
|
* ~~~
|
||||||
*/
|
*/
|
||||||
public $extensions = [];
|
public $extensions = [];
|
||||||
|
/**
|
||||||
|
* @var array list of bootstrap classes. A bootstrap class must have a public static method named
|
||||||
|
* `bootstrap()`. The method will be called during [[init()]] for every bootstrap class.
|
||||||
|
*/
|
||||||
|
public $bootstrap = [];
|
||||||
/**
|
/**
|
||||||
* @var \Exception the exception that is being handled currently. When this is not null,
|
* @var \Exception the exception that is being handled currently. When this is not null,
|
||||||
* it means the application is handling some exception and extra care should be taken.
|
* it means the application is handling some exception and extra care should be taken.
|
||||||
@ -209,6 +214,10 @@ abstract class Application extends Module
|
|||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->initExtensions($this->extensions);
|
$this->initExtensions($this->extensions);
|
||||||
|
foreach ($this->bootstrap as $class) {
|
||||||
|
/** @var Extension $class */
|
||||||
|
$class::bootstrap();
|
||||||
|
}
|
||||||
parent::init();
|
parent::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +237,7 @@ abstract class Application extends Module
|
|||||||
if (isset($extension['bootstrap'])) {
|
if (isset($extension['bootstrap'])) {
|
||||||
/** @var Extension $class */
|
/** @var Extension $class */
|
||||||
$class = $extension['bootstrap'];
|
$class = $extension['bootstrap'];
|
||||||
$class::init();
|
$class::bootstrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace yii\base;
|
|||||||
* Extension is the base class that may be extended by individual extensions.
|
* Extension is the base class that may be extended by individual extensions.
|
||||||
*
|
*
|
||||||
* Extension serves as the bootstrap class for extensions. When an extension
|
* Extension serves as the bootstrap class for extensions. When an extension
|
||||||
* is installed via composer, the [[init()]] method of its Extension class (if any)
|
* is installed via composer, the [[bootstrap()]] method of its Extension class (if any)
|
||||||
* will be invoked during the application initialization stage.
|
* will be invoked during the application initialization stage.
|
||||||
*
|
*
|
||||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
@ -21,9 +21,9 @@ class Extension
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Initializes the extension.
|
* Initializes the extension.
|
||||||
* This method is invoked at the end of [[Application::init()]].
|
* This method is invoked at the beginning of [[Application::init()]].
|
||||||
*/
|
*/
|
||||||
public static function init()
|
public static function bootstrap()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user