|
|
@ -28,7 +28,7 @@ abstract class BaseManager extends Component implements ManagerInterface |
|
|
|
* @var array a list of role names that are assigned to every user automatically without calling [[assign()]]. |
|
|
|
* @var array a list of role names that are assigned to every user automatically without calling [[assign()]]. |
|
|
|
* Note that these roles are applied to users, regardless of their state of authentication. |
|
|
|
* Note that these roles are applied to users, regardless of their state of authentication. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $defaultRoles = []; |
|
|
|
protected $defaultRoles = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -196,6 +196,36 @@ abstract class BaseManager extends Component implements ManagerInterface |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* Set default roles |
|
|
|
|
|
|
|
* @param array|\Closure $roles either array of roles or a callable returning it |
|
|
|
|
|
|
|
* @since 2.0.14 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function setDefaultRoles($roles) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (is_array($roles)) { |
|
|
|
|
|
|
|
$this->defaultRoles = $roles; |
|
|
|
|
|
|
|
} elseif (is_callable($roles)) { |
|
|
|
|
|
|
|
$roles = $roles(); |
|
|
|
|
|
|
|
if (!is_array($roles)) { |
|
|
|
|
|
|
|
throw new InvalidParamException('Default roles closure must return an array'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$this->defaultRoles = $roles; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
throw new InvalidParamException('Default roles must be either an array or a callable'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Get default roles |
|
|
|
|
|
|
|
* @return array default roles |
|
|
|
|
|
|
|
* @since 2.0.14 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function getDefaultRoles() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $this->defaultRoles; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Returns defaultRoles as array of Role objects. |
|
|
|
* Returns defaultRoles as array of Role objects. |
|
|
|
* @since 2.0.12 |
|
|
|
* @since 2.0.12 |
|
|
|
* @return Role[] default roles. The array is indexed by the role names |
|
|
|
* @return Role[] default roles. The array is indexed by the role names |
|
|
|