22 public function value($key,$time = null){
23 if(array_key_exists($key,$this->
items)){
24 $values = $this->
items[$key];
25 if(!$time)
return array_pop($values);
26 foreach(array_reverse($values,
true) as $start => $value)
if(is_numeric($start) && ($start <= $time))
return $value;
37 public function add($key,$value,$start = null){
38 if($start === null) $start = time();
40 while(!$lock->request($this->lockItem)) sleep(1);
43 if(array_key_exists($key,$items = \
Rsi\File::jsonDecode($this->_filename))){
44 $items[$key][$start] = $value;
47 else $items[$key] = [$start => $value];
48 $result = \Rsi\File::jsonEncode($this->_filename,$items);
51 $this->
component(
'log')->info(
'Unable to add: ' . $e->getMessage(),__FILE__,__LINE__);
53 $lock->release($this->lockItem);
61 $categories = \Rsi\Record::get($this->
items,null) ?: [];
62 foreach($this->
items as $key => $item)
63 if($key && ($category = \
Rsi\Record::get($item,
'category')) && !array_key_exists($category,$categories))
64 $categories[$category] = null;
72 public function items($category){
74 foreach($this->
items as $key => $item)
if(\
Rsi\Record::get($item,
'category') == $category)
75 $items[$key] = \Rsi\Record::get($item,
'mask');
80 if($this->_items === null){
81 while($this->
component(
'lock')->exists($this->lockItem)) sleep(1);
82 $this->_items = \Rsi\File::jsonDecode($this->_filename);
83 if(!$this->_items)
throw new Exception(
'Could not decode items');
88 protected function _get($key){
89 return $this->
value($key);
92 protected function _set($key,$value){
93 $this->
add($key,$value);
Variables component (dynamic configuration).
add($key, $value, $start=null)
Add a value.
value($key, $time=null)
Retrieve a value.
$_filename
Storage file (JSON formatted).
categories()
All categories.
items($category)
All config items for a category.
component($name)
Get a component (local or default).