1 | <?php |
||
9 | trait HasTranslations |
||
10 | { |
||
11 | /** |
||
12 | * @param string $key |
||
13 | * |
||
14 | * @return mixed |
||
15 | */ |
||
16 | public function getAttributeValue($key) |
||
24 | |||
25 | /** |
||
26 | * @param string $key |
||
27 | * @param string $locale |
||
28 | * |
||
29 | * @return mixed |
||
30 | */ |
||
31 | public function translate($key, $locale = null) |
||
35 | |||
36 | /*** |
||
37 | * @param string $key |
||
38 | * @param string $locale |
||
39 | * |
||
40 | * @return mixed |
||
41 | */ |
||
42 | public function getTranslation($key, $locale) |
||
56 | |||
57 | public function getTranslations($key) |
||
63 | |||
64 | /** |
||
65 | * @param string $key |
||
66 | * @param string $locale |
||
67 | * @param $value |
||
68 | * |
||
69 | * @return $this |
||
70 | */ |
||
71 | public function setTranslation($key, $locale, $value) |
||
92 | |||
93 | /** |
||
94 | * @param string $key |
||
95 | * @param array $translations |
||
96 | * |
||
97 | * @return $this |
||
98 | */ |
||
99 | public function setTranslations($key, array $translations) |
||
109 | |||
110 | /** |
||
111 | * @param string $key |
||
112 | * @param string $locale |
||
113 | * |
||
114 | * @return $this |
||
115 | */ |
||
116 | public function forgetTranslation($key, $locale) |
||
126 | |||
127 | public function getTranslatedLocales($key) |
||
131 | |||
132 | public function isTranslatableAttribute($key) |
||
136 | |||
137 | protected function guardAgainstUntranslatableAttribute($key) |
||
143 | |||
144 | protected function normalizeLocale($key, $locale) |
||
156 | |||
157 | public function getTranslatableAttributes() |
||
163 | |||
164 | public function getCasts() |
||
171 | } |
||
172 |
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.