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

php-casbin / think-authz / 15025178114

14 May 2025 03:45PM UTC coverage: 92.667%. Remained the same
15025178114

push

github

web-flow
fix: delete without condition if cache disabled (#52)

1 of 1 new or added line in 1 file covered. (100.0%)

139 of 150 relevant lines covered (92.67%)

48.54 hits per line

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

90.48
/src/TauthzService.php
1
<?php
2

3
namespace tauthz;
4

5
use Casbin\Enforcer;
6
use Casbin\Model\Model;
7
use Casbin\Log\Log;
8
use Casbin\Log\Logger\DefaultLogger;
9
use think\Service;
10
use tauthz\command\Publish;
11

12
/**
13
 * Tauthz service.
14
 *
15
 * @author leeqvip@gmail.com
16
 */
17
class TauthzService extends Service
18
{
19
    /**
20
     * Register service.
21
     *
22
     * @return void
23
     */
24
    public function register()
25
    {
26
        // 注册数据迁移服务
27
        $this->app->register(\think\migration\Service::class);
117✔
28

29
        // 绑定 Casbin决策器
30
        $this->app->bind('enforcer', function () {
117✔
31
            $default = $this->app->config->get('tauthz.default');
108✔
32

33
            $config = $this->app->config->get('tauthz.enforcers.'.$default);
108✔
34
            $adapter = $config['adapter'];
108✔
35

36
            $configType = $config['model']['config_type'];
108✔
37

38
            $model = new Model();
108✔
39
            if ('file' == $configType) {
108✔
40
                $model->loadModel($config['model']['config_file_path']);
108✔
41
            } elseif ('text' == $configType) {
×
42
                $model->loadModel($config['model']['config_text']);
×
43
            }
44

45
            if ($logger = $this->app->config->get('tauthz.log.logger')) {
108✔
46
                if (is_string($logger)) {
108✔
47
                    $logger = new DefaultLogger($this->app->make($logger));
108✔
48
                }
49

50
                Log::setLogger($logger);
108✔
51
            }
52

53
            return new Enforcer($model, app($adapter), $logger, $this->app->config->get('tauthz.log.enabled', false));
108✔
54
        });
117✔
55
    }
56

57
    /**
58
     * Boot function.
59
     *
60
     * @return void
61
     */
62
    public function boot()
63
    {
64
        $this->mergeConfigFrom(__DIR__.'/../config/tauthz.php', 'tauthz');
117✔
65

66
        $this->commands(['tauthz:publish' => Publish::class]);
117✔
67
    }
68

69
    /**
70
     * Merge the given configuration with the existing configuration.
71
     *
72
     * @param string $path
73
     * @param string $key
74
     *
75
     * @return void
76
     */
77
    protected function mergeConfigFrom(string $path, string $key)
78
    {
79
        $config = $this->app->config->get($key, []);
117✔
80

81
        $this->app->config->set(array_merge(require $path, $config), $key);
117✔
82
    }
83
}
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