1 | <?php |
||
9 | class Helper |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * Array of message keys. A set of messages that are |
||
14 | * supposed to be exported to the JS code in addition |
||
15 | * to Config::get('js-localization.messages'). |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $messagesToExport = []; |
||
20 | |||
21 | /** |
||
22 | * Allows registration of additional messages to |
||
23 | * export to the JS code. The additional messages |
||
24 | * registered using this method extend the |
||
25 | * Config::get('js-localization.messages') |
||
26 | * array. |
||
27 | * Don't forget to run `php artisan js-localization:refresh`! |
||
28 | * |
||
29 | * @param array $messageKeys Array of message keys. |
||
30 | * @return void |
||
31 | */ |
||
32 | 2 | public function addMessagesToExport(array $messageKeys) |
|
41 | |||
42 | /** |
||
43 | * Similar to addMessagesToExport(), but does not |
||
44 | * register an array of message keys, but the |
||
45 | * messages of a whole language file (one of the |
||
46 | * PHP files in app/lang). |
||
47 | * |
||
48 | * @param string $filePath Path to the message file. |
||
49 | * @param string $prefix Optional. Prefix to prepend before the message keys. |
||
50 | * @return void |
||
51 | * @throws FileNotFoundException |
||
52 | */ |
||
53 | 2 | public function addMessageFileToExport($filePath, $prefix="") |
|
70 | |||
71 | /** |
||
72 | * Returns the message keys previously registered |
||
73 | * by addMessagesToExport(). Nested arrays have |
||
74 | * already been resolved to a single flat array. |
||
75 | * |
||
76 | * @return array |
||
77 | * Array of message keys to export to the JS code. |
||
78 | */ |
||
79 | 10 | public function getAdditionalMessages() |
|
83 | |||
84 | /** |
||
85 | * Takes an array of message keys with nested |
||
86 | * sub-arrays and returns a flat array of |
||
87 | * fully qualified message keys. |
||
88 | * |
||
89 | * @param array $messageKeys Complex array of message keys. |
||
90 | * @return array Flat array of fully qualified message keys. |
||
91 | */ |
||
92 | 10 | public function resolveMessageKeyArray(array $messageKeys) |
|
105 | |||
106 | /** |
||
107 | * Resolves a message array with nested |
||
108 | * sub-arrays to a flat array of fully |
||
109 | * qualified message keys. |
||
110 | * |
||
111 | * @param array $messages Complex message array (like the ones in the app/lang/* files). |
||
112 | * @return array Flat array of fully qualified message keys. |
||
113 | */ |
||
114 | 2 | public function resolveMessageArrayToMessageKeys(array $messages, $prefix="") |
|
127 | |||
128 | /** |
||
129 | * Returns the concatenation of prefix and key if the key |
||
130 | * is a string. If the key is an array then the function |
||
131 | * will recurse. |
||
132 | * |
||
133 | * @param mixed $key An array item read from the configuration ('messages' array). |
||
134 | * @param mixed $keyIndex The array index of $key. Is necessary if $key is an array. |
||
135 | * @param callable $callback A callback function: function($fullyQualifiedKey). |
||
136 | * @param string $prefix Optional key prefix. |
||
137 | */ |
||
138 | 9 | private function resolveMessageKey($key, $keyIndex, $callback, $prefix="") |
|
151 | |||
152 | /** |
||
153 | * Returns the concatenation of prefix and key if the value |
||
154 | * is a message. If the value is an array then the function |
||
155 | * will recurse. |
||
156 | * |
||
157 | * @param mixed $message An array item read from a message file array. |
||
158 | * @param mixed $key The array key of $message. |
||
159 | * @param callable $callback A callback function: function($fullyQualifiedKey). |
||
160 | * @param string $prefix Optional key prefix. |
||
161 | */ |
||
162 | 2 | private function resolveMessageToKeys($message, $key, $callback, $prefix="") |
|
175 | |||
176 | /** |
||
177 | * Appends a dot to the prefix if necessary. |
||
178 | * |
||
179 | * @param string $prefix Prefix to validate and possibly append dot to. |
||
180 | * @return string Processed prefix. |
||
181 | */ |
||
182 | 1 | private function prefix($prefix) |
|
194 | |||
195 | } |