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 $value |
||
28 | * |
||
29 | * @return mixed |
||
30 | */ |
||
31 | public function setAttribute($key, $value) |
||
39 | |||
40 | /** |
||
41 | * @param string $key |
||
42 | * @param string $locale |
||
43 | * |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public function translate(string $key, string $locale = '') |
||
50 | |||
51 | /*** |
||
52 | * @param string $key |
||
53 | * @param string $locale |
||
54 | * @param bool $useFallbackLocale |
||
55 | * |
||
56 | * @return mixed |
||
57 | */ |
||
58 | public function getTranslation(string $key, string $locale, bool $useFallbackLocale = true) |
||
72 | |||
73 | public function getTranslationWithFallback(string $key, string $locale) |
||
77 | |||
78 | public function getTranslationWithoutFallback(string $key, string $locale) |
||
82 | |||
83 | public function getTranslations($key) : array |
||
89 | |||
90 | /** |
||
91 | * @param string $key |
||
92 | * @param string $locale |
||
93 | * @param $value |
||
94 | * |
||
95 | * @return $this |
||
96 | */ |
||
97 | public function setTranslation(string $key, string $locale, $value) |
||
118 | |||
119 | /** |
||
120 | * @param string $key |
||
121 | * @param array $translations |
||
122 | * |
||
123 | * @return $this |
||
124 | */ |
||
125 | public function setTranslations(string $key, array $translations) |
||
135 | |||
136 | /** |
||
137 | * @param string $key |
||
138 | * @param string $locale |
||
139 | * |
||
140 | * @return $this |
||
141 | */ |
||
142 | public function forgetTranslation(string $key, string $locale) |
||
152 | |||
153 | public function getTranslatedLocales(string $key) : array |
||
157 | |||
158 | public function isTranslatableAttribute(string $key) : bool |
||
162 | |||
163 | protected function guardAgainstUntranslatableAttribute(string $key) |
||
169 | |||
170 | protected function normalizeLocale(string $key, string $locale, bool $useFallbackLocale) : string |
||
186 | |||
187 | public function getTranslatableAttributes() : array |
||
193 | |||
194 | public function getCasts() : array |
||
201 | } |
||
202 |
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.