Passed
Push — sudav3 ( 699e88...9ddd82 )
by 世昌
02:51
created

TableMiddlewareTrait::outputName()   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\TableStruct;
5
6
trait TableMiddlewareTrait
7
{
8
    /**
9
     * 处理输入数据
10
     *
11
     * @param string $name
12
     * @param mixed $data
13
     * @return mixed
14
     */
15
    public function input(string $name, $data)
16
    {
17
        $methodName = '_input'.ucfirst($name).'Field';
18
        if (\method_exists($this, $methodName)) {
19
            return $this->$methodName($data);
20
        }
21
        return $data;
22
    }
23
24
    /**
25
     * 处理输出数据
26
     *
27
     * @param string $name
28
     * @param mixed $data
29
     * @return mixed
30
     */
31
    public function output(string $name, $data)
32
    {
33
        $methodName = '_output'.ucfirst($name).'Field';
34
        if (\method_exists($this, $methodName)) {
35
            return $this->$methodName($data);
36
        }
37
        return $data;
38
    }
39
40
    /**
41
     * 对输出列进行处理
42
     *
43
     * @param mixed $row
44
     * @return mixed
45
     */
46
    public function outputRow($row)
47
    {
48
        $methodName = '_outputDataFilter';
49
        if (\method_exists($this, $methodName)) {
50
            return $this->$methodName($row);
51
        }
52
        return $row;
53
    }
54
55
    /**
56
     * 输入参数名
57
     *
58
     * @param string $name
59
     * @return string
60
     */
61
    public function inputName(string $name):string
62
    {
63
        return $name;
64
    }
65
66
    /**
67
     * 输出参数名
68
     *
69
     * @param string $name
70
     * @return string
71
     */
72
    public function outputName(string $name):string
73
    {
74
        return $name;
75
    }
76
}
77