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(string $key, string $locale = '') |
||
35 | |||
36 | /*** |
||
37 | * @param string $key |
||
38 | * @param string $locale |
||
39 | * |
||
40 | * @return mixed |
||
41 | */ |
||
42 | public function getTranslation(string $key, string $locale, bool $withFallback = true) |
||
56 | |||
57 | public function getTranslationWithFallback(string $key, string $locale) |
||
61 | |||
62 | public function getTranslationWithoutFallback(string $key, string $locale) |
||
66 | |||
67 | public function getTranslations($key) : array |
||
73 | |||
74 | /** |
||
75 | * @param string $key |
||
76 | * @param string $locale |
||
77 | * @param $value |
||
78 | * |
||
79 | * @return $this |
||
80 | */ |
||
81 | public function setTranslation(string $key, string $locale, $value) |
||
102 | |||
103 | /** |
||
104 | * @param string $key |
||
105 | * @param array $translations |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function setTranslations(string $key, array $translations) |
||
119 | |||
120 | /** |
||
121 | * @param string $key |
||
122 | * @param string $locale |
||
123 | * |
||
124 | * @return $this |
||
125 | */ |
||
126 | public function forgetTranslation(string $key, string $locale) |
||
136 | |||
137 | public function getTranslatedLocales(string $key) : array |
||
141 | |||
142 | public function isTranslatableAttribute(string $key) : bool |
||
146 | |||
147 | protected function guardAgainstUntranslatableAttribute(string $key) |
||
153 | |||
154 | protected function normalizeLocale(string $key, string $locale, bool $withFallBack) : string |
||
171 | |||
172 | public function getTranslatableAttributes() : array |
||
178 | |||
179 | public function getCasts() : array |
||
186 | } |
||
187 |
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.