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
ee261d38
Commit
ee261d38
authored
Oct 19, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1020 from yiisoft/module-refactoring
Module & Application refactoring
parents
07c65385
8e1199b0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
12 deletions
+23
-12
Application.php
framework/yii/base/Application.php
+19
-0
Module.php
framework/yii/base/Module.php
+4
-12
No files found.
framework/yii/base/Application.php
View file @
ee261d38
...
@@ -54,6 +54,13 @@ abstract class Application extends Module
...
@@ -54,6 +54,13 @@ abstract class Application extends Module
* @event ActionEvent an event raised after executing a controller action.
* @event ActionEvent an event raised after executing a controller action.
*/
*/
const
EVENT_AFTER_ACTION
=
'afterAction'
;
const
EVENT_AFTER_ACTION
=
'afterAction'
;
/**
* @var string the namespace that controller classes are in. If not set,
* it will use the "app\controllers" namespace.
*/
public
$controllerNamespace
=
'app\\controllers'
;
/**
/**
* @var string the application name.
* @var string the application name.
*/
*/
...
@@ -221,6 +228,18 @@ abstract class Application extends Module
...
@@ -221,6 +228,18 @@ abstract class Application extends Module
}
}
/**
/**
* Sets the root directory of the applicaition and the @app alias.
* This method can only be invoked at the beginning of the constructor.
* @param string $path the root directory of the application.
* @throws InvalidParamException if the directory does not exist.
*/
public
function
setBasePath
(
$path
)
{
parent
::
setBasePath
(
$path
);
Yii
::
setAlias
(
'@app'
,
$this
->
getBasePath
());
}
/**
* Runs the application.
* Runs the application.
* This is the main entrance of an application.
* This is the main entrance of an application.
* @return integer the exit status (0 means normal, non-zero values mean abnormal)
* @return integer the exit status (0 means normal, non-zero values mean abnormal)
...
...
framework/yii/base/Module.php
View file @
ee261d38
...
@@ -83,7 +83,6 @@ abstract class Module extends Component
...
@@ -83,7 +83,6 @@ abstract class Module extends Component
* it will use the "controllers" sub-namespace under the namespace of this module.
* it will use the "controllers" sub-namespace under the namespace of this module.
* For example, if the namespace of this module is "foo\bar", then the default
* For example, if the namespace of this module is "foo\bar", then the default
* controller namespace would be "foo\bar\controllers".
* controller namespace would be "foo\bar\controllers".
* If the module is an application, it will default to "app\controllers".
*/
*/
public
$controllerNamespace
;
public
$controllerNamespace
;
/**
/**
...
@@ -167,20 +166,16 @@ abstract class Module extends Component
...
@@ -167,20 +166,16 @@ abstract class Module extends Component
/**
/**
* Initializes the module.
* Initializes the module.
* This method is called after the module is created and initialized with property values
* This method is called after the module is created and initialized with property values
* given in configuration. The default implement will create a path alias using the module [[id]]
* given in configuration. The default implement
ation
will create a path alias using the module [[id]]
* and then call [[preloadComponents()]] to load components that are declared in [[preload]].
* and then call [[preloadComponents()]] to load components that are declared in [[preload]].
*/
*/
public
function
init
()
public
function
init
()
{
{
$this
->
preloadComponents
();
$this
->
preloadComponents
();
if
(
$this
->
controllerNamespace
===
null
)
{
if
(
$this
->
controllerNamespace
===
null
)
{
if
(
$this
instanceof
Application
)
{
$class
=
get_class
(
$this
);
$this
->
controllerNamespace
=
'app\\controllers'
;
if
((
$pos
=
strrpos
(
$class
,
'\\'
))
!==
false
)
{
}
else
{
$this
->
controllerNamespace
=
substr
(
$class
,
0
,
$pos
)
.
'\\controllers'
;
$class
=
get_class
(
$this
);
if
((
$pos
=
strrpos
(
$class
,
'\\'
))
!==
false
)
{
$this
->
controllerNamespace
=
substr
(
$class
,
0
,
$pos
)
.
'\\controllers'
;
}
}
}
}
}
}
}
...
@@ -221,9 +216,6 @@ abstract class Module extends Component
...
@@ -221,9 +216,6 @@ abstract class Module extends Component
$p
=
realpath
(
$path
);
$p
=
realpath
(
$path
);
if
(
$p
!==
false
&&
is_dir
(
$p
))
{
if
(
$p
!==
false
&&
is_dir
(
$p
))
{
$this
->
_basePath
=
$p
;
$this
->
_basePath
=
$p
;
if
(
$this
instanceof
Application
)
{
Yii
::
setAlias
(
'@app'
,
$p
);
}
}
else
{
}
else
{
throw
new
InvalidParamException
(
"The directory does not exist:
$path
"
);
throw
new
InvalidParamException
(
"The directory does not exist:
$path
"
);
}
}
...
...
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