Abstract Class humhub\components\access\AccessValidator

Inheritancehumhub\components\access\AccessValidator » yii\base\BaseObject
Subclasseshumhub\components\access\ActionAccessValidator, humhub\components\access\DelegateAccessValidator, humhub\components\access\DeprecatedPermissionAccessValidator, humhub\components\access\GuestAccessValidator, humhub\components\access\PermissionAccessValidator, humhub\modules\content\components\ContentContainerPermissionAccess, humhub\modules\content\components\UserGroupAccessValidator

AccessValidators are responsible for validating a given set of rules.

Rules consist of an array with at leas an rule name and optional further rule settings. If only a rule name is given, the rule is considered global, otherwise it may be restricted to specific actions by providing an action setting e.g.:

// Global myRule
['myRule']

// MyRule restricted to action1 and action2
['myRule' => ['action1', 'action2']]

// Alternative action configuration
['myRule', 'actions' => ['action1', 'action2']]

A Validator has an unique name which is used to detect related rules and can filter out non related rules by means of the filterRelatedRules() function.

AccessValidators have access to a ControllerAccess instance, which holds the ruleset and validation state.

This abstract validator class furthermore provides some helper functions as:

  • isActionRelated(): Checks if a given rule is related to the current action
  • extractActions(): Extracts the action settings from a given rule array
  • getRuleName(): Extracts the rule name from a given rule array

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$access humhub\components\access\ControllerAccess Access instance humhub\components\access\AccessValidator
$actionFilter boolean Determines if this validator is only interested in action related rules or all validator related rules humhub\components\access\AccessValidator
$code integer Http error code used in case the validation failes humhub\components\access\AccessValidator
$name string The name of the valdiator humhub\components\access\AccessValidator
$reason string Validator error message humhub\components\access\AccessValidator

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
extractActions() Extracts actions settings form a given rule. humhub\components\access\AccessValidator
filterRelatedRules() Filters out all rules which are not related to this validator. humhub\components\access\AccessValidator
getRuleName() Extracts the ruleName from the given array. humhub\components\access\AccessValidator
isActionRelated() Checks if the current action is contained in the given $rule. humhub\components\access\AccessValidator

Property Details

$access public property

Access instance

$actionFilter public property

Determines if this validator is only interested in action related rules or all validator related rules

public boolean $actionFilter true
$code public property

Http error code used in case the validation failes

public integer $code 403
$name public property

The name of the valdiator

public string $name null
$reason public property

Validator error message

public string $reason null

Method Details

extractActions() protected method

Extracts actions settings form a given rule.

Action rules can be either set like:

['ruleName', 'actions' => ['action1', 'action2']]

or in some cases:

['ruleName' => ['action1', 'action2']]

protected array extractActions ( $rule )
$rule
filterRelatedRules() protected method

Filters out all rules which are not related to this validator.

protected array filterRelatedRules ( $rules null )
$rules
getCode() public method

public integer getCode ( )
return integer

Http error code used in case the validation fails

getReason() public method

public string getReason ( )
return string

The error message in case the validation fails

getRuleName() protected method

Extracts the ruleName from the given array.

protected mixed|null getRuleName ( $rule )
$rule
init() public method

public void init ( )
isActionRelated() protected method

Checks if the current action is contained in the given $rule.

This is the case either if the current action is contained in the rules action settings or the rule is global (no action restriction).

protected boolean isActionRelated ( $rule )
$rule
run() public abstract method

Responsible for validating the given ruleset.

Related rules may be filtered by means of the filterRelatedRules() function. The whole rule set can be retrieved by calling $this->access->rules.

public abstract boolean run ( )
return boolean

True if validation passed otherwise true