Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
`getAllChildPermissions()` methods of `ItemsStorageInterface` (@arogachev)
- Enh #204: Add simple storages for items and assignments (@arogachev)
- Chg #217: Raise PHP version to 8.1 (@arogachev)
- Bug #221: Exclude items with base names when getting children (@arogachev)

## 1.0.2 April 20, 2023

Expand Down
10 changes: 7 additions & 3 deletions src/SimpleItemsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,25 +331,29 @@ private function getAllChildrenInternal(string|array $names, array &$result): vo
{
$names = (array) $names;
foreach ($names as $name) {
$this->fillChildrenRecursive($name, $result);
$this->fillChildrenRecursive($name, $result, $names);
}
}

/**
* @psalm-param ItemsIndexedByName $result
* @psalm-param-out ItemsIndexedByName $result
*/
private function fillChildrenRecursive(string $name, array &$result): void
private function fillChildrenRecursive(string $name, array &$result, array $baseNames): void
{
$children = $this->children[$name] ?? [];
foreach ($children as $childName => $_childItem) {
if (in_array($childName, $baseNames, strict: true)) {
continue;
}

$child = $this->get($childName);
if ($child !== null) {
/** @psalm-var ItemsIndexedByName $result Imported type in `psalm-param-out` is not resolved. */
$result[$childName] = $child;
}

$this->fillChildrenRecursive($childName, $result);
$this->fillChildrenRecursive($childName, $result, $baseNames);
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Common/ItemsStorageTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static function dataGetAllChildren(): array
[['Parent 1', 'Parent 2'], ['Child 1', 'Child 2', 'Child 3']],
[
['posts.viewer', 'posts.redactor', 'posts.admin'],
['posts.redactor', 'posts.viewer', 'posts.view', 'posts.create', 'posts.update', 'posts.delete'],
['posts.view', 'posts.create', 'posts.update', 'posts.delete'],
],
['non-existing', []],
];
Expand Down Expand Up @@ -251,7 +251,7 @@ public static function dataGetAllChildRoles(): array
['posts.redactor', ['posts.viewer']],
['posts.admin', ['posts.redactor', 'posts.viewer']],
[['Parent 2', 'Parent 4'], ['Child 2', 'Child 3', 'Child 4']],
[['posts.viewer', 'posts.redactor', 'posts.admin'], ['posts.redactor', 'posts.viewer']],
[['posts.viewer', 'posts.redactor', 'posts.admin'], []],
['non-existing', []],
];
}
Expand Down Expand Up @@ -617,12 +617,12 @@ protected function getFixtures(): array
['parent' => 'Parent 5', 'child' => 'Child 5'],

// Multiple generations of children
['parent' => 'posts.admin', 'child' => 'posts.redactor'],
['parent' => 'posts.redactor', 'child' => 'posts.viewer'],
['parent' => 'posts.viewer', 'child' => 'posts.view'],
['parent' => 'posts.redactor', 'child' => 'posts.create'],
['parent' => 'posts.redactor', 'child' => 'posts.update'],
['parent' => 'posts.admin', 'child' => 'posts.delete'],
['parent' => 'posts.admin', 'child' => 'posts.redactor'],
['parent' => 'posts.redactor', 'child' => 'posts.viewer'],
];
foreach ($itemsChildren as $itemChild) {
$parentItemType = $itemsMap[$itemChild['parent']];
Expand Down