Skip to content

Commit 68ee8df

Browse files
authored
Merge pull request #2 from basakest/upgrade
feat: upgrade dependencies
2 parents 1da5eb4 + 99defe2 commit 68ee8df

File tree

3 files changed

+74
-33
lines changed

3 files changed

+74
-33
lines changed

.github/workflows/build.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,44 @@ jobs:
2323
strategy:
2424
fail-fast: true
2525
matrix:
26-
php: [ 5.6, 7.0, 7.1, 7.2, 7.3]
27-
stability: [ prefer-lowest, prefer-stable ]
26+
# php: [ ]
27+
# medoo: [ ]
28+
# stability: [ prefer-lowest, prefer-stable ]
29+
include:
30+
# medoo 1.7
31+
- php: 7.1
32+
medoo: 1.7.*
33+
phpunit: ~7.0
34+
- php: 7.2
35+
medoo: 1.7.*
36+
phpunit: ~7.0
37+
- php: 7.3
38+
medoo: 1.7.*
39+
phpunit: ~7.0
2840

29-
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
41+
# medoo 2.0
42+
- php: 7.3
43+
medoo: 2.0.*
44+
phpunit: ~7.0
45+
- php: 7.4
46+
medoo: 2.0.*
47+
phpunit: ~7.0
48+
- php: 8.0
49+
medoo: 2.0.*
50+
phpunit: ~9.0
51+
52+
# medoo 2.1
53+
- php: 7.3
54+
medoo: 2.1.*
55+
phpunit: ~8.0
56+
- php: 7.4
57+
medoo: 2.1.*
58+
phpunit: ~8.0
59+
- php: 8.0
60+
medoo: 2.1.*
61+
phpunit: ~9.0
62+
63+
name: Medoo${{ matrix.medoo }}-PHP${{ matrix.php }}
3064

3165
steps:
3266
- name: Checkout code
@@ -46,7 +80,6 @@ jobs:
4680
if: steps.composer-cache.outputs.cache-hit != 'true'
4781
run: |
4882
composer install --prefer-dist --no-progress --no-suggest
49-
5083
- name: Run test suite
5184
run: ./vendor/bin/phpunit
5285

@@ -58,7 +91,6 @@ jobs:
5891
run: |
5992
composer global require php-coveralls/php-coveralls:^2.4
6093
php-coveralls --coverage_clover=build/logs/clover.xml -v
61-
6294
upload-coverage:
6395
runs-on: ubuntu-latest
6496
needs: [ test ]

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
],
1919
"license": "Apache-2.0",
2020
"require": {
21-
"casbin/casbin": "^1.0",
22-
"catfan/medoo": "^1.7"
21+
"php": ">=7.1.0",
22+
"casbin/casbin": "~3.1",
23+
"catfan/medoo": "~1.7|~2.0"
2324
},
2425
"require-dev": {
25-
"phpunit/phpunit": "~5.7|~6.0|~7.0",
26-
"php-coveralls/php-coveralls": "^2.1"
26+
"phpunit/phpunit": "~7.0|~8.0|~9.0",
27+
"php-coveralls/php-coveralls": "^2.4"
2728
},
2829
"autoload": {
2930
"psr-4": {
@@ -35,4 +36,4 @@
3536
"CasbinAdapter\\Medoo\\Tests\\": "tests/"
3637
}
3738
}
38-
}
39+
}

src/Adapter.php

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Adapter implements AdapterContract
3535
*
3636
* @param array $config
3737
*/
38-
public function __construct($config)
38+
public function __construct(array $config)
3939
{
4040
$database = new Medoo($config);
4141
$this->database = $database;
@@ -50,7 +50,7 @@ public function __construct($config)
5050
*
5151
* @return Adapter
5252
*/
53-
public static function newAdapter($config)
53+
public static function newAdapter(array $config)
5454
{
5555
return new static($config);
5656
}
@@ -73,22 +73,32 @@ public function initTable()
7373
]);
7474
}
7575

