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 $key |
||
27 | * @param $value |
||
28 | * |
||
29 | * @return $this |
||
30 | */ |
||
31 | public function setAttribute($key, $value) |
||
48 | |||
49 | /** |
||
50 | * @param string $key |
||
51 | * @param string $locale |
||
52 | * |
||
53 | * @return mixed |
||
54 | */ |
||
55 | public function translate(string $key, string $locale = '') |
||
59 | |||
60 | /*** |
||
61 | * @param string $key |
||
62 | * @param string $locale |
||
63 | * |
||
64 | * @return mixed |
||
65 | */ |
||
66 | public function getTranslation(string $key, string $locale) |
||
80 | |||
81 | public function getTranslations($key) : array |
||
87 | |||
88 | /** |
||
89 | * @param string $key |
||
90 | * @param string $locale |
||
91 | * @param $value |
||
92 | * |
||
93 | * @return $this |
||
94 | */ |
||
95 | public function setTranslation(string $key, string $locale, $value) |
||
116 | |||
117 | /** |
||
118 | * @param string $key |
||
119 | * @param array $translations |
||
120 | * |
||
121 | * @return $this |
||
122 | */ |
||
123 | public function setTranslations(string $key, array $translations) |
||
133 | |||
134 | /** |
||
135 | * @param string $key |
||
136 | * @param string $locale |
||
137 | * |
||
138 | * @return $this |
||
139 | */ |
||
140 | public function forgetTranslation(string $key, string $locale) |
||
150 | |||
151 | public function getTranslatedLocales(string $key) : array |
||
155 | |||
156 | protected function isTranslatableAttribute(string $key) : bool |
||
160 | |||
161 | protected function guardAgainstUntranslatableAttribute(string $key) |
||
167 | |||
168 | protected function normalizeLocale(string $key, string $locale) : string |
||
180 | |||
181 | public function getTranslatableAttributes() : array |
||
187 | |||
188 | public function getCasts() : array |
||
195 | } |
||
196 |
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.