Skip to content

Commit

Permalink
Merge pull request #2 from radiatecode/0.3
Browse files Browse the repository at this point in the history
Get only names function does not return custom permissions
  • Loading branch information
radiatecode authored Mar 2, 2023
2 parents 05f96c0 + 6df03bf commit df6c7b8
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ public function get(): array
public function getOnlyPermissionsNames()
{
if (!$this->hasCachedPermissions()) {
sort($this->onlyPermissionsNames);

return $this->onlyPermissionsNames;
}

Expand All @@ -95,16 +93,36 @@ protected function customPermissions(): Permissions
foreach ($permission as $item) {
// when the permission only contains permission name
if (!is_array($item)) {

// skip if permission exist
if (in_array($item, $this->onlyPermissionsNames)) {
continue;
}

$this->permissions[$key][] = [
'name' => $item,
'text' => ucwords(str_replace($this->splitter, ' ', $item)),
];

$this->onlyPermissionsNames[] = $item;

continue;
}

// when permission has valid permission structure (ex: slug, name key available)
// skip if permission array format is invalid
if (!array_key_exists('name', $item) || !array_key_exists('text', $item)) {
continue;
}

// skip if permission exist
if (in_array($item['name'], $this->onlyPermissionsNames)) {
continue;
}

// when permission has valid permission structure (ex: text, name key available)
$this->permissions[$key][] = $item;

$this->onlyPermissionsNames[] = $item['name'];
}
}
}
Expand Down

0 comments on commit df6c7b8

Please sign in to comment.