22
33namespace CasbinAdapter \Database ;
44
5+ use Casbin \Model \Model ;
56use Casbin \Persist \Adapter as AdapterContract ;
67use TechOne \Database \Manager ;
78use Casbin \Persist \AdapterHelper ;
@@ -56,7 +57,12 @@ public function savePolicyLine($ptype, array $rule)
5657 $ this ->connection ->execute ($ sql , array_values ($ col ));
5758 }
5859
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
6066 {
6167 $ rows = $ this ->connection ->query ('SELECT ptype, v0, v1, v2, v3, v4, v5 FROM ' .$ this ->casbinRuleTableName .'' );
6268
@@ -68,29 +74,47 @@ public function loadPolicy($model)
6874 }
6975 }
7076
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
7283 {
73- foreach ($ model-> model ['p ' ] as $ ptype => $ ast ) {
84+ foreach ($ model ['p ' ] as $ ptype => $ ast ) {
7485 foreach ($ ast ->policy as $ rule ) {
7586 $ this ->savePolicyLine ($ ptype , $ rule );
7687 }
7788 }
7889
79- foreach ($ model-> model ['g ' ] as $ ptype => $ ast ) {
90+ foreach ($ model ['g ' ] as $ ptype => $ ast ) {
8091 foreach ($ ast ->policy as $ rule ) {
8192 $ this ->savePolicyLine ($ ptype , $ rule );
8293 }
8394 }
84-
85- return true ;
8695 }
8796
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
89106 {
90- return $ this ->savePolicyLine ($ ptype , $ rule );
107+ $ this ->savePolicyLine ($ ptype , $ rule );
91108 }
92109
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
94118 {
95119 $ where ['ptype ' ] = $ ptype ;
96120 $ condition [] = 'ptype = :ptype ' ;
@@ -101,10 +125,19 @@ public function removePolicy($sec, $ptype, $rule)
101125
102126 $ sql = 'DELETE FROM ' .$ this ->casbinRuleTableName .' WHERE ' .implode (' AND ' , $ condition );
103127
104- return $ this ->connection ->execute ($ sql , $ where );
128+ $ this ->connection ->execute ($ sql , $ where );
105129 }
106130
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
108141 {
109142 $ where ['ptype ' ] = $ ptype ;
110143 $ condition [] = 'ptype = :ptype ' ;
@@ -119,6 +152,6 @@ public function removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues)
119152
120153 $ sql = 'DELETE FROM ' .$ this ->casbinRuleTableName .' WHERE ' .implode (' AND ' , $ condition );
121154
122- return $ this ->connection ->execute ($ sql , $ where );
155+ $ this ->connection ->execute ($ sql , $ where );
123156 }
124157}
0 commit comments