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 | * @return HasTranslations|void |
||
29 | */ |
||
30 | public function setAttribute($key, $value) |
||
42 | |||
43 | /** |
||
44 | * @param string $key |
||
45 | * @param string $locale |
||
46 | * |
||
47 | * @return mixed |
||
48 | */ |
||
49 | public function translate(string $key, string $locale = '') |
||
53 | |||
54 | /*** |
||
55 | * @param string $key |
||
56 | * @param string $locale |
||
57 | * |
||
58 | * @return mixed |
||
59 | */ |
||
60 | public function getTranslation(string $key, string $locale) |
||
74 | |||
75 | public function getTranslations($key) : array |
||
81 | |||
82 | /** |
||
83 | * @param string $key |
||
84 | * @param string $locale |
||
85 | * @param $value |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | public function setTranslation(string $key, string $locale, $value) |
||
110 | |||
111 | /** |
||
112 | * @param string $key |
||
113 | * @param array $translations |
||
114 | * |
||
115 | * @return $this |
||
116 | */ |
||
117 | public function setTranslations(string $key, array $translations) |
||
127 | |||
128 | /** |
||
129 | * @param string $key |
||
130 | * @param string $locale |
||
131 | * |
||
132 | * @return $this |
||
133 | */ |
||
134 | public function forgetTranslation(string $key, string $locale) |
||
144 | |||
145 | public function getTranslatedLocales(string $key) : array |
||
149 | |||
150 | protected function isTranslatableAttribute(string $key) : bool |
||
154 | |||
155 | protected function guardAgainstUntranslatableAttribute(string $key) |
||
161 | |||
162 | protected function normalizeLocale(string $key, string $locale) : string |
||
174 | |||
175 | public function getTranslatableAttributes() : array |
||
181 | |||
182 | public function getCasts() : array |
||
189 | } |
||
190 |
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.