Repository navigation
Expand file tree
/
Copy pathConfig.php
More file actions
83 lines (69 loc) · 1.71 KB
/
Copy pathConfig.php
File metadata and controls
83 lines (69 loc) · 1.71 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/*
* Inphinit
*
* Copyright (c) 2026 Guilherme Nascimento (brcontainer@yahoo.com.br)
*
* Released under the MIT license
*/
namespace Inphinit;
use Inphinit\Diagnostics\Inspector;
class Config
{
private $exceptionLevel = 3;
private $data = array();
private $path;
/**
* Load items from a config file in a object
*
* @param string $path
* @throws \Inphinit\Exception
*/
public function __construct($path)
{
if (preg_match('#^\w+(\.\w[\w\.]+)?$#', $path) !== 1) {
throw new Exception('Invalid config path');
}
$this->path = 'configs/' . str_replace('.', '/', $path) . '.php';
$this->reload();
}
/**
* Reload configuration from file
*
* @throws \Inphinit\Exception
*/
public function reload()
{
$level = $this->exceptionLevel;
$this->exceptionLevel = 2;
$configs = inphinit_sandbox($this->path);
if (is_array($configs) === false) {
throw new Exception($this->path . ' configurations cannot be loaded or format is invalid', 0, $level);
}
$this->data = $configs;
}
/**
* Magic method for get specific item
*
* @param string $name
* @return mixed
*/
public function __get($name)
{
return isset($this->data[$name]) ? $this->data[$name] : null;
}
/**
* Magic method for check if value exists in top-level
*
* @param string $name
* @return bool
*/
public function __isset($name)
{
return isset($this->data[$name]);
}
public function __set($name, $value)
{
throw new Exception('Creation of dynamic property is not allowed');
}
}