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

Commit d6f58d9

Browse files
authored
Added removeFilteredPolicy for Adapter
1 parent 6f13b4f commit d6f58d9

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Adapter.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace CasbinAdapter\Think;
44

55
use CasbinAdapter\Think\Models\CasbinRule;
6-
use Casbin\Exceptions\CasbinException;
76
use Casbin\Persist\Adapter as AdapterContract;
87
use Casbin\Persist\AdapterHelper;
98

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

7877
public function removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues)
7978
{
80-
throw new CasbinException('not implemented');
79+
$count = 0;
80+
81+
$instance = $this->casbinRule->where('ptype', $ptype);
82+
foreach (range(0, 5) as $value) {
83+
if ($fieldIndex <= $value && $value < $fieldIndex + count($fieldValues)) {
84+
if ('' != $fieldValues[$value - $fieldIndex]) {
85+
$instance->where('v'.strval($value), $fieldValues[$value - $fieldIndex]);
86+
}
87+
}
88+
}
89+
90+
foreach ($instance->select() as $model) {
91+
if ($model->delete()) {
92+
++$count;
93+
}
94+
}
95+
96+
return $count;
8197
}
8298
}

0 commit comments

Comments
 (0)