Service::instance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
declare (strict_types=1);
4
5
namespace dtapps\qiniu\sms;
6
7
use think\App;
8
use think\Container;
9
10
/**
11
 * 自定义服务基类
12
 * Class Service
13
 * @package asw
14
 */
15
abstract class Service
16
{
17
    /**
18
     * 应用实例
19
     * @var App
20
     */
21
    protected $app;
22
23
    /**
24
     * Service constructor.
25
     * @param App $app
26
     */
27
    public function __construct(App $app)
28
    {
29
        $this->app = $app;
30
        $this->initialize();
31
    }
32
33
    /**
34
     * 初始化服务
35
     * @return static
36
     */
37
    protected function initialize(): Service
38
    {
39
        return $this;
40
    }
41
42
    /**
43
     * 静态实例对象
44
     * @param array $var 实例参数
45
     * @param boolean $new 创建新实例
46
     * @return static
47
     */
48
    public static function instance(array $var = [], bool $new = false): Service
49
    {
50
        return Container::getInstance()->make(static::class, $var, $new);
51
    }
52
}