1 | <?php |
||
9 | trait HasTranslations |
||
10 | { |
||
11 | /** |
||
12 | * @param string $key |
||
13 | * |
||
14 | * @return mixed |
||
15 | */ |
||
16 | public function getAttributeValue($key) |
||
24 | |||
25 | /** |
||
26 | * Assume default locale for translatable attributes. |
||
27 | * |
||
28 | * @param string $key |
||
29 | * @param mixed $value |
||
30 | * @return $this |
||
31 | */ |
||
32 | public function __set($key, $value) |
||
40 | |||
41 | /** |
||
42 | * @param string $key |
||
43 | * @param string $locale |
||
44 | * |
||
45 | * @return mixed |
||
46 | */ |
||
47 | public function translate(string $key, string $locale = '') |
||
51 | |||
52 | /*** |
||
53 | * @param string $key |
||
54 | * @param string $locale |
||
55 | * |
||
56 | * @return mixed |
||
57 | */ |
||
58 | public function getTranslation(string $key, string $locale) |
||
72 | |||
73 | public function getTranslations($key) : array |
||
79 | |||
80 | /** |
||
81 | * @param string $key |
||
82 | * @param string $locale |
||
83 | * @param $value |
||
84 | * |
||
85 | * @return $this |
||
86 | */ |
||
87 | public function setTranslation(string $key, string $locale, $value) |
||
108 | |||
109 | /** |
||
110 | * @param string $key |
||
111 | * @param array $translations |
||
112 | * |
||
113 | * @return $this |
||
114 | */ |
||
115 | public function setTranslations(string $key, array $translations) |
||
125 | |||
126 | /** |
||
127 | * @param string $key |
||
128 | * @param string $locale |
||
129 | * |
||
130 | * @return $this |
||
131 | */ |
||
132 | public function forgetTranslation(string $key, string $locale) |
||
142 | |||
143 | public function getTranslatedLocales(string $key) : array |
||
147 | |||
148 | public function isTranslatableAttribute(string $key) : bool |
||
152 | |||
153 | protected function guardAgainstUntranslatableAttribute(string $key) |
||
159 | |||
160 | protected function normalizeLocale(string $key, string $locale) : string |
||
172 | |||
173 | public function getTranslatableAttributes() : array |
||
179 | |||
180 | public function getCasts() : array |
||
187 | } |
||
188 |
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.