Skip to content

Commit 301524f

Browse files
committed
fix a format
1 parent ff99791 commit 301524f

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

src/Adapter.php

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(array $config)
3535
$this->initTable();
3636
}
3737

38-
/**
38+
/**
3939
* Returns true if the loaded policy has been filtered.
4040
*
4141
* @return bool
@@ -45,6 +45,51 @@ public function isFiltered(): bool
4545
return $this->filtered;
4646
}
4747

48+
public static function newAdapter(array $config)
49+
{
50+
return new static($config);
51+
}
52+
53+
public function initTable()
54+
{
55+
$sql = file_get_contents(__DIR__.'/../migrations/'.$this->config['type'].'.sql');
56+
$sql = str_replace('%table_name%', $this->casbinRuleTableName, $sql);
57+
$this->connection->execute($sql, []);
58+
}
59+
60+
public function savePolicyLine($ptype, array $rule)
61+
{
62+
$col['ptype'] = $ptype;
63+
foreach ($rule as $key => $value) {
64+
$col['v'.strval($key).''] = $value;
65+
}
66+
67+
$colStr = implode(', ', array_keys($col));
68+
69+
$name = rtrim(str_repeat('?, ', count($col)), ', ');
70+
71+
$sql = 'INSERT INTO '.$this->casbinRuleTableName.'('.$colStr.') VALUES ('.$name.') ';
72+
73+
$this->connection->execute($sql, array_values($col));
74+
}
75+
76+
/**
77+
* loads all policy rules from the storage.
78+
*
79+
* @param Model $model
80+
*/
81+
public function loadPolicy(Model $model): void
82+
{
83+
$rows = $this->connection->query('SELECT ptype, v0, v1, v2, v3, v4, v5 FROM '.$this->casbinRuleTableName.'');
84+
85+
foreach ($rows as $row) {
86+
$line = implode(', ', array_filter($row, function ($val) {
87+
return '' != $val && !is_null($val);
88+
}));
89+
$this->loadPolicyLine(trim($line), $model);
90+
}
91+
}
92+
4893
/**
4994
* Loads only policy rules that match the filter from storage.
5095
*
@@ -94,51 +139,6 @@ public function loadFilteredPolicy(Model $model, $filter): void
94139
$this->filtered = true;
95140
}
96141

97-
public static function newAdapter(array $config)
98-
{
99-
return new static($config);
100-
}
101-
102-
public function initTable()
103-
{
104-
$sql = file_get_contents(__DIR__.'/../migrations/'.$this->config['type'].'.sql');
105-
$sql = str_replace('%table_name%', $this->casbinRuleTableName, $sql);
106-
$this->connection->execute($sql, []);
107-
}
108-
109-
public function savePolicyLine($ptype, array $rule)
110-
{
111-
$col['ptype'] = $ptype;
112-
foreach ($rule as $key => $value) {
113-
$col['v'.strval($key).''] = $value;
114-
}
115-
116-
$colStr = implode(', ', array_keys($col));
117-
118-
$name = rtrim(str_repeat('?, ', count($col)), ', ');
119-
120-
$sql = 'INSERT INTO '.$this->casbinRuleTableName.'('.$colStr.') VALUES ('.$name.') ';
121-
122-
$this->connection->execute($sql, array_values($col));
123-
}
124-
125-
/**
126-
* loads all policy rules from the storage.
127-
*
128-
* @param Model $model
129-
*/
130-
public function loadPolicy(Model $model): void
131-
{
132-
$rows = $this->connection->query('SELECT ptype, v0, v1, v2, v3, v4, v5 FROM '.$this->casbinRuleTableName.'');
133-
134-
foreach ($rows as $row) {
135-
$line = implode(', ', array_filter($row, function ($val) {
136-
return '' != $val && !is_null($val);
137-
}));
138-
$this->loadPolicyLine(trim($line), $model);
139-
}
140-
}
141-
142142
/**
143143
* saves all policy rules to the storage.
144144
*

0 commit comments

Comments
 (0)