Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Added removeFilteredPolicy for Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
leeqvip authored Apr 11, 2019
1 parent 6f13b4f commit d6f58d9
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace CasbinAdapter\Think;

use CasbinAdapter\Think\Models\CasbinRule;
use Casbin\Exceptions\CasbinException;
use Casbin\Persist\Adapter as AdapterContract;
use Casbin\Persist\AdapterHelper;

Expand Down Expand Up @@ -77,6 +76,23 @@ public function removePolicy($sec, $ptype, $rule)

public function removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues)
{
throw new CasbinException('not implemented');
$count = 0;

$instance = $this->casbinRule->where('ptype', $ptype);
foreach (range(0, 5) as $value) {
if ($fieldIndex <= $value && $value < $fieldIndex + count($fieldValues)) {
if ('' != $fieldValues[$value - $fieldIndex]) {
$instance->where('v'.strval($value), $fieldValues[$value - $fieldIndex]);
}
}
}

foreach ($instance->select() as $model) {
if ($model->delete()) {
++$count;
}
}

return $count;
}
}

0 comments on commit d6f58d9

Please sign in to comment.