Skip to content

Commit

Permalink
Merge pull request #13 from basakest/fix-addPolicies
Browse files Browse the repository at this point in the history
fix: addPolicies doesn't execute the sql statement
  • Loading branch information
leeqvip authored Jul 13, 2021
2 parents a31da99 + 176d5ed commit 5519e48
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ public function addPolicy(string $sec, string $ptype, array $rule): void
public function addPolicies(string $sec, string $ptype, array $rules): void
{
$table = $this->casbinRuleTableName;
$columns = ['p_type', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5'];
$columns = ['ptype', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5'];
$values = [];
$sets = [];
$columnsCount = count($columns);
foreach ($rules as $rule) {
array_unshift($rule, $ptype);
$values = array_merge($values, array_pad($rule, $columnsCount, null));
$sets[] = array_pad([], $columnsCount, '?');
}
Expand All @@ -155,6 +156,7 @@ public function addPolicies(string $sec, string $ptype, array $rules): void
}, $sets));
$sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $columns) . ')' .
' VALUES' . $valuesStr;
$this->connection->execute($sql, $values);
}

public function removePolicies(string $sec, string $ptype, array $rules): void
Expand Down

0 comments on commit 5519e48

Please sign in to comment.