diff --git a/framework/filters/AccessRule.php b/framework/filters/AccessRule.php index a1c243e9292..066bf4fa838 100644 --- a/framework/filters/AccessRule.php +++ b/framework/filters/AccessRule.php @@ -98,18 +98,33 @@ class AccessRule extends Component * The map indicates query parameters that will be passed when determining * role access. * - * If only a value is passed then the query parameter will by passed as is. - * If both a key and value are passed, then the name of the parameter will - * be changed. A value of `['a' => 'b']` will invoke [[User::can()]] with - * the content of queryParam['a'] as key 'b' in the params argument. + * If both a key and a value are passed, then the name of the parameter will + * be changed. A value of `['a' => 'b']` will cause [[User::can()]] to be + * invoked with the content of queryParam['a'] as key 'b' in the params + * argument. + * If only a value is passed then it is equivalent to passing the same value + * as key. * * The special parameters '{action}' and '{controller}' are bound to the * action and controller ids */ public $paramsMap = []; - + /** + * @var array the parameters to be passed to [[User::can()]]. + * + * Do not use directly, use [[getParamsForCan()]] to access it + */ private $_paramsForCan = null; + + /** + * Gets the parameters to be passed to [[User::can()]]. + * + * It will parse [[AccessRule::paramsMap]] and create the array of + * parameters, if it has not been created already. + * + * @return array + */ private function getParamsForCan() { if ($this->_paramsForCan === null) { $newParams = []; @@ -118,10 +133,10 @@ private function getParamsForCan() { if (!is_string($key)) { $key = $value; } - if ($key == '{action}') { + if ($key === '{action}') { $newParams[$value] = Yii::$app->controller->action->id; } - else if ($key == '{controller}') { + elseif ($key === '{controller}') { $newParams[$value] = Yii::$app->controller->id; } if (ArrayHelper::keyExists($key, $queryParams)) {