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
ea75177a
Commit
ea75177a
authored
Apr 10, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored app bootstrap logic.
parent
567a2bf2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
28 additions
and
13 deletions
+28
-13
main.php
apps/advanced/backend/config/main.php
+1
-0
main.php
apps/advanced/console/config/main.php
+1
-0
main.php
apps/advanced/frontend/config/main.php
+1
-0
console.php
apps/basic/config/console.php
+1
-0
web.php
apps/basic/config/web.php
+1
-0
Module.php
extensions/debug/Module.php
+7
-1
Application.php
framework/base/Application.php
+16
-12
No files found.
apps/advanced/backend/config/main.php
View file @
ea75177a
...
...
@@ -10,6 +10,7 @@ return [
'id'
=>
'app-backend'
,
'basePath'
=>
dirname
(
__DIR__
),
'controllerNamespace'
=>
'backend\controllers'
,
'bootstrap'
=>
[
'log'
],
'modules'
=>
[],
'components'
=>
[
'user'
=>
[
...
...
apps/advanced/console/config/main.php
View file @
ea75177a
...
...
@@ -9,6 +9,7 @@ $params = array_merge(
return
[
'id'
=>
'app-console'
,
'basePath'
=>
dirname
(
__DIR__
),
'bootstrap'
=>
[
'log'
],
'controllerNamespace'
=>
'console\controllers'
,
'modules'
=>
[],
'components'
=>
[
...
...
apps/advanced/frontend/config/main.php
View file @
ea75177a
...
...
@@ -9,6 +9,7 @@ $params = array_merge(
return
[
'id'
=>
'app-frontend'
,
'basePath'
=>
dirname
(
__DIR__
),
'bootstrap'
=>
[
'log'
],
'controllerNamespace'
=>
'frontend\controllers'
,
'components'
=>
[
'user'
=>
[
...
...
apps/basic/config/console.php
View file @
ea75177a
...
...
@@ -8,6 +8,7 @@ $db = require(__DIR__ . '/db.php');
return
[
'id'
=>
'basic-console'
,
'basePath'
=>
dirname
(
__DIR__
),
'bootstrap'
=>
[
'log'
],
'controllerNamespace'
=>
'app\commands'
,
'extensions'
=>
require
(
__DIR__
.
'/../vendor/yiisoft/extensions.php'
),
'components'
=>
[
...
...
apps/basic/config/web.php
View file @
ea75177a
...
...
@@ -6,6 +6,7 @@ $db = require(__DIR__ . '/db.php');
$config
=
[
'id'
=>
'basic'
,
'basePath'
=>
dirname
(
__DIR__
),
'bootstrap'
=>
[
'log'
],
'extensions'
=>
require
(
__DIR__
.
'/../vendor/yiisoft/extensions.php'
),
'components'
=>
[
'cache'
=>
[
...
...
extensions/debug/Module.php
View file @
ea75177a
...
...
@@ -71,9 +71,15 @@ class Module extends \yii\base\Module implements BootstrapInterface
public
function
init
()
{
parent
::
init
();
$this
->
dataPath
=
Yii
::
getAlias
(
$this
->
dataPath
);
$this
->
initPanels
();
}
/**
* Initializes panels.
*/
protected
function
initPanels
()
{
// merge custom panels and core panels so that they are ordered mainly by custom panels
if
(
empty
(
$this
->
panels
))
{
$this
->
panels
=
$this
->
corePanels
();
...
...
framework/base/Application.php
View file @
ea75177a
...
...
@@ -137,29 +137,32 @@ abstract class Application extends Module
* [
* 'name' => 'extension name',
* 'version' => 'version number',
* 'bootstrap' => 'BootstrapClassName',
* 'bootstrap' => 'BootstrapClassName',
// optional, may also be a configuration array
* 'alias' => [
* '@alias1' => 'to/path1',
* '@alias2' => 'to/path2',
* ],
* ]
* ~~~
*
* The "bootstrap" class listed above will be instantiated during the application
* [[bootstrap()|bootstrapping process]]. If the class implements [[BootstrapInterface]],
* its [[BootstrapInterface::bootstrap()|bootstrap()]] method will be also be called.
*/
public
$extensions
=
[];
/**
* @var array list of bootstrap components that should be run right after
* the application is configured.
* @var array list of components that should be run during the application [[bootstrap()|bootstrapping process]].
*
* Each
bootstrap
component may be specified in one of the following formats:
* Each component may be specified in one of the following formats:
*
* - an application component ID as specified via [[components]].
* - a module ID as specified via [[modules]].
* - a class name.
* - a configuration array.
*
*
Note that a bootstrap component must implement [[BootstrapInterface]], or an exception will be thrown.
*
The [[BootstrapInterface::bootstrap()]] method of each bootstrap component will be calle
d
* w
hen the component is instantiated and run in in [[bootstrap()]]
.
*
During the bootstrapping process, each component will be instantiated. If the component class
*
implements [[BootstrapInterface]], its [[BootstrapInterface::bootstrap()|bootstrap()]] metho
d
* w
ill be also be called
.
*/
public
$bootstrap
=
[];
/**
...
...
@@ -245,7 +248,6 @@ abstract class Application extends Module
public
function
init
()
{
$this
->
state
=
self
::
STATE_INIT
;
$this
->
get
(
'log'
);
$this
->
bootstrap
();
}
...
...
@@ -253,7 +255,6 @@ abstract class Application extends Module
* Initializes extensions and executes bootstrap components.
* This method is called by [[init()]] after the application has been fully configured.
* If you override this method, make sure you also call the parent implementation.
* @throws InvalidConfigException if a bootstrap component does not implement BootstrapInterface
*/
protected
function
bootstrap
()
{
...
...
@@ -266,10 +267,10 @@ abstract class Application extends Module
if
(
isset
(
$extension
[
'bootstrap'
]))
{
$component
=
Yii
::
createObject
(
$extension
[
'bootstrap'
]);
if
(
$component
instanceof
BootstrapInterface
)
{
Yii
::
trace
(
"Bootstrap with "
.
get_class
(
$component
)
.
'::bootstrap()'
,
__METHOD__
);
$component
->
bootstrap
(
$this
);
}
else
{
$class
=
is_array
(
$extension
[
'bootstrap'
])
?
$extension
[
'bootstrap'
][
'class'
]
:
$extension
[
'bootstrap'
];
throw
new
InvalidConfigException
(
"
$class
must implement
\\
yii
\\
base
\\
BootstrapInterface"
);
Yii
::
trace
(
"Bootstrap with "
.
get_class
(
$component
),
__METHOD__
);
}
}
}
...
...
@@ -280,6 +281,8 @@ abstract class Application extends Module
$component
=
$this
->
get
(
$class
);
}
elseif
(
$this
->
hasModule
(
$class
))
{
$component
=
$this
->
getModule
(
$class
);
}
elseif
(
strpos
(
$class
,
'\\'
)
===
false
)
{
throw
new
InvalidConfigException
(
"Unknown bootstrap component ID:
$class
"
);
}
}
if
(
!
isset
(
$component
))
{
...
...
@@ -287,9 +290,10 @@ abstract class Application extends Module
}
if
(
$component
instanceof
BootstrapInterface
)
{
Yii
::
trace
(
"Bootstrap with "
.
get_class
(
$component
)
.
'::bootstrap()'
,
__METHOD__
);
$component
->
bootstrap
(
$this
);
}
else
{
throw
new
InvalidConfigException
((
is_array
(
$class
)
?
$class
[
'class'
]
:
$class
)
.
" must implement
\\
yii
\\
base
\\
BootstrapInterface"
);
Yii
::
trace
(
"Bootstrap with "
.
get_class
(
$component
),
__METHOD__
);
}
}
}
...
...
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