Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
9c4d4715
Commit
9c4d4715
authored
Jul 03, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
guide WIP [skip ci]
parent
8f7c4672
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
15 additions
and
55 deletions
+15
-55
concept-di-container.md
docs/guide/concept-di-container.md
+1
-1
extend-creating-extensions.md
docs/guide/extend-creating-extensions.md
+0
-40
structure-applications.md
docs/guide/structure-applications.md
+4
-4
structure-extensions.md
docs/guide/structure-extensions.md
+0
-0
structure-filters.md
docs/guide/structure-filters.md
+1
-1
README.md
extensions/composer/README.md
+1
-1
Application.php
framework/base/Application.php
+1
-1
BootstrapInterface.php
framework/base/BootstrapInterface.php
+3
-3
ContentNegotiator.php
framework/filters/ContentNegotiator.php
+2
-2
ErrorHandler.php
framework/web/ErrorHandler.php
+2
-2
No files found.
docs/guide/concept-di-container.md
View file @
9c4d4715
...
...
@@ -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 bootstrap
ping
class of the extension.
Summary <a name="summary"></a>
...
...
docs/guide/extend-creating-extensions.md
View file @
9c4d4715
...
...
@@ -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
---------------------
...
...
docs/guide/structure-applications.md
View file @
9c4d4715
...
...
@@ -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 bootstrap
ping
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 bootstrap
ping
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 bootstrap
ping
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 bootstrap
ping
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;
...
...
docs/guide/structure-extensions.md
View file @
9c4d4715
This diff is collapsed.
Click to expand it.
docs/guide/structure-filters.md
View file @
9c4d4715
...
...
@@ -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
[
bootstrap
ping
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:
...
...
extensions/composer/README.md
View file @
9c4d4715
...
...
@@ -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 bootstrap
ping
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
...
...
framework/base/Application.php
View file @
9c4d4715
...
...
@@ -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 bootstrap
ping
component ID:
$class
"
);
}
}
if
(
!
isset
(
$component
))
{
...
...
framework/base/BootstrapInterface.php
View file @
9c4d4715
...
...
@@ -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.
* Bootstrap
ping
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 bootstrap
ping
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 bootstrap
ping
class in terms of either a class name or a configuration class.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
...
...
framework/filters/ContentNegotiator.php
View file @
9c4d4715
...
...
@@ -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 bootstrap
ping
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 bootstrap
ping
component. Note that in this case,
* the content negotiation applies to the whole application.
*
* ```php
...
...
framework/web/ErrorHandler.php
View file @
9c4d4715
...
...
@@ -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>'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment