Skip to content

Commit

Permalink
Added functions to get list or array of all permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Gross committed Feb 1, 2015
1 parent 0d3220f commit 10ea5ac
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
26 changes: 26 additions & 0 deletions src/PermissionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,30 @@ public function setTemporaryPermissions($permissionArray, $requestLifetime = 2)
\Log::error('[Laraguard] ERROR - could not write permissions.yml');
return false;
}

/**
* Returns an array with all permission names
*
* @return array
*/
public function getPermissionNames() {
return array_keys($this->getPermissionArray());
}

/**
* Returns an array with all permissions and their respective
* children (regex or controller action string)
*
* @return array
*/
public function getPermissionArray() {
if($this->permissionConf !== null) {
// Get controller action permissions
$permissionArray = $this->permissionConf['controllerActionPermissions'];
// Add custom permissions
$permissionArray = array_merge($permissionArray, $this->permissionConf['customPermissions']);
return $permissionArray;
}
return [];
}
}
3 changes: 0 additions & 3 deletions src/Providers/LaraguardServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public function register()
$this->app->singleton('Laraguard', function($app) {
return new Laraguard();
});
$this->app->singleton('CGross\Laraguard\Services\Laraguard', function($app) {
return $app->make('Laraguard');
});
}

}
21 changes: 21 additions & 0 deletions src/Services/Laraguard.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,25 @@ public function setTemporaryPermissions($permissionArray, $permissionLifetime =
public function resetTemporaryPermissions() {
return $this->permissionParser->resetTemporaryPermissions();
}

/**
* Returns an array with all permission names
*
* @return array
*/
public function getPermissionNames() {
$permissionNames = array_keys($this->getPermissionArray());
sort($permissionNames);
return $permissionNames;
}

/**
* Returns an array with all permissions and their respective
* children (regex or controller action string)
*
* @return array
*/
public function getPermissionArray() {
return $this->permissionParser->getPermissionArray();
}
}

0 comments on commit 10ea5ac

Please sign in to comment.