76-
public function savePolicyLine($ptype, array $rule)
76+
/**
77+
* savePolicyLine function.
78+
*
79+
* @param string $ptype
80+
* @param array $rule
81+
*
82+
* @return void
83+
*/
84+
public function savePolicyLine(string $ptype, array $rule): void
7785
{
7886
$data = [];
7987
foreach ($rule as $key => $value) {
80-
$data['v'.strval($key)] = $value;
88+
$data['v' . strval($key)] = $value;
8189
}
8290

83-
return $this->database->insert($this->casbinRuleTableName, $data);
91+
$this->database->insert($this->casbinRuleTableName, $data);
8492
}
8593

8694
/**
8795
* loads all policy rules from the storage.
8896
*
8997
* @param Model $model
98+
*
99+
* @return void
90100
*/
91-
public function loadPolicy($model)
101+
public function loadPolicy(Model $model): void
92102
{
93103
$data = $this->database->select($this->casbinRuleTableName, ['ptype', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5']);
94104
foreach ($data as $row) {
@@ -104,22 +114,20 @@ public function loadPolicy($model)
104114
*
105115
* @param Model $model
106116
*
107-
* @return bool
117+
* @return void
108118
*/
109-
public function savePolicy($model)
119+
public function savePolicy(Model $model): void
110120
{
111-
foreach ($model->model['p'] as $ptype => $ast) {
121+
foreach ($model['p'] as $ptype => $ast) {
112122
foreach ($ast->policy as $rule) {
113123
$this->savePolicyLine($ptype, $rule);
114124
}
115125
}
116-
foreach ($model->model['g'] as $ptype => $ast) {
126+
foreach ($model['g'] as $ptype => $ast) {
117127
foreach ($ast->policy as $rule) {
118128
$this->savePolicyLine($ptype, $rule);
119129
}
120130
}
121-
122-
return true;
123131
}
124132

125133
/**
@@ -130,11 +138,11 @@ public function savePolicy($model)
130138
* @param string $ptype
131139
* @param array $rule
132140
*
133-
* @return mixed
141+
* @return void
134142
*/
135-
public function addPolicy($sec, $ptype, $rule)
143+
public function addPolicy(string $sec, string $ptype, array $rule): void
136144
{
137-
return $this->savePolicyLine($ptype, $rule);
145+
$this->savePolicyLine($ptype, $rule);
138146
}
139147

140148
/**
@@ -144,17 +152,17 @@ public function addPolicy($sec, $ptype, $rule)
144152
* @param string $ptype
145153
* @param array $rule
146154
*
147-
* @return mixed
155+
* @return void
148156
*/
149-
public function removePolicy($sec, $ptype, $rule)
157+
public function removePolicy(string $sec, string $ptype, array $rule): void
150158
{
151159
$where['ptype'] = $ptype;
152160

153161
foreach ($rule as $key => $value) {
154162
$where['v'.strval($key)] = $value;
155163
}
156164

157-
return $this->database->delete($this->casbinRuleTableName, ['AND' => $where]);
165+
$this->database->delete($this->casbinRuleTableName, ['AND' => $where]);
158166
}
159167

160168
/**
@@ -163,12 +171,12 @@ public function removePolicy($sec, $ptype, $rule)
163171
*
164172
* @param string $sec
165173
* @param string $ptype
166-
* @param int $fieldIndex
167-
* @param mixed ...$fieldValues
174+
* @param int $fieldIndex
175+
* @param string ...$fieldValues
168176
*
169-
* @return mixed
177+
* @return void
170178
*/
171-
public function removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues)
179+
public function removeFilteredPolicy(string $sec, string $ptype, int $fieldIndex, string ...$fieldValues): void
172180
{
173181
$where['ptype'] = $ptype;
174182

@@ -180,7 +188,7 @@ public function removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues)
180188
}
181189
}
182190

183-
return $this->database->delete($this->casbinRuleTableName, ['AND' => $where]);
191+
$this->database->delete($this->casbinRuleTableName, ['AND' => $where]);
184192
}
185193

186194
/**

0 commit comments

Comments
 (0)