Improved ACL classes

This commit is contained in:
Matias Griese 2021-12-07 12:50:59 +02:00
parent b2cfc4ef5f
commit 042d4a4603
4 changed files with 8 additions and 21 deletions

View File

@ -14,7 +14,6 @@ use Countable;
use Grav\Common\Utils;
use IteratorAggregate;
use JsonSerializable;
use RuntimeException;
use Traversable;
use function count;
use function is_array;
@ -79,12 +78,7 @@ class Access implements JsonSerializable, IteratorAggregate, Countable
$inherited = array_diff_key($parent->getAllActions(), $acl);
$this->inherited += $parent->inherited + array_fill_keys(array_keys($inherited), $name ?? $parent->getName());
$acl = array_replace($acl, $inherited);
if (null === $acl) {
throw new RuntimeException('Internal error');
}
$this->acl = $acl;
$this->acl = array_replace($acl, $inherited);
}
/**

View File

@ -16,7 +16,6 @@ use IteratorAggregate;
use RuntimeException;
use Traversable;
use function count;
use function strlen;
/**
* Class Action
@ -49,8 +48,8 @@ class Action implements IteratorAggregate, Countable
{
$label = $action['label'] ?? null;
if (!$label) {
if ($pos = strrpos($name, '.')) {
$label = substr($name, $pos + 1);
if ($pos = mb_strrpos($name, '.')) {
$label = mb_substr($name, $pos + 1);
} else {
$label = $name;
}
@ -115,9 +114,9 @@ class Action implements IteratorAggregate, Countable
*/
public function getScope(): string
{
$pos = strpos($this->name, '.');
$pos = mb_strpos($this->name, '.');
if ($pos) {
return substr($this->name, 0, $pos);
return mb_substr($this->name, 0, $pos);
}
return $this->name;
@ -128,7 +127,7 @@ class Action implements IteratorAggregate, Countable
*/
public function getLevels(): int
{
return substr_count($this->name, '.');
return mb_substr_count($this->name, '.');
}
/**
@ -162,12 +161,12 @@ class Action implements IteratorAggregate, Countable
*/
public function addChild(Action $child): void
{
if (strpos($child->name, "{$this->name}.") !== 0) {
if (mb_strpos($child->name, "{$this->name}.") !== 0) {
throw new RuntimeException('Bad child');
}
$child->setParent($this);
$name = substr($child->name, strlen($this->name) + 1);
$name = mb_substr($child->name, mb_strlen($this->name) + 1);
$this->children[$name] = $child;
}

View File

@ -148,9 +148,6 @@ class Permissions implements ArrayAccess, Countable, IteratorAggregate
public function addTypes(array $types): void
{
$types = array_replace($this->types, $types);
if (null === $types) {
throw new RuntimeException('Internal error');
}
$this->types = $types;
}

View File

@ -174,9 +174,6 @@ class PermissionsReader
$scopes[] = $action;
$action = array_replace_recursive(...$scopes);
if (null === $action) {
throw new RuntimeException('Internal error');
}
$newType = $defaults['type'] ?? null;
if ($newType && $newType !== $type) {