Passed
Push — 5.2 ( 897d87...7d4140 )
by liu
02:26
created

Facade::bind()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
// +----------------------------------------------------------------------
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
declare (strict_types = 1);
12
13
namespace think;
14
15
class Facade
1 ignored issue
show
Coding Style introduced by
Missing class doc comment
Loading history...
16
{
17
    /**
18
     * 始终创建新的对象实例
19
     * @var bool
20
     */
21
    protected static $alwaysNewInstance;
22
23
    /**
24
     * 创建Facade实例
25
     * @static
26
     * @access protected
27
     * @param  string    $class          类名或标识
0 ignored issues
show
Coding Style introduced by
Expected 7 spaces after parameter name; 10 found
Loading history...
28
     * @param  array     $args           变量
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter name; 11 found
Loading history...
29
     * @param  bool      $newInstance    是否每次创建新的实例
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
30
     * @return object
31
     */
32
    protected static function createFacade(string $class = '', array $args = [], bool $newInstance = false)
33
    {
34
        $class = $class ?: static::class;
35
36
        $facadeClass = static::getFacadeClass();
37
38
        if ($facadeClass) {
39
            $class = $facadeClass;
40
        }
41
42
        if (static::$alwaysNewInstance) {
43
            $newInstance = true;
44
        }
45
46
        return Container::getInstance()->make($class, $args, $newInstance);
47
    }
48
49
    /**
50
     * 获取当前Facade对应类名
51
     * @access protected
52
     * @return string
53
     */
54
    protected static function getFacadeClass()
55
    {}
0 ignored issues
show
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
56
57
    /**
0 ignored issues
show
Coding Style introduced by
Parameter ...$args should have a doc-comment as per coding-style.
Loading history...
58
     * 带参数实例化当前Facade类
59
     * @access public
60
     * @return object
61
     */
62
    public static function instance(...$args)
63
    {
64
        if (__CLASS__ != static::class) {
0 ignored issues
show
introduced by
The condition __CLASS__ != static::class is always false.
Loading history...
65
            return self::createFacade('', $args);
66
        }
67
    }
68
69
    /**
70
     * 调用类的实例
71
     * @access public
72
     * @param  string        $class          类名或者标识
0 ignored issues
show
Coding Style introduced by
Expected 7 spaces after parameter name; 10 found
Loading history...
73
     * @param  array|true    $args           变量
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter name; 11 found
Loading history...
74
     * @param  bool          $newInstance    是否每次创建新的实例
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
75
     * @return object
76
     */
77
    public static function make(string $class, $args = [], $newInstance = false)
78
    {
79
        if (__CLASS__ != static::class) {
0 ignored issues
show
introduced by
The condition __CLASS__ != static::class is always false.
Loading history...
80
            return self::__callStatic('make', func_get_args());
81
        }
82
83
        if (true === $args) {
84
            // 总是创建新的实例化对象
85
            $newInstance = true;
86
            $args        = [];
87
        }
88
89
        return self::createFacade($class, $args, $newInstance);
90
    }
91
92
    // 调用实际类的方法
93
    public static function __callStatic($method, $params)
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
94
    {
95
        return call_user_func_array([static::createFacade(), $method], $params);
96
    }
97
}
98