protected function flattenContextTree(array $return, array $perms, array $actions = []) : array
{
foreach ($perms as $i => $per) {
// Combine with AND logic
foreach ($actions as $l) {
// Active permissions
$return[$i]['perms'][$l] = ($return[$i]['perms'][$l] ?? false) && ($per['perms'][$l] ?? false);
// Inherited permissions
$return[$i]['inherit'][$l] = $return[$i]['inherit'][$l] ?? false;
$return[$i]['inherit'][$l] = $return[$i]['inherit'][$l] && (($per['inherit'][$l] ?? false) && ($return[$i]['inherit'][$l] ?? false));
}
// Recursion!
if (!empty($per['children'])) {
$return[$i]['children'] = $this->flattenContextTree($return[$i]['children'], $per['children'], $actions);
}
}
return $return;
}