Passed
Push — v6 ( 515a76...c4922d )
by 光春
05:09
created

Helper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 49
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildQuery() 0 3 2
A instance() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
// +----------------------------------------------------------------------
4
// | ThinkLibrary 6.0 for ThinkPhP 6.0
5
// +----------------------------------------------------------------------
6
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
7
// +----------------------------------------------------------------------
8
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
9
// +----------------------------------------------------------------------
10
// | 开源协议 ( https://mit-license.org )
11
// +----------------------------------------------------------------------
12
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
13
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
14
// | gitlab 仓库地址 :https://gitlab.com/liguangchun/thinklibrary
15
// | weixin 仓库地址 :https://git.weixin.qq.com/liguangchun/ThinkLibrary
16
// | huaweicloud 仓库地址 :https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git
17
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
18
// +----------------------------------------------------------------------
19
20
declare (strict_types=1);
21
22
namespace DtApp\ThinkLibrary;
23
24
use think\App;
25
use think\Container;
26
use think\Db;
27
28
/**
29
 * 控制器挂件
30
 * Class Helper
31
 * @package DtApp\ThinkLibrary
32
 */
33
abstract class Helper
34
{
35
    /**
36
     * 应用容器
37
     * @var App
38
     */
39
    public $app;
40
41
    /**
42
     * 数据库实例
43
     * @var
44
     */
45
    public $query;
46
47
    /**
48
     * 控制器实例
49
     * @var Controller
50
     */
51
    public $class;
52
53
    /**
54
     * Helper constructor.
55
     * @param Controller $class
56
     * @param App $app
57
     */
58
    public function __construct(Controller $class, App $app)
59
    {
60
        $this->app = $app;
61
        $this->class = $class;
62
    }
63
64
    /**
65
     * 获取数据库对象
66
     * @param $dbQuery
67
     * @return Db
68
     */
69
    protected function buildQuery($dbQuery)
70
    {
71
        return is_string($dbQuery) ? $this->app->db->name($dbQuery) : $dbQuery;
72
    }
73
74
    /**
75
     * 实例对象反射
76
     * @param mixed ...$args
77
     * @return Helper
78
     */
79
    public static function instance(...$args): Helper
80
    {
81
        return Container::getInstance()->invokeClass(static::class, $args);
82
    }
83
}