Browse Source

refactored AccessControl

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
32ba512246
  1. 17
      framework/web/AccessControl.php

17
framework/web/AccessControl.php

@ -33,12 +33,17 @@ class AccessControl extends ActionFilter
*/ */
public $denyCallback; public $denyCallback;
/** /**
* @var string the default class of the access rules. This is used when * @var array the default configuration of access rules. Individual rule configurations
* a rule is configured without specifying a class in [[rules]]. * specified via [[rules]] will take precedence when the same property of the rule is configured.
*/ */
public $defaultRuleClass = 'yii\web\AccessRule'; public $ruleConfig = array(
'class' => 'yii\web\AccessRule',
);
/** /**
* @var array a list of access rule objects or configurations for creating the rule objects. * @var array a list of access rule objects or configuration arrays for creating the rule objects.
* If a rule is specified via a configuration array, it will be merged with [[ruleConfig]] before
* it is used for creating the rule object.
* @see ruleConfig
*/ */
public $rules = array(); public $rules = array();
@ -50,9 +55,7 @@ class AccessControl extends ActionFilter
parent::init(); parent::init();
foreach ($this->rules as $i => $rule) { foreach ($this->rules as $i => $rule) {
if (is_array($rule)) { if (is_array($rule)) {
if (!isset($rule['class'])) { $rule = array_merge($this->ruleConfig, $rule);
$rule['class'] = $this->defaultRuleClass;
}
$this->rules[$i] = Yii::createObject($rule); $this->rules[$i] = Yii::createObject($rule);
} }
} }

Loading…
Cancel
Save