1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Jaeger |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015-2016, mithra62 |
6
|
|
|
* @link http://jaeger-app.com |
7
|
|
|
* @version 1.0 |
8
|
|
|
* @filesource ./Language.php |
9
|
|
|
*/ |
10
|
|
|
namespace JaegerApp; |
11
|
|
|
|
12
|
|
|
use JaegerApp\Traits\Log; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Jaeger - Language Handler Object |
16
|
|
|
* |
17
|
|
|
* Provides basic and generic string replacement via loaded php arrays ONLY. |
18
|
|
|
* |
19
|
|
|
* Shouldn't be used for anything more than keeping generic phrasing out of the code |
20
|
|
|
* |
21
|
|
|
* @package Language |
22
|
|
|
* @author Eric Lamb <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class Language |
25
|
|
|
{ |
26
|
|
|
use Log; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Container of the loaded language files |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private $is_loaded = array(); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Container for the various languages |
37
|
|
|
* |
38
|
|
|
* @var unknown |
39
|
|
|
*/ |
40
|
|
|
private $language = array(); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Sets up the Language object |
44
|
|
|
* |
45
|
|
|
* @param array $paths |
46
|
|
|
*/ |
47
|
|
|
public function __construct($paths = array()) |
48
|
|
|
{ |
49
|
|
|
if (! is_array($paths)) { |
50
|
|
|
$paths = array( |
51
|
|
|
$paths |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
foreach($paths As $path) { |
56
|
|
|
$this->init($path); |
57
|
|
|
}; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Loads a language array file for use |
62
|
|
|
* |
63
|
|
|
* @param string $path |
64
|
|
|
* The path to the language direcotry to load |
65
|
|
|
* @return void|unknown|boolean |
66
|
|
|
*/ |
67
|
|
|
public function init($path) |
68
|
|
|
{ |
69
|
|
|
if (in_array($path, $this->is_loaded, TRUE)) { |
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$lang = array(); |
74
|
|
|
if (is_dir($path)) { |
75
|
|
|
$d = dir($path); |
76
|
|
|
while (false !== ($entry = $d->read())) { |
77
|
|
|
if (! in_array($entry, array( |
78
|
|
|
'.', |
79
|
|
|
'..' |
80
|
|
|
))) { |
81
|
|
|
$file = $path . '/' . $entry; |
82
|
|
|
$lang = include ($file); |
83
|
|
|
|
84
|
|
|
$this->is_loaded[] = $file; |
85
|
|
|
|
86
|
|
|
if (! $lang) { |
87
|
|
|
$this->logWarning('Language file contains no data: ' . $file); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->language = array_merge($this->language, $lang); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
unset($lang); |
96
|
|
|
return TRUE; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Fetch a single line of text from the language array |
101
|
|
|
* |
102
|
|
|
* @param string $line |
103
|
|
|
* line |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function __($line = '') |
107
|
|
|
{ |
108
|
|
|
$line = ($line == '' or ! isset($this->language[$line])) ? $line : $this->language[$line]; |
|
|
|
|
109
|
|
|
return $line; |
110
|
|
|
} |
111
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..