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
8293e4d9
Commit
8293e4d9
authored
Oct 16, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored getModule and hasModule.
parent
71222c1f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
32 deletions
+24
-32
Module.php
framework/yii/base/Module.php
+24
-32
No files found.
framework/yii/base/Module.php
View file @
8293e4d9
...
...
@@ -326,55 +326,47 @@ abstract class Module extends Component
}
/**
* Checks whether the named module exists.
* @param string $id module ID
* Checks whether the child module of the specified ID exists.
* This method supports checking the existence of both child and grand child modules.
* @param string $id module ID. For grand child modules, use ID path relative to this module (e.g. `admin/content`).
* @return boolean whether the named module exists. Both loaded and unloaded modules
* are considered.
*/
public
function
hasModule
(
$id
)
{
if
(
strpos
(
$id
,
'/'
)
===
false
)
{
return
isset
(
$this
->
_modules
[
$id
]);
if
((
$pos
=
strpos
(
$id
,
'/'
))
!==
false
)
{
// sub-module
$module
=
$this
->
getModule
(
substr
(
$id
,
0
,
$pos
));
return
$module
===
null
?
false
:
$module
->
hasModule
(
substr
(
$id
,
$pos
+
1
));
}
else
{
// it's a sub-module
$ids
=
explode
(
'/'
,
$id
);
$module
=
$this
;
foreach
(
$ids
as
$id
)
{
if
(
!
isset
(
$module
->
_modules
[
$id
]))
{
return
false
;
}
$module
=
$module
->
getModule
(
$id
);
}
return
true
;
return
isset
(
$this
->
_modules
[
$id
]);
}
}
/**
* Retrieves the named module.
* @param string $id module ID (case-sensitive).
* Retrieves the child module of the specified ID.
* This method supports retrieving both child modules and grand child modules.
* @param string $id module ID (case-sensitive). To retrieve grand child modules,
* use ID path relative to this module (e.g. `admin/content`).
* @param boolean $load whether to load the module if it is not yet loaded.
* @return Module|null the module instance, null if the module does not exist.
* @see hasModule()
*/
public
function
getModule
(
$id
,
$load
=
true
)
{
if
(
strpos
(
$id
,
'/'
)
===
false
)
{
if
(
isset
(
$this
->
_modules
[
$id
]))
{
if
(
$this
->
_modules
[
$id
]
instanceof
Module
)
{
return
$this
->
_modules
[
$id
];
}
elseif
(
$load
)
{
Yii
::
trace
(
"Loading module:
$id
"
,
__METHOD__
);
return
$this
->
_modules
[
$id
]
=
Yii
::
createObject
(
$this
->
_modules
[
$id
],
$id
,
$this
);
}
}
}
else
{
// it's a sub-module
$ids
=
explode
(
'/'
,
$id
);
$module
=
$this
;
foreach
(
$ids
as
$id
)
{
$module
=
$module
->
getModule
(
$id
);
if
((
$pos
=
strpos
(
$id
,
'/'
))
!==
false
)
{
// sub-module
$module
=
$this
->
getModule
(
substr
(
$id
,
0
,
$pos
));
return
$module
===
null
?
null
:
$module
->
getModule
(
substr
(
$id
,
$pos
+
1
),
$load
);
}
if
(
isset
(
$this
->
_modules
[
$id
]))
{
if
(
$this
->
_modules
[
$id
]
instanceof
Module
)
{
return
$this
->
_modules
[
$id
];
}
elseif
(
$load
)
{
Yii
::
trace
(
"Loading module:
$id
"
,
__METHOD__
);
return
$this
->
_modules
[
$id
]
=
Yii
::
createObject
(
$this
->
_modules
[
$id
],
$id
,
$this
);
}
return
$module
;
}
return
null
;
}
...
...
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