1 | <?php namespace Arcanedev\LaravelHtml\Traits; |
||
12 | trait FormAccessible |
||
13 | { |
||
14 | /* ------------------------------------------------------------------------------------------------ |
||
15 | | Properties |
||
16 | | ------------------------------------------------------------------------------------------------ |
||
17 | */ |
||
18 | /** |
||
19 | * A cached ReflectionClass instance for $this |
||
20 | * |
||
21 | * @var ReflectionClass |
||
22 | */ |
||
23 | protected $reflection; |
||
24 | |||
25 | /* ------------------------------------------------------------------------------------------------ |
||
26 | | Main Functions |
||
27 | | ------------------------------------------------------------------------------------------------ |
||
28 | */ |
||
29 | /** |
||
30 | * @param string $key |
||
31 | * |
||
32 | * @return mixed |
||
33 | */ |
||
34 | 8 | public function getFormValue($key) |
|
53 | |||
54 | /* ------------------------------------------------------------------------------------------------ |
||
55 | | Other Functions |
||
56 | | ------------------------------------------------------------------------------------------------ |
||
57 | */ |
||
58 | /** |
||
59 | * Check if has a form mutator. |
||
60 | * |
||
61 | * @param string $key |
||
62 | * |
||
63 | * @return bool |
||
64 | */ |
||
65 | 8 | protected function hasFormMutator($key) |
|
77 | |||
78 | /** |
||
79 | * Mutate the form attribute. |
||
80 | * |
||
81 | * @param string $key |
||
82 | * @param mixed $value |
||
83 | * |
||
84 | * @return mixed |
||
85 | */ |
||
86 | 8 | private function mutateFormAttribute($key, $value) |
|
90 | |||
91 | /** |
||
92 | * Get a ReflectionClass Instance |
||
93 | * |
||
94 | * @return ReflectionClass |
||
95 | */ |
||
96 | 8 | protected function getReflection() |
|
104 | } |
||
105 |
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.