1 | <?php |
||
16 | trait FormAccessible |
||
17 | { |
||
18 | /* ----------------------------------------------------------------- |
||
19 | | Properties |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | /** |
||
24 | * A cached ReflectionClass instance for $this. |
||
25 | * |
||
26 | * @var \ReflectionClass |
||
27 | */ |
||
28 | protected $reflection; |
||
29 | |||
30 | /* ----------------------------------------------------------------- |
||
31 | | Main Methods |
||
32 | | ----------------------------------------------------------------- |
||
33 | */ |
||
34 | |||
35 | /** |
||
36 | * Get form value from the eloquent model. |
||
37 | * |
||
38 | * @param string $key |
||
39 | * |
||
40 | * @return mixed |
||
41 | */ |
||
42 | 18 | public function getFormValue(string $key) |
|
53 | |||
54 | /* ----------------------------------------------------------------- |
||
55 | | Eloquent Methods |
||
56 | | ----------------------------------------------------------------- |
||
57 | */ |
||
58 | |||
59 | /** |
||
60 | * Get an attribute from the $attributes array. |
||
61 | * |
||
62 | * @param string $key |
||
63 | * |
||
64 | * @return mixed |
||
65 | */ |
||
66 | abstract protected function getAttributeFromArray($key); |
||
67 | |||
68 | /** |
||
69 | * Get the attributes that should be converted to dates. |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | abstract public function getDates(); |
||
74 | |||
75 | /** |
||
76 | * Return a timestamp as DateTime object. |
||
77 | * |
||
78 | * @param mixed $value |
||
79 | * |
||
80 | * @return \Carbon\Carbon |
||
81 | */ |
||
82 | abstract protected function asDateTime($value); |
||
83 | |||
84 | /* ----------------------------------------------------------------- |
||
85 | | Other Methods |
||
86 | | ----------------------------------------------------------------- |
||
87 | */ |
||
88 | |||
89 | /** |
||
90 | * Check if has a form mutator. |
||
91 | * |
||
92 | * @param string $key |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | 18 | protected function hasFormMutator(string $key): bool |
|
104 | |||
105 | /** |
||
106 | * Mutate the form attribute. |
||
107 | * |
||
108 | * @param string $key |
||
109 | * @param mixed $value |
||
110 | * |
||
111 | * @return mixed |
||
112 | */ |
||
113 | 12 | private function mutateFormAttribute(string $key, $value) |
|
117 | |||
118 | /** |
||
119 | * Get the mutate form method name. |
||
120 | * |
||
121 | * @param string $key |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | 18 | private function getMutateFromMethodName(string $key): string |
|
129 | |||
130 | /** |
||
131 | * Get a ReflectionClass Instance. |
||
132 | * |
||
133 | * @return \ReflectionClass |
||
134 | */ |
||
135 | 18 | protected function getReflection(): ReflectionClass |
|
143 | } |
||
144 |