2
2
3
3
namespace CasbinAdapter \Database ;
4
4
5
+ use Casbin \Model \Model ;
5
6
use Casbin \Persist \Adapter as AdapterContract ;
6
7
use TechOne \Database \Manager ;
7
8
use Casbin \Persist \AdapterHelper ;
@@ -56,7 +57,12 @@ public function savePolicyLine($ptype, array $rule)
56
57
$ this ->connection ->execute ($ sql , array_values ($ col ));
57
58
}
58
59
59
- public function loadPolicy ($ model )
60
+ /**
61
+ * loads all policy rules from the storage.
62
+ *
63
+ * @param Model $model
64
+ */
65
+ public function loadPolicy (Model $ model ): void
60
66
{
61
67
$ rows = $ this ->connection ->query ('SELECT ptype, v0, v1, v2, v3, v4, v5 FROM ' .$ this ->casbinRuleTableName .'' );
62
68
@@ -68,29 +74,47 @@ public function loadPolicy($model)
68
74
}
69
75
}
70
76
71
- public function savePolicy ($ model )
77
+ /**
78
+ * saves all policy rules to the storage.
79
+ *
80
+ * @param Model $model
81
+ */
82
+ public function savePolicy (Model $ model ): void
72
83
{
73
- foreach ($ model-> model ['p ' ] as $ ptype => $ ast ) {
84
+ foreach ($ model ['p ' ] as $ ptype => $ ast ) {
74
85
foreach ($ ast ->policy as $ rule ) {
75
86
$ this ->savePolicyLine ($ ptype , $ rule );
76
87
}
77
88
}
78
89
79
- foreach ($ model-> model ['g ' ] as $ ptype => $ ast ) {
90
+ foreach ($ model ['g ' ] as $ ptype => $ ast ) {
80
91
foreach ($ ast ->policy as $ rule ) {
81
92
$ this ->savePolicyLine ($ ptype , $ rule );
82
93
}
83
94
}
84
-
85
- return true ;
86
95
}
87
96
88
- public function addPolicy ($ sec , $ ptype , $ rule )
97
+ /**
98
+ * adds a policy rule to the storage.
99
+ * This is part of the Auto-Save feature.
100
+ *
101
+ * @param string $sec
102
+ * @param string $ptype
103
+ * @param array $rule
104
+ */
105
+ public function addPolicy (string $ sec , string $ ptype , array $ rule ): void
89
106
{
90
- return $ this ->savePolicyLine ($ ptype , $ rule );
107
+ $ this ->savePolicyLine ($ ptype , $ rule );
91
108
}
92
109
93
- public function removePolicy ($ sec , $ ptype , $ rule )
110
+ /**
111
+ * This is part of the Auto-Save feature.
112
+ *
113
+ * @param string $sec
114
+ * @param string $ptype
115
+ * @param array $rule
116
+ */
117
+ public function removePolicy (string $ sec , string $ ptype , array $ rule ): void
94
118
{
95
119
$ where ['ptype ' ] = $ ptype ;
96
120
$ condition [] = 'ptype = :ptype ' ;
@@ -101,10 +125,19 @@ public function removePolicy($sec, $ptype, $rule)
101
125
102
126
$ sql = 'DELETE FROM ' .$ this ->casbinRuleTableName .' WHERE ' .implode (' AND ' , $ condition );
103
127
104
- return $ this ->connection ->execute ($ sql , $ where );
128
+ $ this ->connection ->execute ($ sql , $ where );
105
129
}
106
130
107
- public function removeFilteredPolicy ($ sec , $ ptype , $ fieldIndex , ...$ fieldValues )
131
+ /**
132
+ * RemoveFilteredPolicy removes policy rules that match the filter from the storage.
133
+ * This is part of the Auto-Save feature.
134
+ *
135
+ * @param string $sec
136
+ * @param string $ptype
137
+ * @param int $fieldIndex
138
+ * @param string ...$fieldValues
139
+ */
140
+ public function removeFilteredPolicy (string $ sec , string $ ptype , int $ fieldIndex , string ...$ fieldValues ): void
108
141
{
109
142
$ where ['ptype ' ] = $ ptype ;
110
143
$ condition [] = 'ptype = :ptype ' ;
@@ -119,6 +152,6 @@ public function removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues)
119
152
120
153
$ sql = 'DELETE FROM ' .$ this ->casbinRuleTableName .' WHERE ' .implode (' AND ' , $ condition );
121
154
122
- return $ this ->connection ->execute ($ sql , $ where );
155
+ $ this ->connection ->execute ($ sql , $ where );
123
156
}
124
157
}
0 commit comments