mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-04 06:37:55 +08:00 
			
		
		
		
	Better executeRule implementation.
This commit is contained in:
		@ -9,6 +9,7 @@ namespace yii\rbac;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use Yii;
 | 
					use Yii;
 | 
				
			||||||
use yii\base\Component;
 | 
					use yii\base\Component;
 | 
				
			||||||
 | 
					use yii\base\InvalidConfigException;
 | 
				
			||||||
use yii\base\InvalidParamException;
 | 
					use yii\base\InvalidParamException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -145,16 +146,21 @@ abstract class Manager extends Component
 | 
				
			|||||||
     * @param string $ruleName name of the rule to be executed.
 | 
					     * @param string $ruleName name of the rule to be executed.
 | 
				
			||||||
     * @param array $params parameters passed to [[Manager::checkAccess()]].
 | 
					     * @param array $params parameters passed to [[Manager::checkAccess()]].
 | 
				
			||||||
     * @param mixed $data additional data associated with the authorization item or assignment.
 | 
					     * @param mixed $data additional data associated with the authorization item or assignment.
 | 
				
			||||||
     * @return boolean whether the rule execution returns true.
 | 
					     * @return boolean whether the rule execution returns true. If `$ruleName` is null, true will be returned.
 | 
				
			||||||
     * If the rule is empty, it will still return true.
 | 
					     * @throws InvalidConfigException if `$ruleName` does not correspond to a valid rule.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function executeRule($ruleName, $params, $data)
 | 
					    public function executeRule($ruleName, $params, $data)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $rule = $this->getRule($ruleName);
 | 
					        if ($ruleName !== null) {
 | 
				
			||||||
        if ($rule) {
 | 
					            $rule = $this->getRule($ruleName);
 | 
				
			||||||
            return $rule->execute($params, $data);
 | 
					            if ($rule instanceof Rule) {
 | 
				
			||||||
 | 
					                return $rule->execute($params, $data);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                throw new InvalidConfigException("Rule not found: $ruleName");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user