Upgrade to 3.4.3

This commit is contained in:
Bastian Allgeier
2020-09-15 10:25:09 +02:00
parent 54b9ba3047
commit d8e797dd9b
108 changed files with 1750 additions and 523 deletions

View File

@@ -17,8 +17,14 @@ use Kirby\Exception\InvalidArgumentException;
*/
class Permissions
{
/**
* @var array
*/
public static $extendedActions = [];
/**
* @var array
*/
protected $actions = [
'access' => [
'panel' => true,
@@ -76,6 +82,12 @@ class Permissions
]
];
/**
* Permissions constructor
*
* @param array $settings
* @throws \Kirby\Exception\InvalidArgumentException
*/
public function __construct($settings = [])
{
// dynamically register the extended actions
@@ -96,6 +108,11 @@ class Permissions
}
}
/**
* @param string|null $category
* @param string|null $action
* @return bool
*/
public function for(string $category = null, string $action = null): bool
{
if ($action === null) {
@@ -113,16 +130,31 @@ class Permissions
return $this->actions[$category][$action];
}
/**
* @param string $category
* @param string $action
* @return bool
*/
protected function hasAction(string $category, string $action): bool
{
return $this->hasCategory($category) === true && array_key_exists($action, $this->actions[$category]) === true;
}
/**
* @param string $category
* @return bool
*/
protected function hasCategory(string $category): bool
{
return array_key_exists($category, $this->actions) === true;
}
/**
* @param string $category
* @param string $action
* @param $setting
* @return self
*/
protected function setAction(string $category, string $action, $setting)
{
// wildcard to overwrite the entire category
@@ -135,6 +167,10 @@ class Permissions
return $this;
}
/**
* @param bool $setting
* @return self
*/
protected function setAll(bool $setting)
{
foreach ($this->actions as $categoryName => $actions) {
@@ -144,6 +180,10 @@ class Permissions
return $this;
}
/**
* @param array $settings
* @return self
*/
protected function setCategories(array $settings)
{
foreach ($settings as $categoryName => $categoryActions) {
@@ -161,6 +201,12 @@ class Permissions
return $this;
}
/**
* @param string $category
* @param bool $setting
* @return self
* @throws \Kirby\Exception\InvalidArgumentException
*/
protected function setCategory(string $category, bool $setting)
{
if ($this->hasCategory($category) === false) {
@@ -174,6 +220,9 @@ class Permissions
return $this;
}
/**
* @return array
*/
public function toArray(): array
{
return $this->actions;