<span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span>
function
run(
$route
, $<span style=
"color: #0000ff;"
>params</span> =<span style=
"color: #000000;"
> [])
{
$pos
</span>=
strpos
(
$route
, <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">/</span><span style="color: #800000;">'
</span><span style=
"color: #000000;"
>);
</span><span style=
"color: #0000ff;"
>
if
</span> (
$pos
=== <span style=
"color: #0000ff;"
>false</span>) {<span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>this</span>->runAction(
$route
, $<span style=
"color: #0000ff;"
>params</span><span style=
"color: #000000;"
>);
}
elseif
(
$pos
</span>> <span style=
"color: #800080;"
>0</span><span style=
"color: #000000;"
>) {
</span><span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>this</span>->module->runAction(
$route
, $<span style=
"color: #0000ff;"
>params</span><span style=
"color: #000000;"
>);
} </span><span style=
"color: #0000ff;"
>
else
</span><span style=
"color: #000000;"
> {
</span><span style=
"color: #0000ff;"
>
return
</span> Yii::
$app
->runAction(ltrim(
$route
, <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">/</span><span style="color: #800000;">'
</span>), $<span style=
"color: #0000ff;"
>params</span><span style=
"color: #000000;"
>);
}
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span>
function
bindActionParams(
$action
, $<span style=
"color: #0000ff;"
>params</span><span style=
"color: #000000;"
>)
{
</span><span style=
"color: #0000ff;"
>
return
</span><span style=
"color: #000000;"
> [];
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
createAction(
$id
)
{
</span><span style=
"color: #0000ff;"
>
if
</span> (
$id
=== <span style=
"color: #800000;"
>
''
</span><span style=
"color: #000000;"
>) {
</span><span style=
"color: #008000;"
>
$id
= $<span style=
"color: #0000ff;"
>this</span>-><span style=
"color: #000000;"
>defaultAction;
}
$actionMap
</span>= $<span style=
"color: #0000ff;"
>this</span>->actions();<span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
if
</span><span style=
"color: #000000;"
> (isset(
$actionMap
[
$id
])) {
</span><span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
return
</span> Yii::createObject(
$actionMap
[
$id
], [
$id
, $<span style=
"color: #0000ff;"
>this</span><span style=
"color: #000000;"
>]);
}
elseif
(preg_match(</span><span style=
"color: #800000;"
>
'</span><span style="color: #800000;">/^[a-z0-9\\-_]+$/</span><span style="color: #800000;">'
</span>,
$id
) &&
strpos
(
$id
, <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">--</span><span style="color: #800000;">'
</span>) === <span style=
"color: #0000ff;"
>false</span> && trim(
$id
, <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">-</span><span style="color: #800000;">'
</span>) ===<span style=
"color: #000000;"
>
$id
) {
</span><span style=
"color: #008000;"
>
</span><span style=
"color: #008000;"
>
$methodName
= <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">action</span><span style="color: #800000;">'
</span> .
str_replace
(<span style=
"color: #800000;"
>
'</span> <span style="color: #800000;">'
</span>, <span style=
"color: #800000;"
>
''
</span>, ucwords(implode(<span style=
"color: #800000;"
>
'</span> <span style="color: #800000;">'
</span>,
explode
(<span style=
"color: #800000;"
>
'</span><span style="color: #800000;">-</span><span style="color: #800000;">'
</span><span style=
"color: #000000;"
>,
$id
))));
</span><span style=
"color: #0000ff;"
>
if
</span> (method_exists($<span style=
"color: #0000ff;"
>this</span><span style=
"color: #000000;"
>,
$methodName
)) {
</span><span style=
"color: #008000;"
>
$method
= <span style=
"color: #0000ff;"
>
new
</span> \ReflectionMethod($<span style=
"color: #0000ff;"
>this</span><span style=
"color: #000000;"
>,
$methodName
);
</span><span style=
"color: #0000ff;"
>
if
</span> (
$method
->isPublic() &&
$method
->getName() ===<span style=
"color: #000000;"
>
$methodName
) {
</span><span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
return
</span> <span style=
"color: #0000ff;"
>
new
</span> InlineAction(
$id
, $<span style=
"color: #0000ff;"
>this</span><span style=
"color: #000000;"
>,
$methodName
);
}
}
}
</span><span style=
"color: #0000ff;"
>
return
</span> <span style=
"color: #0000ff;"
>null</span><span style=
"color: #000000;"
>;
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
beforeAction(
$action
)
{
$</span><span style=
"color: #0000ff;"
>event</span> = <span style=
"color: #0000ff;"
>
new
</span><span style=
"color: #000000;"
> ActionEvent(
$action
);
$</span><span style=
"color: #0000ff;"
>this</span>->trigger(self::EVENT_BEFORE_ACTION, $<span style=
"color: #0000ff;"
>event</span><span style=
"color: #000000;"
>);
</span><span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>event</span>-><span style=
"color: #000000;"
>isValid;
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
afterAction(
$action
,
$result
)
{
$</span><span style=
"color: #0000ff;"
>event</span> = <span style=
"color: #0000ff;"
>
new
</span><span style=
"color: #000000;"
> ActionEvent(
$action
);
$</span><span style=
"color: #0000ff;"
>event</span>->result =<span style=
"color: #000000;"
>
$result
;
$</span><span style=
"color: #0000ff;"
>this</span>->trigger(self::EVENT_AFTER_ACTION, $<span style=
"color: #0000ff;"
>event</span><span style=
"color: #000000;"
>);
</span><span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>event</span>-><span style=
"color: #000000;"
>result;
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
getModules()
{
</span><span style=
"color: #008000;"
>
$modules
= [$<span style=
"color: #0000ff;"
>this</span>-><span style=
"color: #000000;"
>module];
$module
</span>= $<span style=
"color: #0000ff;"
>this</span>-><span style=
"color: #000000;"
>module;
</span><span style=
"color: #0000ff;"
>
while
</span> (
$module
->module !== <span style=
"color: #0000ff;"
>null</span><span style=
"color: #000000;"
>) {
</span><span style=
"color: #008000;"
>
array_unshift
(
$modules
,
$module
-><span style=
"color: #000000;"
>module);
$module
</span>=
$module
-><span style=
"color: #000000;"
>module;
}
</span><span style=
"color: #0000ff;"
>
return
</span><span style=
"color: #000000;"
>
$modules
;
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
getUniqueId()
{
</span><span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>this</span>->module
instanceof
Application ? $<span style=
"color: #0000ff;"
>this</span>->id : $<span style=
"color: #0000ff;"
>this</span>->module->getUniqueId() . <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">/</span><span style="color: #800000;">'
</span> . $<span style=
"color: #0000ff;"
>this</span>-><span style=
"color: #000000;"
>id;
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
getRoute()
{
</span><span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>this</span>->action !== <span style=
"color: #0000ff;"
>null</span> ? $<span style=
"color: #0000ff;"
>this</span>->action->getUniqueId() : $<span style=
"color: #0000ff;"
>this</span>-><span style=
"color: #000000;"
>getUniqueId();
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span>
function
render(
$view
, $<span style=
"color: #0000ff;"
>params</span> =<span style=
"color: #000000;"
> [])
{
</span><span style=
"color: #008000;"
>
$content
= $<span style=
"color: #0000ff;"
>this</span>->getView()->render(
$view
, $<span style=
"color: #0000ff;"
>params</span>, $<span style=
"color: #0000ff;"
>this</span><span style=
"color: #000000;"
>);
</span><span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>this</span>->renderContent(
$content
);<span style=
"color: #008000;"
>
<span style=
"color: #000000;"
> }
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
renderContent(
$content
)
{
$layoutFile
</span>= $<span style=
"color: #0000ff;"
>this</span>->findLayoutFile($<span style=
"color: #0000ff;"
>this</span>->getView()); <span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
if
</span> (
$layoutFile
!== <span style=
"color: #0000ff;"
>false</span>) {<span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>this</span>->getView()->renderFile(
$layoutFile
, [<span style=
"color: #800000;"
>
'</span><span style="color: #800000;">content</span><span style="color: #800000;">'
</span> =>
$content
], $<span style=
"color: #0000ff;"
>this</span><span style=
"color: #000000;"
>);
} </span><span style=
"color: #0000ff;"
>
else
</span><span style=
"color: #000000;"
> {
</span><span style=
"color: #0000ff;"
>
return
</span><span style=
"color: #000000;"
>
$content
;
}
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span>
function
renderPartial(
$view
, $<span style=
"color: #0000ff;"
>params</span> =<span style=
"color: #000000;"
> [])
{
</span><span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>this</span>->getView()->render(
$view
, $<span style=
"color: #0000ff;"
>params</span>, $<span style=
"color: #0000ff;"
>this</span><span style=
"color: #000000;"
>);
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span>
function
renderFile(
$file
, $<span style=
"color: #0000ff;"
>params</span> =<span style=
"color: #000000;"
> [])
{
</span><span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>this</span>->getView()->renderFile(
$file
, $<span style=
"color: #0000ff;"
>params</span>, $<span style=
"color: #0000ff;"
>this</span><span style=
"color: #000000;"
>);
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
getView()
{
</span><span style=
"color: #0000ff;"
>
if
</span> ($<span style=
"color: #0000ff;"
>this</span>->_view === <span style=
"color: #0000ff;"
>null</span><span style=
"color: #000000;"
>) {
$</span><span style=
"color: #0000ff;"
>this</span>->_view = Yii::
$app
-><span style=
"color: #000000;"
>getView();
}
</span><span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>this</span>-><span style=
"color: #000000;"
>_view;
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
setView(
$view
)
{
$</span><span style=
"color: #0000ff;"
>this</span>->_view =<span style=
"color: #000000;"
>
$view
;
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
getViewPath()
{
</span><span style=
"color: #0000ff;"
>
return
</span> $<span style=
"color: #0000ff;"
>this</span>->module->getViewPath() . DIRECTORY_SEPARATOR . $<span style=
"color: #0000ff;"
>this</span>-><span style=
"color: #000000;"
>id;
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
public
</span><span style=
"color: #000000;"
>
function
findLayoutFile(
$view
)
{
$module
</span>= $<span style=
"color: #0000ff;"
>this</span>-><span style=
"color: #000000;"
>module;
</span><span style=
"color: #0000ff;"
>
if
</span> (
is_string
($<span style=
"color: #0000ff;"
>this</span>-><span style=
"color: #000000;"
>layout)) {
</span><span style=
"color: #008000;"
>
$layout
= $<span style=
"color: #0000ff;"
>this</span>-><span style=
"color: #000000;"
>layout;
}
elseif
($</span><span style=
"color: #0000ff;"
>this</span>->layout === <span style=
"color: #0000ff;"
>null</span><span style=
"color: #000000;"
>) {
</span><span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
while
</span> (
$module
!== <span style=
"color: #0000ff;"
>null</span> &&
$module
->layout === <span style=
"color: #0000ff;"
>null</span><span style=
"color: #000000;"
>) {
$module
</span>=
$module
-><span style=
"color: #000000;"
>module;
}
</span><span style=
"color: #0000ff;"
>
if
</span> (
$module
!== <span style=
"color: #0000ff;"
>null</span> &&
is_string
(
$module
-><span style=
"color: #000000;"
>layout)) {
$layout
</span>=
$module
-><span style=
"color: #000000;"
>layout;
}
}
</span><span style=
"color: #0000ff;"
>
if
</span> (!<span style=
"color: #000000;"
>isset(
$layout
)) {
</span><span style=
"color: #0000ff;"
>
return
</span> <span style=
"color: #0000ff;"
>false</span>;<span style=
"color: #008000;"
>
<span style=
"color: #000000;"
> }
</span><span style=
"color: #0000ff;"
>
if
</span> (
strncmp
(
$layout
, <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">@</span><span style="color: #800000;">'
</span>, <span style=
"color: #800080;"
>1</span>) === <span style=
"color: #800080;"
>0</span><span style=
"color: #000000;"
>) {
$file
</span>= Yii::getAlias(
$layout
);<span style=
"color: #008000;"
>
}
elseif
(
strncmp
(
$layout
, <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">/</span><span style="color: #800000;">'
</span>, <span style=
"color: #800080;"
>1</span>) === <span style=
"color: #800080;"
>0</span>) {<span style=
"color: #008000;"
>
$file
= Yii::
$app
->getLayoutPath() . DIRECTORY_SEPARATOR .
substr
(
$layout
, <span style=
"color: #800080;"
>1</span><span style=
"color: #000000;"
>);
} </span><span style=
"color: #0000ff;"
>
else
</span> {<span style=
"color: #008000;"
>
$file
=
$module
-><span style=
"color: #000000;"
>getLayoutPath() . DIRECTORY_SEPARATOR .
$layout
;
}
</span><span style=
"color: #0000ff;"
>
if
</span> (
pathinfo
(
$file
, PATHINFO_EXTENSION) !== <span style=
"color: #800000;"
>
''
</span><span style=
"color: #000000;"
>) {
</span><span style=
"color: #0000ff;"
>
return
</span>
$file
;<span style=
"color: #008000;"
>
<span style=
"color: #000000;"
> }
$path
</span>=
$file
. <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">.</span><span style="color: #800000;">'
</span> .
$view
->defaultExtension;<span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
if
</span> (
$view
->defaultExtension !== <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">php</span><span style="color: #800000;">'
</span> && !<span style=
"color: #000000;"
>
is_file
(
$path
)) {
$path
</span>=
$file
. <span style=
"color: #800000;"
>
'</span><span style="color: #800000;">.php</span><span style="color: #800000;">'
</span>;<span style=
"color: #008000;"
>
<span style=
"color: #000000;"
> }
</span><span style=
"color: #0000ff;"
>
return
</span><span style=
"color: #000000;"
>
$path
;
}</span>