Skip to content

Commit bbde598

Browse files
committed
Changed bug in routes filter
1 parent ef4bd5f commit bbde598

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

components/RoutesFilter.php

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,73 @@ class RoutesFilter extends ActionFilter
1313

1414
public function beforeAction($action)
1515
{
16-
if (!($this->type == 'before')) {
16+
if (!($this->type == 'before'))
17+
{
1718
return TRUE;
1819
}
1920

20-
if (is_callable($this->rule)) {
21+
if (is_callable($this->rule))
22+
{
2123
$return_data = call_user_func($this->rule);
2224

23-
if (!is_bool($return_data)) {
25+
if (!is_bool($return_data))
26+
{
2427
return FALSE;
2528
}
29+
2630
return TRUE;
2731
}
32+
2833
return FALSE;
2934
}
3035

3136
public function afterAction($action, $result)
3237
{
33-
if (!($this->type == 'after')) {
38+
if (!($this->type == 'after'))
39+
{
3440
return $result;
3541
}
3642

37-
if (is_callable($this->rule)) {
43+
if (is_callable($this->rule))
44+
{
3845
$return_data = call_user_func($this->rule);
3946

40-
if (!is_bool($return_data)) {
47+
if (!is_bool($return_data))
48+
{
4149
return FALSE;
4250
}
51+
4352
return $result;
4453
}
54+
4555
return FALSE;
4656
}
4757

48-
}
4958

59+
/**
60+
* @inheritdoc
61+
* @param \yii\base\Action $action
62+
* @return bool
63+
*/
64+
protected function isActive($action)
65+
{
66+
if ($this->owner instanceof Module)
67+
{
68+
// convert action uniqueId into an ID relative to the module
69+
$mid = $this->owner->getUniqueId();
70+
$id = $action->getUniqueId();
71+
if ($mid !== '' && strpos($id, $mid) === 0)
72+
{
73+
$id = substr($id, strlen($mid) + 1);
74+
}
75+
76+
$id = $action->controller->id . '/' . $id;
77+
}
78+
else
79+
{
80+
$id = $action->controller->id . '/' . $action->id;
81+
}
82+
83+
return !in_array($id, $this->except, TRUE) && (empty($this->only) || in_array($id, $this->only, TRUE));
84+
}
85+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"route",
88
"filter"
99
],
10-
"version": "0.0.2",
10+
"version": "0.0.3",
1111
"type": "yii2-extension",
1212
"license": "BSD",
1313
"authors": [

0 commit comments

Comments
 (0)