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) |
||
54 | |||
55 | public function getTranslations($key) : array |
||
61 | |||
62 | /** |
||
63 | * @param string $key |
||
64 | * @param string $locale |
||
65 | * @param $value |
||
66 | * |
||
67 | * @return $this |
||
68 | */ |
||
69 | public function setTranslation(string $key, string $locale, $value) |
||
90 | |||
91 | /** |
||
92 | * @param string $key |
||
93 | * @param array $translations |
||
94 | * |
||
95 | * @return $this |
||
96 | */ |
||
97 | public function setTranslations(string $key, array $translations) |
||
107 | |||
108 | /** |
||
109 | * @param string $key |
||
110 | * @param string $locale |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | public function forgetTranslation(string $key, string $locale) |
||
124 | |||
125 | public function getTranslatedLocales(string $key) : array |
||
129 | |||
130 | protected function isTranslatableAttribute(string $key) : bool |
||
134 | |||
135 | protected function guardAgainstUntranslatableAttribute(string $key) |
||
141 | |||
142 | public function getTranslatableAttributes() : array |
||
148 | |||
149 | public function getCasts() : array |
||
156 | } |
||
157 |
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.