Passed
Push — master ( f9244b...ce4141 )
by 世昌
02:39 queued 14s
created

Table::isSubOf()   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\database\TableAccess;
5
use suda\database\struct\TableStruct;
6
use suda\database\middleware\Middleware;
7
8
/**
9
 * 数据表抽象对象
10
 *
11
 * 用于提供对数据表的操作
12
 *
13
 */
14
abstract class Table extends TableAccess implements Middleware
15
{
16
    use TableMiddlewareTrait;
17
18
    /**
19
     * Table constructor.
20
     * @param string $tableName
21
     */
22
    public function __construct(string $tableName)
23
    {
24
        parent::__construct($this->initStruct($tableName), Database::application()->getDataSource(), $this);
25
    }
26
27
    /**
28
     * 构建数据表
29
     * @param TableStruct $table
30
     * @return TableStruct
31
     */
32
    abstract public function onCreateStruct(TableStruct $table):TableStruct;
33
34
    /**
35
     * 创建表结构
36
     *
37
     * @param string $tableName
38
     * @return TableStruct
39
     */
40
    protected function initStruct(string $tableName):TableStruct
41
    {
42
        $table = new TableStruct($tableName);
43
        return $this->onCreateStruct($table);
44
    }
45
46
    /**
47
     * 结构继承
48
     * @param Table $table
49
     * @return bool
50
     */
51
    public function isSubOf(Table $table)
52
    {
53
        return TableStruct::isSubOf($this->getStruct(), $table->getStruct());
54
    }
55
}
56