Другая интерпретация реестра
This commit is contained in:
parent
40fad0e75b
commit
aaa9c2e1bf
21 changed files with 156 additions and 92 deletions
40
src/Registry.php
Normal file
40
src/Registry.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso;
|
||||
use ctiso\File,
|
||||
Exception;
|
||||
|
||||
class Registry {
|
||||
public $namespace = [];
|
||||
|
||||
function importFile($namespace, $filePath = null) {
|
||||
$data = json_decode(File::getContents($filePath), true);
|
||||
$data['_file'] = $filePath;
|
||||
$this->namespace[$namespace] = [
|
||||
'path' => $filePath,
|
||||
'data' => $data
|
||||
];
|
||||
}
|
||||
|
||||
function importArray($namespace, $data = []) {
|
||||
if (isset($this->namespace[$namespace])) {
|
||||
$data = array_merge($this->namespace[$namespace]['data'], $data);
|
||||
}
|
||||
$this->namespace[$namespace] = [
|
||||
'path' => null,
|
||||
'data' => $data
|
||||
];
|
||||
}
|
||||
|
||||
public function get($ns, $key) {
|
||||
return $this->namespace[$ns]['data'][$key];
|
||||
}
|
||||
|
||||
public function has($ns, $key) {
|
||||
return isset($this->namespace[$ns]['data'][$key]);
|
||||
}
|
||||
|
||||
function set($ns, $key, $value) {
|
||||
$this->namespace[$ns]['data'][$key] = $value;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue