Skip to content

Commit cb04496

Browse files
committed
feat: Casbin Logger, Supported: \Psr\Log\LoggerInterface
1 parent 2ada6ff commit cb04496

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/Adapter/DatabaseAdapter.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use Casbin\Persist\FilteredAdapter;
1919
use Casbin\Persist\Adapters\Filter;
2020
use Casbin\Exceptions\InvalidFilterTypeException;
21+
use think\db\exception\DataNotFoundException;
22+
use think\db\exception\DbException;
23+
use think\db\exception\ModelNotFoundException;
2124
use think\facade\Db;
2225
use Casbin\WebmanPermission\Model\RuleModel;
2326

@@ -80,7 +83,7 @@ public function filterRule(array $rule): array
8083
*
8184
* @return void
8285
*/
83-
public function savePolicyLine($ptype, array $rule)
86+
public function savePolicyLine(string $ptype, array $rule): void
8487
{
8588
$col['ptype'] = $ptype;
8689
foreach ($rule as $key => $value) {
@@ -93,6 +96,9 @@ public function savePolicyLine($ptype, array $rule)
9396
* loads all policy rules from the storage.
9497
*
9598
* @param Model $model
99+
* @throws DataNotFoundException
100+
* @throws DbException
101+
* @throws ModelNotFoundException
96102
*/
97103
public function loadPolicy(Model $model): void
98104
{
@@ -168,7 +174,10 @@ public function addPolicies(string $sec, string $ptype, array $rules): void
168174
*
169175
* @param string $sec
170176
* @param string $ptype
171-
* @param array $rule
177+
* @param array $rule
178+
* @throws DataNotFoundException
179+
* @throws DbException
180+
* @throws ModelNotFoundException
172181
*/
173182
public function removePolicy(string $sec, string $ptype, array $rule): void
174183
{
@@ -205,12 +214,14 @@ public function removePolicies(string $sec, string $ptype, array $rules): void
205214
}
206215

207216
/**
208-
* @param string $sec
209-
* @param string $ptype
210-
* @param int $fieldIndex
217+
* @param string $sec
218+
* @param string $ptype
219+
* @param int $fieldIndex
211220
* @param string|null ...$fieldValues
212221
* @return array
213-
* @throws Throwable
222+
* @throws DbException
223+
* @throws ModelNotFoundException
224+
* @throws DataNotFoundException
214225
*/
215226
public function _removeFilteredPolicy(string $sec, string $ptype, int $fieldIndex, ?string ...$fieldValues): array
216227
{
@@ -244,8 +255,11 @@ public function _removeFilteredPolicy(string $sec, string $ptype, int $fieldInde
244255
*
245256
* @param string $sec
246257
* @param string $ptype
247-
* @param int $fieldIndex
258+
* @param int $fieldIndex
248259
* @param string ...$fieldValues
260+
* @throws DataNotFoundException
261+
* @throws DbException
262+
* @throws ModelNotFoundException
249263
*/
250264
public function removeFilteredPolicy(string $sec, string $ptype, int $fieldIndex, string ...$fieldValues): void
251265
{
@@ -260,6 +274,9 @@ public function removeFilteredPolicy(string $sec, string $ptype, int $fieldIndex
260274
* @param string $ptype
261275
* @param string[] $oldRule
262276
* @param string[] $newPolicy
277+
* @throws DataNotFoundException
278+
* @throws DbException
279+
* @throws ModelNotFoundException
263280
*/
264281
public function updatePolicy(string $sec, string $ptype, array $oldRule, array $newPolicy): void
265282
{
@@ -342,6 +359,10 @@ public function setFiltered(bool $filtered): void
342359
*
343360
* @param Model $model
344361
* @param mixed $filter
362+
* @throws InvalidFilterTypeException
363+
* @throws DataNotFoundException
364+
* @throws DbException
365+
* @throws ModelNotFoundException
345366
*/
346367
public function loadFilteredPolicy(Model $model, $filter): void
347368
{
@@ -351,7 +372,6 @@ public function loadFilteredPolicy(Model $model, $filter): void
351372
$instance = $instance->whereRaw($filter);
352373
} elseif ($filter instanceof Filter) {
353374
foreach ($filter->p as $k => $v) {
354-
$where[$v] = $filter->g[$k];
355375
$instance = $instance->where($v, $filter->g[$k]);
356376
}
357377
} elseif ($filter instanceof \Closure) {

src/Adapter/LaravelDatabaseAdapter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ public function loadFilteredPolicy(Model $model, $filter): void
368368
*
369369
* @return Builder[]|Collection
370370
*/
371-
protected function getCollection(string $ptype, int $fieldIndex, array $fieldValues) {
371+
protected function getCollection(string $ptype, int $fieldIndex, array $fieldValues): Collection|array
372+
{
372373
$where = [
373374
'ptype' => $ptype,
374375
];

0 commit comments

Comments
 (0)