3
3
namespace tauthz \adapter ;
4
4
5
5
use tauthz \model \Rule ;
6
+ use Casbin \Model \Model ;
6
7
use Casbin \Persist \Adapter ;
7
8
use Casbin \Persist \AdapterHelper ;
8
9
@@ -53,15 +54,13 @@ public function savePolicyLine($ptype, array $rule)
53
54
* loads all policy rules from the storage.
54
55
*
55
56
* @param Model $model
56
- *
57
- * @return mixed
58
57
*/
59
- public function loadPolicy ($ model )
58
+ public function loadPolicy (Model $ model ): void
60
59
{
61
60
$ rows = $ this ->model ->select ()->toArray ();
62
61
foreach ($ rows as $ row ) {
63
- $ line = implode (', ' , array_filter (array_slice ($ row , 1 ),function ($ val ){
64
- return $ val != "" && !is_null ($ val );
62
+ $ line = implode (', ' , array_filter (array_slice ($ row , 1 ), function ($ val ) {
63
+ return '' != $ val && !is_null ($ val );
65
64
}));
66
65
$ this ->loadPolicyLine (trim ($ line ), $ model );
67
66
}
@@ -71,39 +70,33 @@ public function loadPolicy($model)
71
70
* saves all policy rules to the storage.
72
71
*
73
72
* @param Model $model
74
- *
75
- * @return bool
76
73
*/
77
- public function savePolicy ($ model )
74
+ public function savePolicy (Model $ model ): void
78
75
{
79
- foreach ($ model-> model ['p ' ] as $ ptype => $ ast ) {
76
+ foreach ($ model ['p ' ] as $ ptype => $ ast ) {
80
77
foreach ($ ast ->policy as $ rule ) {
81
78
$ this ->savePolicyLine ($ ptype , $ rule );
82
79
}
83
80
}
84
81
85
- foreach ($ model-> model ['g ' ] as $ ptype => $ ast ) {
82
+ foreach ($ model ['g ' ] as $ ptype => $ ast ) {
86
83
foreach ($ ast ->policy as $ rule ) {
87
84
$ this ->savePolicyLine ($ ptype , $ rule );
88
85
}
89
86
}
90
-
91
- return true ;
92
87
}
93
88
94
89
/**
95
- * Adds a policy rule to the storage.
90
+ * adds a policy rule to the storage.
96
91
* This is part of the Auto-Save feature.
97
92
*
98
93
* @param string $sec
99
94
* @param string $ptype
100
95
* @param array $rule
101
- *
102
- * @return mixed
103
96
*/
104
- public function addPolicy ($ sec , $ ptype , $ rule )
97
+ public function addPolicy (string $ sec , string $ ptype , array $ rule ): void
105
98
{
106
- return $ this ->savePolicyLine ($ ptype , $ rule );
99
+ $ this ->savePolicyLine ($ ptype , $ rule );
107
100
}
108
101
109
102
/**
@@ -112,10 +105,8 @@ public function addPolicy($sec, $ptype, $rule)
112
105
* @param string $sec
113
106
* @param string $ptype
114
107
* @param array $rule
115
- *
116
- * @return mixed
117
108
*/
118
- public function removePolicy ($ sec , $ ptype , $ rule )
109
+ public function removePolicy (string $ sec , string $ ptype , array $ rule ): void
119
110
{
120
111
$ count = 0 ;
121
112
@@ -130,8 +121,6 @@ public function removePolicy($sec, $ptype, $rule)
130
121
++$ count ;
131
122
}
132
123
}
133
-
134
- return $ count ;
135
124
}
136
125
137
126
/**
@@ -141,11 +130,9 @@ public function removePolicy($sec, $ptype, $rule)
141
130
* @param string $sec
142
131
* @param string $ptype
143
132
* @param int $fieldIndex
144
- * @param mixed ...$fieldValues
145
- *
146
- * @return mixed
133
+ * @param string ...$fieldValues
147
134
*/
148
- public function removeFilteredPolicy ($ sec , $ ptype , $ fieldIndex , ...$ fieldValues )
135
+ public function removeFilteredPolicy (string $ sec , string $ ptype , int $ fieldIndex , string ...$ fieldValues ): void
149
136
{
150
137
$ count = 0 ;
151
138
@@ -163,7 +150,5 @@ public function removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues)
163
150
++$ count ;
164
151
}
165
152
}
166
-
167
- return $ count ;
168
153
}
169
154
}
0 commit comments