1 | <?php |
||
30 | trait MappingTrait |
||
31 | { |
||
32 | use LoaderAwareTrait; |
||
33 | |||
34 | /** |
||
35 | * Ddefault messages for current message class |
||
36 | * |
||
37 | * This property HAS TO BE redefined for each descendant message class ! |
||
38 | * |
||
39 | * @var string[] |
||
40 | * @access protected |
||
41 | */ |
||
42 | protected static $messages = []; |
||
43 | |||
44 | /** |
||
45 | * Message mapping cache |
||
46 | * |
||
47 | * @var array |
||
48 | * @access private |
||
49 | */ |
||
50 | private static $mappings = []; |
||
51 | |||
52 | /** |
||
53 | * Reset current message class' code to message mappings cache |
||
54 | * |
||
55 | * ```php |
||
56 | * MyMessage::setMappings([ |
||
57 | * MyMessage::MSG_HELLO => 'Hello %s' |
||
58 | * ]); |
||
59 | * ``` |
||
60 | * |
||
61 | * @param array $messages messages mapping array |
||
62 | * @param bool $manual manually, not auto load from $loader |
||
63 | * @access public |
||
64 | * @api |
||
65 | */ |
||
66 | public static function setMappings( |
||
86 | |||
87 | /** |
||
88 | * Check current class' message mapping cache |
||
89 | * |
||
90 | * @return bool |
||
91 | * @access protected |
||
92 | */ |
||
93 | protected static function hasMappings()/*# : bool */ |
||
97 | |||
98 | /** |
||
99 | * Get current class' message mapping, default or cached |
||
100 | * |
||
101 | * @return array |
||
102 | * @access protected |
||
103 | */ |
||
104 | protected static function getMappings()/*# : array */ |
||
114 | |||
115 | /** |
||
116 | * Clear the mapping cache |
||
117 | * |
||
118 | * @access protected |
||
119 | */ |
||
120 | protected static function resetMappings() |
||
124 | |||
125 | /** |
||
126 | * Check message template in default mapping |
||
127 | * |
||
128 | * @param int $code the message code |
||
129 | * @return bool |
||
130 | * @access protected |
||
131 | */ |
||
132 | protected static function messageDefined(/*# int */ $code)/*# : bool */ |
||
136 | |||
137 | /** |
||
138 | * Resolving code for current message class, from cache or default |
||
139 | * |
||
140 | * If nothing found, return the code anyway |
||
141 | * |
||
142 | * @param int $code the message code |
||
143 | * @return string |
||
144 | * @access protected |
||
145 | */ |
||
146 | protected static function getMessage(/*# int */ $code)/*# : string */ |
||
154 | |||
155 | /** |
||
156 | * Resolving $code to message template, start from $class |
||
157 | * |
||
158 | * @param int $code message code |
||
159 | * @param string $class class name |
||
160 | * @return string |
||
161 | * @access protected |
||
162 | */ |
||
163 | protected static function getTemplateByCode( |
||
184 | |||
185 | /** |
||
186 | * Load message mappings into cache for $class |
||
187 | * |
||
188 | * @access protected |
||
189 | */ |
||
190 | protected static function loadMappings() |
||
208 | |||
209 | /** |
||
210 | * Update mapping cache if status changed |
||
211 | * |
||
212 | * @access protected |
||
213 | */ |
||
214 | protected static function checkStatus() |
||
221 | } |
||
222 |