-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorage.php
More file actions
58 lines (44 loc) · 1.12 KB
/
Storage.php
File metadata and controls
58 lines (44 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Undercloud\Lang;
use Undercloud\Lang\Parser\AbstractParser;
class Storage
{
private $root;
private $parser;
private $stack = array();
public function setRoot($root)
{
$this->root = $root;
return $this;
}
public function setParser(AbstractParser $parser)
{
$this->parser = $parser;
return $this;
}
public function load($locale, $message)
{
$keys = explode('.', $message);
$entity = array_shift($keys);
if (false == isset($this->stack[$locale][$entity])) {
$arguments = array();
if (property_exists($this->parser, 'buildPath') and false === $this->parser->buildPath) {
$arguments[] = $locale;
$arguments[] = $entity;
} else {
$arguments[] = $this->root . '/' . str_replace('.', '/', $locale) . '/' . $entity;
}
$this->stack[$locale][$entity] = call_user_func_array(array($this->parser, 'parse'), $arguments);
}
$array = $this->stack[$locale][$entity];
foreach ($keys as $key) {
if (isset($array[$key])) {
$array = $array[$key];
} else {
return new TranslateNotFound;
}
}
return $array;
}
}
?>