diff --git a/docs/guide/basics.md b/docs/guide/basics.md index f8fddfa..605a023 100644 --- a/docs/guide/basics.md +++ b/docs/guide/basics.md @@ -114,9 +114,11 @@ There are several classes provided by framework: - FileHelper - Html - HtmlPurifier +- Image - Inflector - Json - Markdown - Security - StringHelper +- Url - VarDumper diff --git a/docs/guide/url.md b/docs/guide/url.md index 5c1e990..a3058b5 100644 --- a/docs/guide/url.md +++ b/docs/guide/url.md @@ -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 -`\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)` - `createAbsoluteUrl($params, $schema = null)` diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 0081c90..7cb5f7c 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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 #2735: Added support for `DateTimeInterface` in `Formatter` (ivokund) - 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 `favicon.ico` and `robots.txt` to default application templates (samdark) - 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` - 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: `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 #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) diff --git a/framework/base/Application.php b/framework/base/Application.php index f44edef..52df984 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -133,6 +133,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(); } } } diff --git a/framework/base/Extension.php b/framework/base/Extension.php index 0cbc0cc..7f73d41 100644 --- a/framework/base/Extension.php +++ b/framework/base/Extension.php @@ -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() { } }