1 | <?php |
||
15 | trait AutoWithTrait |
||
16 | { |
||
17 | /** |
||
18 | * 用户请求引入字段. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $param_columns = null; |
||
23 | |||
24 | /** |
||
25 | * 根节点的字段. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $param_root_columns = []; |
||
30 | |||
31 | /** |
||
32 | * 自动 with include 的关联. |
||
33 | * |
||
34 | * @return $this |
||
35 | */ |
||
36 | public function autoWith() |
||
56 | |||
57 | /** |
||
58 | * 添加一个可用的引入项. |
||
59 | * |
||
60 | * @param $name |
||
61 | * @param $default_columns |
||
62 | * |
||
63 | * @return $this |
||
64 | * |
||
65 | * @throws Exception |
||
66 | */ |
||
67 | public function addAvailableInclude($name, $default_columns) |
||
79 | |||
80 | /** |
||
81 | * 设置数据要查询的字段,自动绑定 include 关联的外键. |
||
82 | * |
||
83 | * @param $columns |
||
84 | * |
||
85 | * @return $this |
||
86 | */ |
||
87 | public function autoWithRootColumns($columns) |
||
97 | |||
98 | /** |
||
99 | * 解析 columns 参数,用于指定 include 关联的字段 |
||
100 | * eg. ?include=user&columns=user(name,avatar,gender). |
||
101 | * |
||
102 | * @return array |
||
103 | */ |
||
104 | private function parseColumnsParam() |
||
127 | } |
||
128 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.