Passed
Push — master ( a325c0...46b506 )
by 世昌
02:20
created

DataAccess::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace suda\application\database;
3
4
use suda\orm\DataSource;
5
use suda\application\Application;
6
use suda\orm\middleware\Middleware;
7
8
/**
9
 * 数据表抽象对象
10
 *
11
 * 用于提供对数据表的操作
12
 *
13
 */
14
class DataAccess extends \suda\orm\DataAccess
15
{
16
    
17
18
    /**
19
     * 应用引用
20
     *
21
     * @var Application
22
     */
23
    protected static $application;
24
25
26
    /**
27
     * 创建对数据的操作
28
     *
29
     * @param string $object
30
     * @param Middleware|null $middleware
31
     */
32
    public function __construct(string $object, ?Middleware $middleware = null)
33
    {
34
        parent::__construct($object, static::$application->getDataSource(), $middleware);
35
    }
36
37
    /**
38
     * 从变量创建中间件
39
     *
40
     * @param object $object
41
     * @return DataAccess
42
     */
43
    public static function create($object):DataAccess
44
    {
45
        $middleware = null;
46
        if ($object instanceof Middleware) {
47
            $middleware = $object;
48
        }
49
        return new self(get_class($object), $middleware);
50
    }
51
52
    /**
53
     * 创建访问工具
54
     *
55
     * @param string $object
56
     * @param \suda\orm\middleware\Middleware|null $middleware
57
     * @return DataAccess
58
     */
59
    public static function new(string $object, ?Middleware $middleware = null):DataAccess
60
    {
61
        return new self($object, $middleware);
62
    }
63
64
    /**
65
     * 从应用创建表
66
     *
67
     * @param \suda\application\Application $application
68
     * @return void
69
     */
70
    public static function load(Application $application)
71
    {
72
        static::$application = $application;
73
    }
74
75
    /**
76
     * Get 应用引用
77
     *
78
     * @return  Application
79
     */
80
    public static function application()
81
    {
82
        return static::$application;
83
    }
84
}
85