-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.php
83 lines (71 loc) · 1.78 KB
/
Config.php
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
/**
* DframeFramework
* Copyright (c) Sławomir Kaleta.
*
* @license https://github.com/dframe/dframe/blob/master/LICENCE (MIT)
*/
namespace Dframe\Config;
use Dframe\Config\Exceptions\ConfigException;
/**
* Config Class.
*
* @author Sławomir Kaleta <[email protected]>
*/
class Config
{
/**
* @var array
*/
protected static $cfg = [];
/**
* @var string
*/
public $path;
/**
* @var string
*/
protected $file;
/**
* Config constructor.
*
* @param $file
* @param string $path
*/
public function __construct($file, $path = '')
{
if (!defined('APP_DIR')) {
throw new ConfigException('Please Define APP_DIR in Main config.php', 500);
}
$this->path = (isset($path) and !empty($path)) ? $path : APP_DIR . $path . 'Config' . DIRECTORY_SEPARATOR;
$this->file = $file;
if (file_exists($this->path . $this->file . '.php') !== true) {
self::$cfg[$file] = [];
} else {
self::$cfg[$file] = isset(self::$cfg[$file]) ? self::$cfg[$file] : include $this->path . $this->file . '.php';
}
}
/**
* @param $file
* @param null $path
*
* @return Config
*/
public static function load($file, $path = null)
{
return new self($file, $path);
}
/**
* @param null $param
* @param null $or
*
* @return mixed|null
*/
public function get($param = null, $or = null)
{
if ($param === null) {
return (isset(self::$cfg[$this->file])) ? self::$cfg[$this->file] : null;
}
return (isset(self::$cfg[$this->file][$param]) and !empty(self::$cfg[$this->file][$param])) ? self::$cfg[$this->file][$param] : $or;
}
}