1 | <?php |
||
15 | abstract class MagicAttributes |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * 允许设置的属性名称 |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $attributes = []; |
||
24 | |||
25 | /** |
||
26 | * 方法名转换缓存 |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected static $snakeCache = []; |
||
31 | |||
32 | /** |
||
33 | * 设置属性 |
||
34 | * |
||
35 | * @param $attribute |
||
36 | * @param $value |
||
37 | * |
||
38 | * @return \Wechat\Utils\Menu\MagicAttributes |
||
39 | */ |
||
40 | public function setAttribute($attribute, $value) |
||
44 | |||
45 | /** |
||
46 | * 设置属性 |
||
47 | * |
||
48 | * @param string $attribute |
||
49 | * @param mixed $value |
||
50 | * |
||
51 | * @return MagicAttributes |
||
52 | */ |
||
53 | public function with($attribute, $value) |
||
65 | |||
66 | /** |
||
67 | * 生成数组 |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | public function toArray() |
||
75 | |||
76 | /** |
||
77 | * 验证 |
||
78 | * |
||
79 | * @param string $attribute |
||
80 | * @param mixed $value |
||
81 | * |
||
82 | * @return bool |
||
83 | */ |
||
84 | protected function validate($attribute, $value) |
||
88 | |||
89 | /** |
||
90 | * 调用不存在的方法 |
||
91 | * |
||
92 | * @param string $method |
||
93 | * @param array $args |
||
94 | * |
||
95 | * @return MagicAttributes |
||
96 | */ |
||
97 | public function __call($method, $args) |
||
105 | |||
106 | /** |
||
107 | * 魔术读取 |
||
108 | * |
||
109 | * @param $property |
||
110 | * |
||
111 | * @return null |
||
112 | */ |
||
113 | public function __get($property) |
||
117 | |||
118 | /** |
||
119 | * 魔术写入 |
||
120 | * |
||
121 | * @param $property |
||
122 | * @param $value |
||
123 | * |
||
124 | * @return \Wechat\Utils\Menu\MagicAttributes |
||
125 | */ |
||
126 | public function __set($property, $value) |
||
130 | |||
131 | /** |
||
132 | * 转换为下划线模式字符串 |
||
133 | * |
||
134 | * @param string $value |
||
135 | * @param string $delimiter |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | protected function snake($value, $delimiter = '_') |
||
153 | } |
||
154 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.