1 | <?php |
||
10 | abstract class Attribute extends Collection |
||
11 | { |
||
12 | /** |
||
13 | * Attributes alias. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $aliases = []; |
||
18 | |||
19 | /** |
||
20 | * Auto snake attribute name. |
||
21 | * |
||
22 | * @var bool |
||
23 | */ |
||
24 | protected $snakeable = true; |
||
25 | |||
26 | /** |
||
27 | * Required attributes. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $requirements = []; |
||
32 | |||
33 | /** |
||
34 | * Constructor. |
||
35 | * |
||
36 | * @param array $attributes |
||
37 | */ |
||
38 | public function __construct(array $attributes = []) |
||
42 | |||
43 | /** |
||
44 | * Set attribute. |
||
45 | * |
||
46 | * @param string $attribute |
||
47 | * @param string $value |
||
48 | * |
||
49 | * @return Attribute |
||
50 | */ |
||
51 | public function setAttribute($attribute, $value) |
||
57 | |||
58 | /** |
||
59 | * Get attribute. |
||
60 | * |
||
61 | * @param string $attribute |
||
62 | * @param mixed $default |
||
63 | * |
||
64 | * @return mixed |
||
65 | */ |
||
66 | public function getAttribute($attribute, $default) |
||
70 | |||
71 | /** |
||
72 | * Set attribute. |
||
73 | * |
||
74 | * @param string $attribute |
||
75 | * @param mixed $value |
||
76 | * |
||
77 | * @throws \EntWeChat\Core\Exceptions\InvalidArgumentException |
||
78 | * |
||
79 | * @return Attribute |
||
80 | */ |
||
81 | public function with($attribute, $value) |
||
93 | |||
94 | /** |
||
95 | * Attribute validation. |
||
96 | * |
||
97 | * @param string $attribute |
||
98 | * @param mixed $value |
||
99 | * |
||
100 | * @return bool |
||
101 | */ |
||
102 | protected function validate($attribute, $value) |
||
106 | |||
107 | /** |
||
108 | * Override parent set() method. |
||
109 | * |
||
110 | * @param string $attribute |
||
111 | * @param mixed $value |
||
112 | */ |
||
113 | public function set($attribute, $value = null) |
||
117 | |||
118 | /** |
||
119 | * Override parent get() method. |
||
120 | * |
||
121 | * @param string $attribute |
||
122 | * @param mixed $default |
||
123 | * |
||
124 | * @return mixed |
||
125 | */ |
||
126 | public function get($attribute, $default = null) |
||
130 | |||
131 | /** |
||
132 | * Magic call. |
||
133 | * |
||
134 | * @param string $method |
||
135 | * @param array $args |
||
136 | * |
||
137 | * @return Attribute |
||
138 | */ |
||
139 | public function __call($method, $args) |
||
147 | |||
148 | /** |
||
149 | * Magic set. |
||
150 | * |
||
151 | * @param string $property |
||
152 | * @param mixed $value |
||
153 | * |
||
154 | * @return Attribute |
||
155 | */ |
||
156 | public function __set($property, $value) |
||
160 | |||
161 | /** |
||
162 | * Whether or not an data exists by key. |
||
163 | * |
||
164 | * @param string $key |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | public function __isset($key) |
||
172 | |||
173 | /** |
||
174 | * Return the raw name of attribute. |
||
175 | * |
||
176 | * @param string $key |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | protected function getRealKey($key) |
||
188 | |||
189 | /** |
||
190 | * Check required attributes. |
||
191 | * |
||
192 | * @throws InvalidArgumentException |
||
193 | */ |
||
194 | protected function checkRequiredAttributes() |
||
202 | |||
203 | /** |
||
204 | * Return all items. |
||
205 | * |
||
206 | * @throws InvalidArgumentException |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | public function all() |
||
216 | } |
||
217 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.