Passed
Push — master ( afac5a...068199 )
by 世昌
02:20
created

Table::application()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace suda\application\database;
3
4
use suda\orm\TableAccess;
5
use suda\orm\struct\TableStruct;
6
use suda\application\Application;
7
use suda\orm\middleware\Middleware;
8
9
/**
10
 * 数据表抽象对象
11
 *
12
 * 用于提供对数据表的操作
13
 *
14
 */
15
abstract class Table extends TableAccess implements Middleware
16
{
17
    use TableMiddlewareTrait;
18
19
    public function __construct(string $tableName)
20
    {
21
        parent::__construct($this->initStruct($tableName), Database::application()->getDataSource(), $this);
22
    }
23
24
    abstract public function onCreateStruct(TableStruct $table):TableStruct;
25
26
    /**
27
     * 创建表结构
28
     *
29
     * @param string $tableName
30
     * @return TableStruct
31
     */
32
    protected function initStruct(string $tableName):TableStruct
33
    {
34
        $table = new TableStruct($tableName);
35
        return $this->onCreateStruct($table);
36
    }
37
}
38