Inverse of Permission::buildPermissionsFromArray (code review request)

Permalink
It appears that buildPermissionsFromArray (which constructs a string of flags known as a permission set based on the the array contained in the permissions object) is not invertible. That is, there is no operation to go from a permission set to the "simple XML" format for permissions. Is that correct, or am I missing something?

If it is correct, and I have to roll my own, is this code correct for Concrete5 permissions semantics? The purpose is to enable members of one group to view a Page, while preserving all other permissions. It achieves what I want it to, so the correctness I'm looking for is more along the lines of a) avoids side-effects, b) doesn't omit any steps to preserve the original semantics.

function addThirdParty($roleGroupName) {
    $gl = new GroupList($this->page);
    $gArray = $gl->getGroupList();
    $perms = new stdClass;
    $index = 0;
    $alreadyUpdated = false;
    foreach ($gArray as $group) {
      $updateThisGroup = $group->getGroupName() === $roleGroupName;
      if (!$group->permissionSet && !$updateThisGroup) {
        continue;
      }
      $perms->group[$index]['gID'] = $group->getGroupID();
      $perms->group[$index]['canRead'] = $group->canRead() || $updateThisGroup;
      $perms->group[$index]['canWrite'] = $group->canWrite();
      $perms->group[$index]['canApproveVersions'] = $group->canApproveCollection();


(The objection that the standard $pxml special cases guests, admins, and registered is noted, but the looking at the code it seems those are only there for convenience, and if the group ID is passed in correctly it will work just fine. I'll accept the risk that this might become undefined behavior.)