Skip to content

Commit

Permalink
Fixes suggested by @samdark
Browse files Browse the repository at this point in the history
  • Loading branch information
fsateler committed May 15, 2015
1 parent 08dbe57 commit 7d91c50
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions framework/filters/AccessRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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)) {
Expand Down

0 comments on commit 7d91c50

Please sign in to comment.