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 [
...
@@ -10,6 +10,7 @@ return [
'id'
=>
'app-backend'
,
'id'
=>
'app-backend'
,
'basePath'
=>
dirname
(
__DIR__
),
'basePath'
=>
dirname
(
__DIR__
),
'controllerNamespace'
=>
'backend\controllers'
,
'controllerNamespace'
=>
'backend\controllers'
,
'bootstrap'
=>
[
'log'
],
'modules'
=>
[],
'modules'
=>
[],
'components'
=>
[
'components'
=>
[
'user'
=>
[
'user'
=>
[
...
...
apps/advanced/console/config/main.php
View file @
ea75177a
...
@@ -9,6 +9,7 @@ $params = array_merge(
...
@@ -9,6 +9,7 @@ $params = array_merge(
return
[
return
[
'id'
=>
'app-console'
,
'id'
=>
'app-console'
,
'basePath'
=>
dirname
(
__DIR__
),
'basePath'
=>
dirname
(
__DIR__
),
'bootstrap'
=>
[
'log'
],
'controllerNamespace'
=>
'console\controllers'
,
'controllerNamespace'
=>
'console\controllers'
,
'modules'
=>
[],
'modules'
=>
[],
'components'
=>
[
'components'
=>
[
...
...
apps/advanced/frontend/config/main.php
View file @
ea75177a
...
@@ -9,6 +9,7 @@ $params = array_merge(
...
@@ -9,6 +9,7 @@ $params = array_merge(
return
[
return
[
'id'
=>
'app-frontend'
,
'id'
=>
'app-frontend'
,
'basePath'
=>
dirname
(
__DIR__
),
'basePath'
=>
dirname
(
__DIR__
),
'bootstrap'
=>
[
'log'
],
'controllerNamespace'
=>
'frontend\controllers'
,
'controllerNamespace'
=>
'frontend\controllers'
,
'components'
=>
[
'components'
=>
[
'user'
=>
[
'user'
=>
[
...
...
apps/basic/config/console.php
View file @
ea75177a
...
@@ -8,6 +8,7 @@ $db = require(__DIR__ . '/db.php');
...
@@ -8,6 +8,7 @@ $db = require(__DIR__ . '/db.php');
return
[
return
[
'id'
=>
'basic-console'
,
'id'
=>
'basic-console'
,
'basePath'
=>
dirname
(
__DIR__
),
'basePath'
=>
dirname
(
__DIR__
),
'bootstrap'
=>
[
'log'
],
'controllerNamespace'
=>
'app\commands'
,
'controllerNamespace'
=>
'app\commands'
,
'extensions'
=>
require
(
__DIR__
.
'/../vendor/yiisoft/extensions.php'
),
'extensions'
=>
require
(
__DIR__
.
'/../vendor/yiisoft/extensions.php'
),
'components'
=>
[
'components'
=>
[
...
...
apps/basic/config/web.php
View file @
ea75177a
...
@@ -6,6 +6,7 @@ $db = require(__DIR__ . '/db.php');
...
@@ -6,6 +6,7 @@ $db = require(__DIR__ . '/db.php');
$config
=
[
$config
=
[
'id'
=>
'basic'
,
'id'
=>
'basic'
,
'basePath'
=>
dirname
(
__DIR__
),
'basePath'
=>
dirname
(
__DIR__
),
'bootstrap'
=>
[
'log'
],
'extensions'
=>
require
(
__DIR__
.
'/../vendor/yiisoft/extensions.php'
),
'extensions'
=>
require
(
__DIR__
.
'/../vendor/yiisoft/extensions.php'
),
'components'
=>
[
'components'
=>
[
'cache'
=>
[
'cache'
=>
[
...
...
extensions/debug/Module.php
View file @
ea75177a
...
@@ -71,9 +71,15 @@ class Module extends \yii\base\Module implements BootstrapInterface
...
@@ -71,9 +71,15 @@ class Module extends \yii\base\Module implements BootstrapInterface
public
function
init
()
public
function
init
()
{
{
parent
::
init
();
parent
::
init
();
$this
->
dataPath
=
Yii
::
getAlias
(
$this
->
dataPath
);
$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
// merge custom panels and core panels so that they are ordered mainly by custom panels
if
(
empty
(
$this
->
panels
))
{
if
(
empty
(
$this
->
panels
))
{
$this
->
panels
=
$this
->
corePanels
();
$this
->
panels
=
$this
->
corePanels
();
...
...
framework/base/Application.php
View file @
ea75177a
...
@@ -137,29 +137,32 @@ abstract class Application extends Module
...
@@ -137,29 +137,32 @@ abstract class Application extends Module
* [
* [
* 'name' => 'extension name',
* 'name' => 'extension name',
* 'version' => 'version number',
* 'version' => 'version number',
* 'bootstrap' => 'BootstrapClassName',
* 'bootstrap' => 'BootstrapClassName',
// optional, may also be a configuration array
* 'alias' => [
* 'alias' => [
* '@alias1' => 'to/path1',
* '@alias1' => 'to/path1',
* '@alias2' => 'to/path2',
* '@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
=
[];
public
$extensions
=
[];
/**
/**
* @var array list of bootstrap components that should be run right after
* @var array list of components that should be run during the application [[bootstrap()|bootstrapping process]].
* the application is configured.
*
*
* 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]].
* - an application component ID as specified via [[components]].
* - a module ID as specified via [[modules]].
* - a module ID as specified via [[modules]].
* - a class name.
* - a class name.
* - a configuration array.
* - a configuration array.
*
*
*
Note that a bootstrap component must implement [[BootstrapInterface]], or an exception will be thrown.
*
During the bootstrapping process, each component will be instantiated. If the component class
*
The [[BootstrapInterface::bootstrap()]] method of each bootstrap component will be calle
d
*
implements [[BootstrapInterface]], its [[BootstrapInterface::bootstrap()|bootstrap()]] metho
d
* w
hen the component is instantiated and run in in [[bootstrap()]]
.
* w
ill be also be called
.
*/
*/
public
$bootstrap
=
[];
public
$bootstrap
=
[];
/**
/**
...
@@ -245,7 +248,6 @@ abstract class Application extends Module
...
@@ -245,7 +248,6 @@ abstract class Application extends Module
public
function
init
()
public
function
init
()
{
{
$this
->
state
=
self
::
STATE_INIT
;
$this
->
state
=
self
::
STATE_INIT
;
$this
->
get
(
'log'
);
$this
->
bootstrap
();
$this
->
bootstrap
();
}
}
...
@@ -253,7 +255,6 @@ abstract class Application extends Module
...
@@ -253,7 +255,6 @@ abstract class Application extends Module
* Initializes extensions and executes bootstrap components.
* Initializes extensions and executes bootstrap components.
* This method is called by [[init()]] after the application has been fully configured.
* 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.
* 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
()
protected
function
bootstrap
()
{
{
...
@@ -266,10 +267,10 @@ abstract class Application extends Module
...
@@ -266,10 +267,10 @@ abstract class Application extends Module
if
(
isset
(
$extension
[
'bootstrap'
]))
{
if
(
isset
(
$extension
[
'bootstrap'
]))
{
$component
=
Yii
::
createObject
(
$extension
[
'bootstrap'
]);
$component
=
Yii
::
createObject
(
$extension
[
'bootstrap'
]);
if
(
$component
instanceof
BootstrapInterface
)
{
if
(
$component
instanceof
BootstrapInterface
)
{
Yii
::
trace
(
"Bootstrap with "
.
get_class
(
$component
)
.
'::bootstrap()'
,
__METHOD__
);
$component
->
bootstrap
(
$this
);
$component
->
bootstrap
(
$this
);
}
else
{
}
else
{
$class
=
is_array
(
$extension
[
'bootstrap'
])
?
$extension
[
'bootstrap'
][
'class'
]
:
$extension
[
'bootstrap'
];
Yii
::
trace
(
"Bootstrap with "
.
get_class
(
$component
),
__METHOD__
);
throw
new
InvalidConfigException
(
"
$class
must implement
\\
yii
\\
base
\\
BootstrapInterface"
);
}
}
}
}
}
}
...
@@ -280,6 +281,8 @@ abstract class Application extends Module
...
@@ -280,6 +281,8 @@ abstract class Application extends Module
$component
=
$this
->
get
(
$class
);
$component
=
$this
->
get
(
$class
);
}
elseif
(
$this
->
hasModule
(
$class
))
{
}
elseif
(
$this
->
hasModule
(
$class
))
{
$component
=
$this
->
getModule
(
$class
);
$component
=
$this
->
getModule
(
$class
);
}
elseif
(
strpos
(
$class
,
'\\'
)
===
false
)
{
throw
new
InvalidConfigException
(
"Unknown bootstrap component ID:
$class
"
);
}
}
}
}
if
(
!
isset
(
$component
))
{
if
(
!
isset
(
$component
))
{
...
@@ -287,9 +290,10 @@ abstract class Application extends Module
...
@@ -287,9 +290,10 @@ abstract class Application extends Module
}
}
if
(
$component
instanceof
BootstrapInterface
)
{
if
(
$component
instanceof
BootstrapInterface
)
{
Yii
::
trace
(
"Bootstrap with "
.
get_class
(
$component
)
.
'::bootstrap()'
,
__METHOD__
);
$component
->
bootstrap
(
$this
);
$component
->
bootstrap
(
$this
);
}
else
{
}
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