1 | <?php |
||
13 | class Text { |
||
14 | use Singleton; |
||
15 | /** |
||
16 | * Gets text on current language |
||
17 | * |
||
18 | * @param int $database |
||
19 | * @param int|null $id Getting may be done with group and label or with id |
||
20 | * @param bool $store_in_cache If `true` - text will be stored in cache |
||
21 | * |
||
22 | * @return false|string |
||
23 | */ |
||
24 | 4 | function get ($database, $id = null, $store_in_cache = false) { |
|
25 | 4 | $Cache = Cache::instance(); |
|
26 | 4 | $L = Language::instance(); |
|
27 | 4 | $id = (int)$id; |
|
28 | 4 | $cache_key = "texts/$database/{$id}_$L->clang"; |
|
29 | 4 | if ($store_in_cache && ($text = $Cache->$cache_key) !== false) { |
|
30 | 2 | return $text; |
|
31 | } |
||
32 | 4 | $text = $this->get_text_by_id($database, $L->clang, $id); |
|
33 | 4 | if ($text === false) { |
|
34 | 2 | return false; |
|
35 | } |
||
36 | 4 | if ($store_in_cache) { |
|
37 | 4 | $Cache->$cache_key = $text; |
|
38 | } |
||
39 | 4 | return $text; |
|
40 | } |
||
41 | /** |
||
42 | * @param int $database |
||
43 | * @param string $clang |
||
44 | * @param int $id |
||
45 | * |
||
46 | * @return false|string |
||
47 | */ |
||
48 | 4 | protected function get_text_by_id ($database, $clang, $id) { |
|
73 | /** |
||
74 | * Sets text on current language |
||
75 | * |
||
76 | * @param int $database |
||
77 | * @param string $group |
||
78 | * @param string $label |
||
79 | * @param string $text |
||
80 | * |
||
81 | * @return false|string If multilingual support enabled or was enabled and then disabled but translations remains - returns {¶<i>id</i>}, otherwise returns |
||
82 | * original text |
||
83 | */ |
||
84 | 4 | function set ($database, $group, $label, $text) { |
|
133 | /** |
||
134 | * @param int $id |
||
135 | * @param string $text |
||
136 | * @param DB\_Abstract $cdb |
||
137 | * @param string $clang |
||
138 | * |
||
139 | * @return mixed |
||
140 | */ |
||
141 | 4 | protected function set_text ($id, $text, $cdb, $clang) { |
|
191 | /** |
||
192 | * Deletes text on all languages |
||
193 | * |
||
194 | * @param int $database |
||
195 | * @param string $group |
||
196 | * @param string $label |
||
197 | * |
||
198 | * @return bool |
||
199 | */ |
||
200 | 2 | function del ($database, $group, $label) { |
|
229 | /** |
||
230 | * Process text, and replace {¶([0-9]+)} on real text, is used before showing multilingual information |
||
231 | * |
||
232 | * @param int $database |
||
233 | * @param string|string[] $data |
||
234 | * @param bool $store_in_cache If <b>true</b> - text will be stored in cache |
||
235 | * |
||
236 | * @return string|string[] |
||
1 ignored issue
–
show
|
|||
237 | */ |
||
238 | 38 | function process ($database, $data, $store_in_cache = false) { |
|
253 | } |
||
254 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.