• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

php-casbin / codeigniter-permission / 12397367801

18 Dec 2024 04:37PM UTC coverage: 88.112%. Remained the same
12397367801

push

github

leeqvip
ci: update workflows

126 of 143 relevant lines covered (88.11%)

7.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.25
/src/Models/RuleModel.php
1
<?php
2

3
namespace Casbin\CodeIgniter\Models;
4

5
use CodeIgniter\Model;
6

7
class RuleModel extends Model
8
{
9
    protected $afterInsert = ['refreshCache'];
10

11
    protected $afterUpdate = ['refreshCache'];
12

13
    protected $afterDelete = ['refreshCache'];
14

15
    protected $cacheConfig = [
16
        'enabled' => false,
17
        'key' => 'rules',
18
        'ttl' => 24 * 60,
19
    ];
20

21
    protected $allowedFields = ['ptype', 'v0', 'v1', 'v2', 'v3', 'v4', 'v5'];
22

23
    /**
24
     * Gets rules from caches.
25
     *
26
     * @return mixed
27
     */
28
    public function getAllFromCache()
29
    {
30
        $get = function () {
3✔
31
            return $this->select('ptype, v0, v1, v2, v3, v4, v5')->findAll();
3✔
32
        };
3✔
33
        if (!($this->cacheConfig['enabled'] ?? false)) {
3✔
34
            return $get();
3✔
35
        }
36
        
37
        if (!$rules = cache($this->cacheConfig['key'])) {
×
38
            $rules = $get();
×
39
            cache()->save($this->cacheConfig['key'], $rules, $this->cacheConfig['ttl']);
×
40
        }
41

42
        return $rules;
×
43
    }
44

45
    /**
46
     * Refresh Cache.
47
     */
48
    protected function refreshCache(...$args)
49
    {
50
        if (!($this->cacheConfig['enabled'] ?? false)) {
12✔
51
            return;
12✔
52
        }
53

54
        $this->forgetCache();
×
55
        $this->getAllFromCache();
×
56
    }
57

58
    /**
59
     * Forget Cache.
60
     */
61
    public function forgetCache()
62
    {
63
        cache()->delete($this->cacheConfig['key']);
×
64
    }
65

66
    /**
67
     * sets cacheConfig.
68
     *
69
     * @param array $cacheConfig
70
     *
71
     * @return void
72
     */
73
    public function setCacheConfig(array $cacheConfig = [])
74
    {
75
        if ($cacheConfig) {
3✔
76
            $this->cacheConfig = $cacheConfig;
3✔
77
        }
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc