@@ -35,7 +35,7 @@ public function __construct(array $config)
35
35
$ this ->initTable ();
36
36
}
37
37
38
- /**
38
+ /**
39
39
* Returns true if the loaded policy has been filtered.
40
40
*
41
41
* @return bool
@@ -45,6 +45,51 @@ public function isFiltered(): bool
45
45
return $ this ->filtered ;
46
46
}
47
47
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
+
48
93
/**
49
94
* Loads only policy rules that match the filter from storage.
50
95
*
@@ -94,51 +139,6 @@ public function loadFilteredPolicy(Model $model, $filter): void
94
139
$ this ->filtered = true ;
95
140
}
96
141
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
-
142
142
/**
143
143
* saves all policy rules to the storage.
144
144
*
0 commit comments