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) |
||
49 | |||
50 | /** |
||
51 | * @param string $key |
||
52 | * @param string $locale |
||
53 | * |
||
54 | * @return mixed |
||
55 | */ |
||
56 | public function translate(string $key, string $locale = '') |
||
60 | |||
61 | /*** |
||
62 | * @param string $key |
||
63 | * @param string $locale |
||
64 | * @param bool $useFallbackLocale |
||
65 | * |
||
66 | * @return mixed |
||
67 | */ |
||
68 | public function getTranslation(string $key, string $locale, bool $useFallbackLocale = true) |
||
82 | |||
83 | public function getTranslationWithFallback(string $key, string $locale) |
||
87 | |||
88 | public function getTranslationWithoutFallback(string $key, string $locale) |
||
92 | |||
93 | public function getTranslations($key) : array |
||
99 | |||
100 | /** |
||
101 | * @param string $key |
||
102 | * @param string $locale |
||
103 | * @param $value |
||
104 | * |
||
105 | * @return $this |
||
106 | */ |
||
107 | public function setTranslation(string $key, string $locale, $value) |
||
128 | |||
129 | /** |
||
130 | * @param string $key |
||
131 | * @param array $translations |
||
132 | * |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function setTranslations(string $key, array $translations) |
||
145 | |||
146 | /** |
||
147 | * @param string $key |
||
148 | * @param string $locale |
||
149 | * |
||
150 | * @return $this |
||
151 | */ |
||
152 | public function forgetTranslation(string $key, string $locale) |
||
162 | |||
163 | public function getTranslatedLocales(string $key) : array |
||
167 | |||
168 | public function isTranslatableAttribute(string $key) : bool |
||
172 | |||
173 | protected function guardAgainstUntranslatableAttribute(string $key) |
||
179 | |||
180 | protected function normalizeLocale(string $key, string $locale, bool $useFallbackLocale) : string |
||
196 | |||
197 | public function getTranslatableAttributes() : array |
||
203 | |||
204 | public function getCasts() : array |
||
211 | } |
||
212 |
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.