Commit 9c4d4715 by Qiang Xue

guide WIP [skip ci]

parent 8f7c4672
......@@ -317,7 +317,7 @@ as early as possible. The followings are the recommended practices:
* If you are the developer of an application, you can register dependencies in your
application's [entry script](structure-entry-scripts.md) or in a script that is included by the entry script.
* If you are the developer of a redistributable [extension](structure-extensions.md), you can register dependencies
in the bootstrap class of the extension.
in the bootstrapping class of the extension.
Summary <a name="summary"></a>
......
......@@ -117,46 +117,6 @@ Also, the `psr-4` autoloader is specified in the above, which maps the `myname\m
More details on this syntax can be found in the [Composer documentation](http://getcomposer.org/doc/04-schema.md#autoload).
### Bootstrap with extension
Sometimes, you may want your extension to execute some code during the bootstrap stage of an application.
For example, your extension may want to respond to the application's `beginRequest` event. You can ask the extension user
to explicitly attach your event handler in the extension to the application's event. A better way, however, is to
do all these automatically.
To achieve this goal, you can create a bootstrap class by implementing [[yii\base\BootstrapInterface]].
```php
namespace myname\mywidget;
use yii\base\BootstrapInterface;
use yii\base\Application;
class MyBootstrapClass implements BootstrapInterface
{
public function bootstrap($app)
{
$app->on(Application::EVENT_BEFORE_REQUEST, function () {
// do something here
});
}
}
```
You then list this bootstrap class in `composer.json` as follows,
```json
{
"extra": {
"bootstrap": "myname\\mywidget\\MyBootstrapClass"
}
}
```
When the extension is installed in an application, Yii will automatically hook up the bootstrap class
and call its `bootstrap()` while initializing the application for every request.
Working with database
---------------------
......
......@@ -136,7 +136,7 @@ implements [[yii\base\BootstrapInterface]], its [[yii\base\BootstrapInterface::b
will be also be called.
Another practical example is in the application configuration for the [Basic Application Template](start-installation.md),
where the `debug` and `gii` modules are configured as bootstrap components when the application is running
where the `debug` and `gii` modules are configured as bootstrapping components when the application is running
in development environment,
```php
......@@ -151,7 +151,7 @@ if (YII_ENV_DEV) {
```
> Note: Putting too many components in `bootstrap` will degrade the performance of your application because
for each request, the same set of components need to be run. So use bootstrap components judiciously.
for each request, the same set of components need to be run. So use bootstrapping components judiciously.
#### [[yii\web\Application::catchAll|catchAll]] <a name="catchAll"></a>
......@@ -412,7 +412,7 @@ In the special case when you want to maintain extensions manually, you may confi
As you can see, the property takes an array of extension specifications. Each extension is specified with an array
consisting of `name` and `version` elements. If an extension needs to run during the [bootstrap](runtime-bootstrapping.md)
process, a `bootstrap` element may be specified with a bootstrap class name or a [configuration](concept-configurations.md)
process, a `bootstrap` element may be specified with a bootstrapping class name or a [configuration](concept-configurations.md)
array. An extension may also define a few [aliases](concept-aliases.md).
......@@ -581,7 +581,7 @@ an application will undergo the following lifecycle:
* Register the [[yii\base\Application::errorHandler|error handler]].
* Configure application properties.
* [[yii\base\Application::init()|init()]] is called which further calls
[[yii\base\Application::bootstrap()|bootstrap()]] to run bootstrap components.
[[yii\base\Application::bootstrap()|bootstrap()]] to run bootstrapping components.
3. The entry script calls [[yii\base\Application::run()]] to run the application:
* Trigger the [[yii\base\Application::EVENT_BEFORE_REQUEST|EVENT_BEFORE_REQUEST]] event.
* Handle the request: resolve the request into a [route](runtime-routing.md) and the associated parameters;
......
......@@ -171,7 +171,7 @@ public function behaviors()
Response formats and languages often need to be determined much earlier during
the [application lifecycle](structure-applications.md#application-lifecycle). For this reason, ContentNegotiator
is designed in a way such that it can also be used as a [bootstrap component](structure-applications.md#bootstrap)
is designed in a way such that it can also be used as a [bootstrapping component](structure-applications.md#bootstrap)
besides filter. For example, you may configure it in the [application configuration](structure-applications.md#application-configurations)
like the following:
......
......@@ -21,7 +21,7 @@ like the following:
}
```
You may specify a bootstrap class in the `extra` section. The `init()` method of the class will be executed each time
You may specify a bootstrapping class in the `extra` section. The `init()` method of the class will be executed each time
the Yii 2 application is responding to a request. For example,
```json
......
......@@ -298,7 +298,7 @@ abstract class Application extends Module
} elseif ($this->hasModule($class)) {
$component = $this->getModule($class);
} elseif (strpos($class, '\\') === false) {
throw new InvalidConfigException("Unknown bootstrap component ID: $class");
throw new InvalidConfigException("Unknown bootstrapping component ID: $class");
}
}
if (!isset($component)) {
......
......@@ -12,10 +12,10 @@ namespace yii\base;
*
* The main method [[bootstrap()]] will be invoked by an application at the beginning of its `init()` method.
*
* Bootstrap classes can be registered in two approaches.
* Bootstrapping classes can be registered in two approaches.
*
* The first approach is mainly used by extensions and is managed by the Composer installation process.
* You mainly need to list the bootstrap class of your extension in the `composer.json` file like following,
* You mainly need to list the bootstrapping class of your extension in the `composer.json` file like following,
*
* ```json
* {
......@@ -45,7 +45,7 @@ namespace yii\base;
* ];
* ```
*
* As you can see, you can register a bootstrap class in terms of either a class name or a configuration class.
* As you can see, you can register a bootstrapping class in terms of either a class name or a configuration class.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
......
......@@ -27,9 +27,9 @@ use yii\web\UnsupportedMediaTypeHttpException;
* language negotiation based on the value of the GET parameter [[languageParam]] and the `Accept-Language` HTTP header.
* If a match is found, the [[\yii\base\Application::language]] property will be set as the chosen language.
*
* You may use ContentNegotiator as a bootstrap component as well as an action filter.
* You may use ContentNegotiator as a bootstrapping component as well as an action filter.
*
* The following code shows how you can use ContentNegotiator as a bootstrap component. Note that in this case,
* The following code shows how you can use ContentNegotiator as a bootstrapping component. Note that in this case,
* the content negotiation applies to the whole application.
*
* ```php
......
......@@ -73,7 +73,7 @@ class ErrorHandler extends \yii\base\ErrorHandler
$response = new Response();
}
$useErrorView = $response->format === \yii\web\Response::FORMAT_HTML && (!YII_DEBUG || $exception instanceof UserException);
$useErrorView = $response->format === Response::FORMAT_HTML && (!YII_DEBUG || $exception instanceof UserException);
if ($useErrorView && $this->errorAction !== null) {
$result = Yii::$app->runAction($this->errorAction);
......@@ -82,7 +82,7 @@ class ErrorHandler extends \yii\base\ErrorHandler
} else {
$response->data = $result;
}
} elseif ($response->format === \yii\web\Response::FORMAT_HTML) {
} elseif ($response->format === Response::FORMAT_HTML) {
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest' || YII_ENV_TEST) {
// AJAX request
$response->data = '<pre>' . $this->htmlEncode($this->convertExceptionToString($exception)) . '</pre>';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment