1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Casbin; |
6
|
|
|
|
7
|
|
|
use Casbin\Exceptions\NotImplementedException; |
8
|
|
|
use Casbin\Log\Log; |
9
|
|
|
use Casbin\Model\Policy; |
10
|
|
|
use Casbin\Persist\BatchAdapter; |
11
|
|
|
use Casbin\Persist\UpdatableAdapter; |
12
|
|
|
use Casbin\Persist\WatcherEx; |
13
|
|
|
use Casbin\Persist\WatcherUpdatable; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* InternalEnforcer = CoreEnforcer + Internal API. |
17
|
|
|
* |
18
|
|
|
* @author [email protected] |
|
|
|
|
19
|
|
|
*/ |
|
|
|
|
20
|
|
|
class InternalEnforcer extends CoreEnforcer |
21
|
|
|
{ |
22
|
|
|
/** |
|
|
|
|
23
|
|
|
* @return bool |
24
|
|
|
*/ |
25
|
99 |
|
protected function shouldPersist(): bool |
26
|
|
|
{ |
27
|
99 |
|
return !is_null($this->adapter) && $this->autoSave; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
|
|
|
|
31
|
|
|
* @return bool |
32
|
|
|
*/ |
33
|
96 |
|
protected function shouldNotify(): bool |
34
|
|
|
{ |
35
|
96 |
|
return !is_null($this->watcher) && $this->autoNotifyWatcher; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Adds a rule to the current policy without notify. |
40
|
|
|
* |
41
|
|
|
* @param string $sec |
|
|
|
|
42
|
|
|
* @param string $ptype |
|
|
|
|
43
|
|
|
* @param array $rule |
|
|
|
|
44
|
|
|
* |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
48 |
|
protected function addPolicyWithoutNotifyInternal(string $sec, string $ptype, array $rule): bool |
48
|
|
|
{ |
49
|
48 |
|
if ($this->model->hasPolicy($sec, $ptype, $rule)) { |
50
|
3 |
|
return false; |
51
|
|
|
} |
52
|
|
|
|
53
|
48 |
|
if ($this->shouldPersist()) { |
54
|
|
|
try { |
55
|
45 |
|
$this->adapter->addPolicy($sec, $ptype, $rule); |
56
|
45 |
|
} catch (NotImplementedException $e) { |
|
|
|
|
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
48 |
|
$this->model->addPolicy($sec, $ptype, $rule); |
61
|
|
|
|
62
|
48 |
|
if ($sec == "g") { |
63
|
21 |
|
$this->buildIncrementalRoleLinks(Policy::POLICY_ADD, $ptype, [$rule]); |
64
|
|
|
} |
65
|
|
|
|
66
|
48 |
|
return true; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Adds rules to the current policy without notify. |
71
|
|
|
* If autoRemoveRepeat == true, existing rules are automatically filtered |
72
|
|
|
* Otherwise, false is returned directly. |
73
|
|
|
* |
74
|
|
|
* @param string $sec |
|
|
|
|
75
|
|
|
* @param string $ptype |
|
|
|
|
76
|
|
|
* @param array $rules |
|
|
|
|
77
|
|
|
* @param bool $autoRemoveRepeat |
|
|
|
|
78
|
|
|
* |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
27 |
|
protected function addPoliciesWithoutNotifyInternal(string $sec, string $ptype, array $rules, bool $autoRemoveRepeat): bool |
82
|
|
|
{ |
83
|
27 |
|
if (!$autoRemoveRepeat) { |
84
|
27 |
|
if ($this->model->hasPolicies($sec, $ptype, $rules)) { |
85
|
9 |
|
return false; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
27 |
|
if ($this->shouldPersist() && $this->adapter instanceof BatchAdapter) { |
90
|
|
|
try { |
91
|
27 |
|
$this->adapter->addPolicies($sec, $ptype, $rules); |
92
|
21 |
|
} catch (NotImplementedException $e) { |
|
|
|
|
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
27 |
|
$this->model->addPolicies($sec, $ptype, $rules); |
97
|
|
|
|
98
|
27 |
|
if ($sec == "g") { |
99
|
6 |
|
$this->buildIncrementalRoleLinks(Policy::POLICY_ADD, $ptype, $rules); |
100
|
|
|
} |
101
|
|
|
|
102
|
27 |
|
return true; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Updates a rule from the current policy without notify. |
107
|
|
|
* |
108
|
|
|
* @param string $sec |
|
|
|
|
109
|
|
|
* @param string $ptype |
|
|
|
|
110
|
|
|
* @param array $oldRule |
|
|
|
|
111
|
|
|
* @param array $newRule |
|
|
|
|
112
|
|
|
* |
113
|
|
|
* @return bool |
114
|
|
|
*/ |
115
|
3 |
|
protected function updatePolicyWithoutNotifyInternal(string $sec, string $ptype, array $oldRule, array $newRule): bool |
116
|
|
|
{ |
117
|
3 |
|
if ($this->shouldPersist() && $this->adapter instanceof UpdatableAdapter) { |
118
|
|
|
try { |
119
|
3 |
|
$this->adapter->updatePolicy($sec, $ptype, $oldRule, $newRule); |
120
|
3 |
|
} catch (NotImplementedException $e) { |
|
|
|
|
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
3 |
|
$ruleUpdated = $this->model->updatePolicy($sec, $ptype, $oldRule, $newRule); |
125
|
3 |
|
if (!$ruleUpdated) { |
126
|
|
|
return false; |
127
|
|
|
} |
128
|
|
|
|
129
|
3 |
|
if ($sec == "g") { |
130
|
|
|
// remove the old rule |
131
|
|
|
$this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, [$oldRule]); |
132
|
|
|
|
133
|
|
|
// add the new rule |
134
|
|
|
$this->buildIncrementalRoleLinks(Policy::POLICY_ADD, $ptype, [$newRule]); |
135
|
|
|
} |
136
|
|
|
|
137
|
3 |
|
return true; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Updates rules from the current policy without notify. |
142
|
|
|
* |
143
|
|
|
* @param string $sec |
|
|
|
|
144
|
|
|
* @param string $ptype |
|
|
|
|
145
|
|
|
* @param array $oldRules |
|
|
|
|
146
|
|
|
* @param array $newRules |
|
|
|
|
147
|
|
|
* |
148
|
|
|
* @return bool |
149
|
|
|
*/ |
150
|
3 |
|
protected function updatePoliciesWithoutNotifyInternal(string $sec, string $ptype, array $oldRules, array $newRules): bool |
151
|
|
|
{ |
152
|
3 |
|
if ($this->shouldPersist() && $this->adapter instanceof UpdatableAdapter) { |
153
|
|
|
try { |
154
|
3 |
|
$this->adapter->updatePolicies($sec, $ptype, $oldRules, $newRules); |
155
|
3 |
|
} catch (NotImplementedException $e) { |
|
|
|
|
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
3 |
|
$ruleUpdated = $this->model->updatePolicies($sec, $ptype, $oldRules, $newRules); |
160
|
3 |
|
if (!$ruleUpdated) { |
161
|
3 |
|
return false; |
162
|
|
|
} |
163
|
|
|
|
164
|
3 |
|
if ($sec == "g") { |
165
|
|
|
// remove the old rule |
166
|
|
|
$this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, $oldRules); |
167
|
|
|
|
168
|
|
|
// add the new rule |
169
|
|
|
$this->buildIncrementalRoleLinks(Policy::POLICY_ADD, $ptype, $newRules); |
170
|
|
|
} |
171
|
|
|
|
172
|
3 |
|
return true; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Removes a rule from the current policy without notify. |
177
|
|
|
* |
178
|
|
|
* @param string $sec |
|
|
|
|
179
|
|
|
* @param string $ptype |
|
|
|
|
180
|
|
|
* @param array $rule |
|
|
|
|
181
|
|
|
* |
182
|
|
|
* @return bool |
183
|
|
|
*/ |
184
|
33 |
|
protected function removePolicyWithoutNotifyInternal(string $sec, string $ptype, array $rule): bool |
185
|
|
|
{ |
186
|
33 |
|
if ($this->shouldPersist()) { |
187
|
|
|
try { |
188
|
33 |
|
$this->adapter->removePolicy($sec, $ptype, $rule); |
189
|
33 |
|
} catch (NotImplementedException $e) { |
|
|
|
|
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
193
|
33 |
|
$ruleRemoved = $this->model->removePolicy($sec, $ptype, $rule); |
194
|
33 |
|
if (!$ruleRemoved) { |
195
|
3 |
|
return false; |
196
|
|
|
} |
197
|
|
|
|
198
|
33 |
|
if ($sec == "g") { |
199
|
18 |
|
$this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, [$rule]); |
200
|
|
|
} |
201
|
|
|
|
202
|
33 |
|
return true; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Removes rules from the current policy without notify. |
207
|
|
|
* |
208
|
|
|
* @param string $sec |
|
|
|
|
209
|
|
|
* @param string $ptype |
|
|
|
|
210
|
|
|
* @param array $rules |
|
|
|
|
211
|
|
|
* |
212
|
|
|
* @return bool |
213
|
|
|
*/ |
214
|
15 |
|
protected function removePoliciesWithoutNotifyInternal(string $sec, string $ptype, array $rules): bool |
215
|
|
|
{ |
216
|
15 |
|
if (!$this->model->hasPolicies($sec, $ptype, $rules)) { |
217
|
6 |
|
return false; |
218
|
|
|
} |
219
|
|
|
|
220
|
15 |
|
if ($this->shouldPersist() && $this->adapter instanceof BatchAdapter) { |
221
|
|
|
try { |
222
|
15 |
|
$this->adapter->removePolicies($sec, $ptype, $rules); |
223
|
15 |
|
} catch (NotImplementedException $e) { |
|
|
|
|
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
227
|
15 |
|
$ruleRemoved = $this->model->removePolicies($sec, $ptype, $rules); |
228
|
15 |
|
if (!$ruleRemoved) { |
229
|
|
|
return false; |
230
|
|
|
} |
231
|
|
|
|
232
|
15 |
|
if ($sec == "g") { |
233
|
12 |
|
$this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, $rules); |
234
|
|
|
} |
235
|
|
|
|
236
|
15 |
|
return true; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Removes rules based on field filters from the current policy without notify. |
241
|
|
|
* |
242
|
|
|
* @param string $sec |
|
|
|
|
243
|
|
|
* @param string $ptype |
|
|
|
|
244
|
|
|
* @param int $fieldIndex |
|
|
|
|
245
|
|
|
* @param string ...$fieldValues |
|
|
|
|
246
|
|
|
* |
247
|
|
|
* @return bool |
248
|
|
|
*/ |
249
|
24 |
|
protected function removeFilteredPolicyWithoutNotifyInternal(string $sec, string $ptype, int $fieldIndex, string ...$fieldValues): bool |
250
|
|
|
{ |
251
|
24 |
|
if ($this->shouldPersist()) { |
252
|
|
|
try { |
253
|
24 |
|
$this->adapter->removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues); |
254
|
24 |
|
} catch (NotImplementedException $e) { |
|
|
|
|
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
24 |
|
$ruleRemoved = $this->model->removeFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues); |
259
|
24 |
|
if (!$ruleRemoved) { |
|
|
|
|
260
|
|
|
return false; |
261
|
|
|
} |
262
|
|
|
|
263
|
24 |
|
if ($sec == "g") { |
264
|
12 |
|
$this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, $ruleRemoved); |
265
|
|
|
} |
266
|
|
|
|
267
|
24 |
|
return true; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Updates rules based on field filters from the current policy without notify. |
272
|
|
|
* |
273
|
|
|
* @param string $sec |
|
|
|
|
274
|
|
|
* @param string $ptype |
|
|
|
|
275
|
|
|
* @param array $newRules |
|
|
|
|
276
|
|
|
* @param int $fieldIndex |
|
|
|
|
277
|
|
|
* @param string ...$fieldValues |
|
|
|
|
278
|
|
|
* |
279
|
|
|
* @return array |
280
|
|
|
*/ |
281
|
6 |
|
protected function updateFilteredPoliciesWithoutNotifyInternal(string $sec, string $ptype, array $newRules, int $fieldIndex, string ...$fieldValues): array |
282
|
|
|
{ |
283
|
6 |
|
$oldRules = []; |
284
|
6 |
|
if ($this->shouldPersist()) { |
285
|
|
|
try { |
286
|
6 |
|
if ($this->adapter instanceof UpdatableAdapter) { |
287
|
6 |
|
$oldRules = $this->adapter->updateFilteredPolicies($sec, $ptype, $newRules, $fieldIndex, ...$fieldValues); |
288
|
|
|
} |
289
|
3 |
|
} catch (NotImplementedException $e) { |
|
|
|
|
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|
293
|
6 |
|
$ruleChanged = $this->model->removePolicies($sec, $ptype, $oldRules); |
294
|
6 |
|
$this->model->addPolicies($sec, $ptype, $newRules); |
295
|
|
|
|
296
|
6 |
|
$ruleChanged = $ruleChanged && count($newRules) !== 0; |
297
|
6 |
|
if (!$ruleChanged) { |
298
|
3 |
|
return []; |
299
|
|
|
} |
300
|
|
|
|
301
|
6 |
|
if ($sec == "g") { |
302
|
|
|
// remove the old rules |
303
|
|
|
$this->buildIncrementalRoleLinks(Policy::POLICY_REMOVE, $ptype, $oldRules); |
304
|
|
|
// add the new rules |
305
|
|
|
$this->buildIncrementalRoleLinks(Policy::POLICY_ADD, $ptype, $newRules); |
306
|
|
|
} |
307
|
|
|
|
308
|
6 |
|
return $oldRules; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Adds a rule to the current policy. |
313
|
|
|
* |
314
|
|
|
* @param string $sec |
|
|
|
|
315
|
|
|
* @param string $ptype |
|
|
|
|
316
|
|
|
* @param array $rule |
|
|
|
|
317
|
|
|
* |
318
|
|
|
* @return bool |
319
|
|
|
*/ |
320
|
48 |
|
protected function addPolicyInternal(string $sec, string $ptype, array $rule): bool |
321
|
|
|
{ |
322
|
48 |
|
if (!$this->addPolicyWithoutNotifyInternal($sec, $ptype, $rule)) { |
323
|
3 |
|
return false; |
324
|
|
|
} |
325
|
|
|
|
326
|
48 |
|
if ($this->shouldNotify()) { |
327
|
3 |
|
if ($this->watcher instanceof WatcherEx) { |
328
|
|
|
$this->watcher->updateForAddPolicy($sec, $ptype, ...$rule); |
329
|
|
|
} else { |
330
|
3 |
|
$this->watcher->update(); |
331
|
|
|
} |
332
|
|
|
} |
333
|
|
|
|
334
|
48 |
|
return true; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
|
|
|
|
338
|
|
|
* Adds rules to the current policy. |
339
|
|
|
* |
340
|
|
|
* @param string $sec |
|
|
|
|
341
|
|
|
* @param string $ptype |
|
|
|
|
342
|
|
|
* @param array $rules |
|
|
|
|
343
|
|
|
* |
344
|
|
|
* @return bool |
345
|
|
|
* @throws Exceptions\CasbinException |
346
|
|
|
*/ |
347
|
24 |
|
protected function addPoliciesInternal(string $sec, string $ptype, array $rules, bool $autoRemoveRepeat): bool |
348
|
|
|
{ |
349
|
24 |
|
if (!$this->addPoliciesWithoutNotifyInternal($sec, $ptype, $rules, $autoRemoveRepeat)) { |
350
|
9 |
|
return false; |
351
|
|
|
} |
352
|
|
|
|
353
|
24 |
|
if ($this->shouldNotify()) { |
354
|
|
|
$this->watcher->update(); |
355
|
|
|
} |
356
|
|
|
|
357
|
24 |
|
return true; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Updates a rule from the current policy. |
362
|
|
|
* |
363
|
|
|
* @param string $sec |
|
|
|
|
364
|
|
|
* @param string $ptype |
|
|
|
|
365
|
|
|
* @param string[] $oldRule |
|
|
|
|
366
|
|
|
* @param string[] $newRule |
|
|
|
|
367
|
|
|
* |
368
|
|
|
* @return bool |
369
|
|
|
*/ |
370
|
3 |
|
protected function updatePolicyInternal(string $sec, string $ptype, array $oldRule, array $newRule): bool |
371
|
|
|
{ |
372
|
3 |
|
if (!$this->updatePolicyWithoutNotifyInternal($sec, $ptype, $oldRule, $newRule)) { |
373
|
|
|
return false; |
374
|
|
|
} |
375
|
|
|
|
376
|
3 |
|
if ($this->shouldNotify()) { |
377
|
|
|
try { |
378
|
|
|
if ($this->watcher instanceof WatcherUpdatable) { |
379
|
|
|
$this->watcher->updateForUpdatePolicy($oldRule, $newRule); |
380
|
|
|
} else { |
381
|
|
|
$this->watcher->update(); |
382
|
|
|
} |
383
|
|
|
} catch (\Exception $e) { |
384
|
|
|
Log::logPrint("An exception occurred:" . $e->getMessage()); |
385
|
|
|
return false; |
386
|
|
|
} |
387
|
|
|
} |
388
|
|
|
|
389
|
3 |
|
return true; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Updates rules from the current policy. |
394
|
|
|
* |
395
|
|
|
* @param string $sec |
|
|
|
|
396
|
|
|
* @param string $ptype |
|
|
|
|
397
|
|
|
* @param string[][] $oldRules |
|
|
|
|
398
|
|
|
* @param string[][] $newRules |
|
|
|
|
399
|
|
|
* |
400
|
|
|
* @return bool |
401
|
|
|
*/ |
402
|
3 |
|
protected function updatePoliciesInternal(string $sec, string $ptype, array $oldRules, array $newRules): bool |
403
|
|
|
{ |
404
|
3 |
|
if (!$this->updatePoliciesWithoutNotifyInternal($sec, $ptype, $oldRules, $newRules)) { |
405
|
3 |
|
return false; |
406
|
|
|
} |
407
|
|
|
|
408
|
3 |
|
if ($this->shouldNotify()) { |
409
|
|
|
try { |
410
|
3 |
|
if ($this->watcher instanceof WatcherUpdatable) { |
411
|
3 |
|
$this->watcher->updateForUpdatePolicies($oldRules, $newRules); |
412
|
|
|
} else { |
413
|
3 |
|
$this->watcher->update(); |
414
|
|
|
} |
415
|
3 |
|
} catch (\Exception $e) { |
416
|
3 |
|
Log::logPrint("An exception occurred:" . $e->getMessage()); |
417
|
3 |
|
return false; |
418
|
|
|
} |
419
|
|
|
} |
420
|
|
|
|
421
|
3 |
|
return true; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Removes a rule from the current policy. |
426
|
|
|
* |
427
|
|
|
* @param string $sec |
|
|
|
|
428
|
|
|
* @param string $ptype |
|
|
|
|
429
|
|
|
* @param array $rule |
|
|
|
|
430
|
|
|
* |
431
|
|
|
* @return bool |
432
|
|
|
*/ |
433
|
33 |
|
protected function removePolicyInternal(string $sec, string $ptype, array $rule): bool |
434
|
|
|
{ |
435
|
33 |
|
if (!$this->removePolicyWithoutNotifyInternal($sec, $ptype, $rule)) { |
436
|
3 |
|
return false; |
437
|
|
|
} |
438
|
|
|
|
439
|
33 |
|
if ($this->shouldNotify()) { |
440
|
|
|
if ($this->watcher instanceof WatcherEx) { |
441
|
|
|
$this->watcher->updateForRemovePolicy($sec, $ptype, ...$rule); |
442
|
|
|
} else { |
443
|
|
|
$this->watcher->update(); |
444
|
|
|
} |
445
|
|
|
} |
446
|
|
|
|
447
|
33 |
|
return true; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Removes a rules from the current policy. |
452
|
|
|
* |
453
|
|
|
* @param string $sec |
|
|
|
|
454
|
|
|
* @param string $ptype |
|
|
|
|
455
|
|
|
* @param array $rules |
|
|
|
|
456
|
|
|
* |
457
|
|
|
* @return bool |
458
|
|
|
*/ |
459
|
15 |
|
protected function removePoliciesInternal(string $sec, string $ptype, array $rules): bool |
460
|
|
|
{ |
461
|
15 |
|
if (!$this->removePoliciesWithoutNotifyInternal($sec, $ptype, $rules)) { |
462
|
6 |
|
return false; |
463
|
|
|
} |
464
|
|
|
|
465
|
15 |
|
if ($this->shouldNotify()) { |
466
|
|
|
// error intentionally ignored |
467
|
|
|
$this->watcher->update(); |
468
|
|
|
} |
469
|
|
|
|
470
|
15 |
|
return true; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* Removes rules based on field filters from the current policy. |
475
|
|
|
* |
476
|
|
|
* @param string $sec |
|
|
|
|
477
|
|
|
* @param string $ptype |
|
|
|
|
478
|
|
|
* @param int $fieldIndex |
|
|
|
|
479
|
|
|
* @param string ...$fieldValues |
|
|
|
|
480
|
|
|
* |
481
|
|
|
* @return bool |
482
|
|
|
*/ |
483
|
24 |
|
protected function removeFilteredPolicyInternal(string $sec, string $ptype, int $fieldIndex, string ...$fieldValues): bool |
484
|
|
|
{ |
485
|
24 |
|
if (!$this->removeFilteredPolicyWithoutNotifyInternal($sec, $ptype, $fieldIndex, ...$fieldValues)) { |
486
|
|
|
return false; |
487
|
|
|
} |
488
|
|
|
|
489
|
24 |
|
if ($this->shouldNotify()) { |
490
|
|
|
// error intentionally ignored |
491
|
|
|
if ($this->watcher instanceof WatcherEx) { |
492
|
|
|
$this->watcher->updateForRemoveFilteredPolicy($sec, $ptype, $fieldIndex, ...$fieldValues); |
493
|
|
|
} else { |
494
|
|
|
$this->watcher->update(); |
495
|
|
|
} |
496
|
|
|
} |
497
|
|
|
|
498
|
24 |
|
return true; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* Removes rules based on field filters from the current policy. |
503
|
|
|
* |
504
|
|
|
* @param string $sec |
|
|
|
|
505
|
|
|
* @param string $ptype |
|
|
|
|
506
|
|
|
* @param array $newRules |
|
|
|
|
507
|
|
|
* @param int $fieldIndex |
|
|
|
|
508
|
|
|
* @param string ...$fieldValues |
|
|
|
|
509
|
|
|
* |
510
|
|
|
* @return bool |
511
|
|
|
*/ |
512
|
6 |
|
protected function updateFilteredPoliciesInternal(string $sec, string $ptype, array $newRules, int $fieldIndex, string ...$fieldValues): bool |
513
|
|
|
{ |
514
|
6 |
|
$oldRules = $this->updateFilteredPoliciesWithoutNotifyInternal($sec, $ptype, $newRules, $fieldIndex, ...$fieldValues); |
515
|
6 |
|
if(count($oldRules) === 0) { |
|
|
|
|
516
|
3 |
|
return false; |
517
|
|
|
} |
518
|
|
|
|
519
|
6 |
|
if ($this->shouldNotify()) { |
520
|
|
|
// error intentionally ignored |
521
|
3 |
|
if ($this->watcher instanceof WatcherUpdatable) { |
522
|
3 |
|
$this->watcher->updateForUpdatePolicies($oldRules, $newRules); |
523
|
|
|
} else { |
524
|
3 |
|
$this->watcher->update(); |
525
|
|
|
} |
526
|
3 |
|
return true; |
527
|
|
|
} |
528
|
|
|
|
529
|
3 |
|
return true; |
530
|
|
|
} |
531
|
|
|
} |
532
|
|
|
|