mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 13:02:24 +08:00
Fixes #2775: Added yii\base\Application::bootstrap to support running bootstrap classes when starting an application
This commit is contained in:
@ -132,6 +132,11 @@ abstract class Application extends Module
|
||||
* ~~~
|
||||
*/
|
||||
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,
|
||||
* 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()
|
||||
{
|
||||
$this->initExtensions($this->extensions);
|
||||
foreach ($this->bootstrap as $class) {
|
||||
/** @var Extension $class */
|
||||
$class::bootstrap();
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
@ -228,7 +237,7 @@ abstract class Application extends Module
|
||||
if (isset($extension['bootstrap'])) {
|
||||
/** @var Extension $class */
|
||||
$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 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.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
@ -21,9 +21,9 @@ class 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