Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update Doctrine role provider to build role hierarchy properly

 (1) Build every role object first
 (2) Perform parent object injections where necessary
  • Loading branch information...
commit 7c6093eefaaf553c0de93b5d9fa49400071ad2a8 1 parent 372e72f
@adamlundrigan adamlundrigan authored
Showing with 13 additions and 4 deletions.
  1. +13 −4 src/BjyAuthorize/Provider/Role/Doctrine.php
View
17 src/BjyAuthorize/Provider/Role/Doctrine.php
@@ -37,12 +37,21 @@ public function getRoles()
$builder->select($this->roleIdFieldName,$this->parentRoleFieldName)
->from($this->tableName, $this->tableName);
- $result = $builder->execute();
+ $rowset = $builder->execute();
$roles = array();
- foreach($result as $row) {
- $roles[] = new Role($row[$this->roleIdFieldName], $row[$this->parentRoleFieldName]);
+ // Pass One: Build each object
+ foreach ($rowset as $row) {
+ $roleId = $row[$this->roleIdFieldName];
+ $roles[$roleId] = new Role($roleId, $row[$this->parentRoleFieldName]);
}
- return $roles;
+ // Pass Two: Re-inject parent objects to preserve hierarchy
+ foreach ($roles as $roleId=>$roleObj) {
+ $parentRoleObj = $roleObj->getParent();
+ if ($parentRoleObj && $parentRoleObj->getRoleId()) {
+ $roleObj->setParent($roles[$parentRoleObj->getRoleId()]);
+ }
+ }
+ return array_values($roles);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.