1 | <?php |
||
12 | class App extends Container { |
||
13 | /** |
||
14 | * 已经加载的config文件 |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $loadedConfigurations = []; |
||
19 | |||
20 | /** |
||
21 | * 应用的根目录. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $basePath; |
||
26 | public function __construct($basePath) { |
||
32 | |||
33 | private function initEnv(){ |
||
34 | try{ |
||
35 | $dotEnv = new Dotenv($this->basePath); |
||
36 | $dotEnv->load(); |
||
37 | } |
||
38 | catch (\Dotenv\Exception\InvalidPathException $e){ |
||
|
|||
39 | |||
40 | } |
||
41 | date_default_timezone_set(env('APP_TIMEZONE', 'Asia/Shanghai')); |
||
42 | define('IS_CLI', $this->runningInConsole()); |
||
43 | define('IS_DEBUG',env('DEBUG',false)); |
||
44 | if (IS_DEBUG) { |
||
45 | error_reporting(E_ALL); |
||
46 | @ini_set('display_errors', 'On'); |
||
47 | //@ob_start(); |
||
48 | $whoops=new Run; |
||
49 | $handle=IS_CLI ? "PlainTextHandler" : "PrettyPageHandler"; |
||
50 | $handle="\\Whoops\\Handler\\".$handle; |
||
51 | $whoops->pushHandler(new $handle); |
||
52 | $whoops->register(); |
||
53 | } |
||
54 | |||
55 | } |
||
56 | |||
57 | /** |
||
58 | * 判断是否是cli模式 |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function runningInConsole() { |
||
65 | |||
66 | /** |
||
67 | * 初始化容器 |
||
68 | */ |
||
69 | private function initContainer() { |
||
81 | |||
82 | private function initConfig() { |
||
85 | |||
86 | /** |
||
87 | * 加载一个配置文件 |
||
88 | * |
||
89 | * @param string $name |
||
90 | * @return void |
||
91 | */ |
||
92 | public function configure($name) |
||
104 | |||
105 | /** |
||
106 | * 获取配置文件的路径。 |
||
107 | * |
||
108 | * 如果没有给定配置文件的名字,则返回目录。 |
||
109 | * |
||
110 | * 如果应用目录下有相应配置文件则优先返回。 |
||
111 | * |
||
112 | * @param string|null $name |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getConfigurationPath($name = null) |
||
134 | |||
135 | /** |
||
136 | * Get the base path for the application. |
||
137 | * |
||
138 | * @param string|null $path |
||
139 | * @return string |
||
140 | */ |
||
141 | 3 | public function basePath($path = null) { |
|
154 | |||
155 | public function run() { |
||
158 | } |