-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.php
More file actions
121 lines (109 loc) · 2.8 KB
/
Copy pathapp.php
File metadata and controls
121 lines (109 loc) · 2.8 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
// +----------------------------------------------------------------------
// | phpth|phpy: msg-server
// +----------------------------------------------------------------------
// | Copyright (c) 2018
// +----------------------------------------------------------------------
// | Licensed MIT
// +----------------------------------------------------------------------
// | Author: luajia
// +----------------------------------------------------------------------
// | Date: 2018/9/27 0027
// +----------------------------------------------------------------------
// | Time: 下午 20:52
// +----------------------------------------------------------------------
namespace bin;
use Exception;
class app
{
const version = '0.10';
/**
* 需要固定加载的文件
* @var array
*/
protected static $load_file = [
'common/common.php',
'vendor/autoload.php',
];
/**
* 创建框架所需文件夹
* @var array
*/
protected static $need_create_dir = [
TMP_PATH,
];
/**
* 开始框架处理
* @param string $mode_class 运行模式的类命名空间
* @return mixed
* @throws Exception
*/
public static function start($mode_class = 'bin\mode\cli')
{
app::load ();
app::createDir();
app::register ();
$param = (new $mode_class())->param();
return app::run($param['construct'],$param['action']);
}
/**
* 带参数并且执行控制器
* @param array $construct_param
* @param array $action_param
* @return mixed
*/
protected static function run(array $construct_param, array $action_param)
{
$class = CONTROLLER;
return (new $class(...$construct_param))->{ACTION}(...$action_param);
}
/**
* 注册框架自动加载
*/
protected static function register()
{
spl_autoload_register (__NAMESPACE__.'\app::autoLoad',true,true);
}
/**
* 框架自动加载逻辑
* @param $class
* @return mixed
*/
public static function autoLoad($class)
{
$class_file = (str_replace ( '\\' , '/' , $class)).'.php';
$class_path = ROOT_PATH."{$class_file}";
if(file_exists ( $class_path))
{
require $class_path;
}
else
{
return null;
}
return $class;
}
/**
* 加载核心文件
*/
protected static function load()
{
foreach (app::$load_file as $v)
{
require ROOT_PATH.$v;
}
}
/**
* 创建所需文件夹
*/
protected static function createDir()
{
foreach (app::$need_create_dir as $v)
{
if(!is_dir($v))
{
mkdir($v,0755,true);
}
}
}
}