Skip to content

Commit e1522bb

Browse files
committed
added policy support in getAbilities method
1 parent a27208d commit e1522bb

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

src/Permission.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,47 @@ public function getAbilities($module = null)
447447
{
448448
$abilities_arr = $this->config->get('permit.abilities');
449449

450+
$abilities = null;
450451
if (is_null($module)) {
451-
return $abilities_arr;
452+
$abilities = $abilities_arr;
452453
}
453454

454455
if (isset($abilities_arr[$module])) {
455-
return $abilities_arr[$module];
456+
$abilities = $abilities_arr[$module];
456457
}
457458

458-
return null;
459+
return $this->parseAbilities($abilities);
460+
}
461+
462+
/**
463+
* parseAbilities is parse for policy
464+
*
465+
* @param $modules
466+
* @return array
467+
*/
468+
protected function parseAbilities($modules)
469+
{
470+
$policies = $this->config->get('permit.policies');
471+
$new_abilities = [];
472+
473+
foreach ($modules as $module=>$abilities) {
474+
foreach ($abilities as $key => $ability) {
475+
if (!isset($new_abilities[$module])) {
476+
$new_abilities[$module] = [];
477+
}
478+
if (is_int($key)) {
479+
$new_abilities[$module][] = $ability;
480+
} elseif (is_string($key)) {
481+
$policies_name = explode('.', $ability);
482+
if (count($policies_name)==2) {
483+
$new_abilities[$module][$ability] = $policies[$policies_name[0]][$policies_name[1]];
484+
}
485+
}
486+
}
487+
488+
}
489+
490+
return $new_abilities;
459491
}
460492

461493
/**

0 commit comments

Comments
 (0)