Skip to content

Commit

Permalink
fix: Use loadPolicyArray instead of loadPolicyLine to fix the problem…
Browse files Browse the repository at this point in the history
… of quotation marks
  • Loading branch information
leeqvip committed Sep 9, 2021
1 parent d32690d commit 2563953
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ public function loadPolicy(Model $model): void
$stmt = $queryBuilder->select('p_type', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5')->from($this->policyTableName)->execute();

while ($row = $this->fetch($stmt)) {
$line = implode(', ', array_filter($row, function ($val) {
return '' != $val && !is_null($val);
}));
$this->loadPolicyLine(trim($line), $model);
$this->loadPolicyArray($this->filterRule($row), $model);
}
}

Expand Down Expand Up @@ -437,11 +434,16 @@ public function updateFilteredPolicies(string $sec, string $ptype, array $newRul
*/
public function filterRule(array $rule): array
{
$rule = array_filter($rule, function ($val) {
return '' != $val && !is_null($val);
});
$rule = array_values($rule);

$i = count($rule) - 1;
for (; $i >= 0; $i--) {
if ($rule[$i] != "" && !is_null($rule[$i])) {
break;
}
}

return array_values($rule);
return array_slice($rule, 0, $i + 1);
}

/**
Expand Down

0 comments on commit 2563953

Please sign in to comment.