Skip to content

Commit df6c7b8

Browse files
authored
Merge pull request #2 from radiatecode/0.3
Get only names function does not return custom permissions
2 parents 05f96c0 + 6df03bf commit df6c7b8

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/Permissions.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ public function get(): array
7878
public function getOnlyPermissionsNames()
7979
{
8080
if (!$this->hasCachedPermissions()) {
81-
sort($this->onlyPermissionsNames);
82-
8381
return $this->onlyPermissionsNames;
8482
}
8583

@@ -95,16 +93,36 @@ protected function customPermissions(): Permissions
9593
foreach ($permission as $item) {
9694
// when the permission only contains permission name
9795
if (!is_array($item)) {
96+
97+
// skip if permission exist
98+
if (in_array($item, $this->onlyPermissionsNames)) {
99+
continue;
100+
}
101+
98102
$this->permissions[$key][] = [
99103
'name' => $item,
100104
'text' => ucwords(str_replace($this->splitter, ' ', $item)),
101105
];
102106

107+
$this->onlyPermissionsNames[] = $item;
108+
103109
continue;
104110
}
105111

106-
// when permission has valid permission structure (ex: slug, name key available)
112+
// skip if permission array format is invalid
113+
if (!array_key_exists('name', $item) || !array_key_exists('text', $item)) {
114+
continue;
115+
}
116+
117+
// skip if permission exist
118+
if (in_array($item['name'], $this->onlyPermissionsNames)) {
119+
continue;
120+
}
121+
122+
// when permission has valid permission structure (ex: text, name key available)
107123
$this->permissions[$key][] = $item;
124+
125+
$this->onlyPermissionsNames[] = $item['name'];
108126
}
109127
}
110128
}

0 commit comments

Comments
 (0)