Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
UConfigFile.php
Go to the documentation of this file.
1<?php
2
3namespace Ubiquity\utils\base;
13class UConfigFile {
14
15 private string $filename;
16
17 private array $data=[];
18
19 public function __construct(string $name){
20 $this->filename=\ROOT . "config/$name.config.php";
21 }
22
23 public function load(array $default=[]): array {
24 return $this->data=self::load_($this->filename,$default);
25 }
26
27 public function save(): bool {
28 return self::save_($this->filename, $this->data);
29 }
30
31 public function get(string $key,$default=null){
32 return $this->data[$key]??$default;
33 }
34
35 public function set(string $key,$value):self{
36 $this->data[$key]=$value;
37 return $this;
38 }
39
43 public function getData(): array {
44 return $this->data;
45 }
46
50 public function setData(array $data): self {
51 $this->data = $data;
52 return $this;
53 }
54
55
56
57 public static function load_(string $filename,array $default=[]):array {
58 if(\file_exists($filename)){
59 return include($filename);
60 }
61 return $default;
62 }
63
64 public static function save_(string $filename,array $data):bool{
65 return false!==UFileSystem::save($filename, '<?php return '.UArray::asPhpArray_($data,1,true).';');
66 }
67}
68