FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
framework/libs/function/cli.php at master · bojackcode/framework · GitHub
bojackcode
framework
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
framework
/
libs
/
function
/
cli.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
151 lines (147 loc) · 4.34 KB
Breadcrumbs
framework
/
libs
/
function
/
cli.php
Copy path
File metadata and controls
151 lines (147 loc) · 4.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* 导入所有controller
* @return unknown_type
*/
function
import_all_controller(
$
apps_path
)
{
$
d
=
dir
(
$
apps_path
.
'
/controllers
'
);
if
(
empty
(
$
d
))
{
return
false
;
}
while
(
$
file
=
$
d
->
read
())
{
$
name
=
basename
(
$
file
,
'
.php
'
);
//不符合命名规则
if
(!
preg_match
(
'
/^[a-z0-9_]+$/i
'
,
$
name
))
continue
;
//首字母大写的controller为基类控制器,不直接提供响应
if
(ord(
$
name
{
0
})>
64
and
ord
(
$
name
{
0
})<
91
) continue;
$
path
=
$
d
->
path
.
'
/
'
.
$
file
;
import_controller
(
$
name
,
$
path
);
}
$
d
->
close
();
}
function
import_controller
(
$
name
,
$
path
)
{
global
$
php
;
require
(
$
path
);
$
php
->
env
[
'
controllers
'
][
$
name
] =
array
(
'
path
'
=>
$
path
,
'
time
'
=>
time
());
}
/**
* 检查是否加载了某个扩展
* @param $ext_name
* @return unknown_type
*/
function
require_ext
(
$
ext_name
)
{
if
(
extension_loaded
(
$
ext_name
))
return
true
;
else
return
new
Error
(
'
require php extension <b>
'
.
$
ext_name
.
'
</b>
'
);
}
/**
* 导入所有model
* @return unknown_type
*/
function
import_all_model()
{
global
$
php
;
$
d
=
dir
(
APPSPATH
.
'
/models
'
);
while
(
$
file
=
$
d
->
read
())
{
$
name
=
basename
(
$
file
,
'
.model.php
'
);
//不符合命名规则
if
(!
preg_match
(
'
/^[a-z0-9_]+$/i
'
,
$
name
))
continue
;
//首字母大写的controller为基类控制器,不直接提供响应
if
(
ord
(
$
name
{
0
})>
64
and
ord
(
$
name
{
0
})<
91
) continue;
$
path
=
$
d
->
path
.
'
/
'
.
$
file
;
require
(
$
path
);
$
php
->
env
[
'
controllers
'
][
$
name
] =
$
path
;
}
$
d
->
close
();
}
/**
* 创建控制器类的文件
* @param $name
* @return unknown_type
*/
function
create_controllerclass
(
$
name
,
$
hello
=
false
)
{
$
content = "";
$
content
.=
"
<?php
\n"
;
$
content
.=
"
class
{
$
name
}
extends Controller
\n"
;
$
content
.=
"
{
\n"
;
$
content
.=
"
function __construct(
\$
swoole)
\n"
;
$
content
.=
"
{
\n"
;
$
content
.=
"
parent::__construct(
\$
swoole);
\n"
;
$
content
.=
"
}
\n"
;
//添加一个hello vie
if
(
$
hello
)
{
$
content
.=
"
function index(
\$
swoole)
\n"
;
$
content
.=
"
{
\n"
;
$
content
.=
"
echo 'hello world.This page build by <a href=http://www.swoole.com/>swoole</a>!';
\n"
;
$
content
.=
"
}
\n"
;
}
$
content
.=
"
}
"
;
file_put_contents
(
WEBPATH
.
'
/apps/controllers/
'
.
$
name
.
'
.php
'
,
$
content
);
}
/**
* 创建模型类的文件
* @param $name
* @return unknown_type
*/
function
create_modelclass
(
$
name
,
$
table
=
''
)
{
$
content
=
""
;
$
content
.=
"
<?php
\n"
;
$
content
.=
"
class
{
$
name
}
extends Model
\n"
;
$
content
.=
"
{
\n"
;
$
content
.=
"
//Here write Database table's name
\n"
;
$
content
.=
"
var
\$
table = '
{
$
table
}
';
\n"
;
$
content
.=
"
}
"
;
file_put_contents
(
WEBPATH
.
'
/apps/models/
'
.
$
name
.
'
.model.php
'
,
$
content
);
}
/**
* 创建必需的目录
* @return unknown_type
*/
function
create_require_dir
()
{
/**
* 建立MVC目录
*/
if
(!
is_dir
(
WEBPATH
.
'
/apps
'
))
mkdir
(
WEBPATH
.
'
/apps
'
,
0755
);
if
(!
is_dir
(
WEBPATH
.
'
/apps/controllers
'
))
mkdir
(
WEBPATH
.
'
/apps/controllers
'
,
0755
);
if
(!
is_dir
(
WEBPATH
.
'
/apps/models
'
))
mkdir
(
WEBPATH
.
'
/apps/models
'
,
0755
);
/**
* 建立缓存的目录
*/
if
(!
is_dir
(
WEBPATH
.
'
/cache
'
))
mkdir
(
WEBPATH
.
'
/cache
'
,
0755
);
if
(!
is_dir
(
WEBPATH
.
'
/cache/pages_c
'
))
mkdir
(
WEBPATH
.
'
/cache/pages_c
'
,
0777
);
if
(!
is_dir
(
WEBPATH
.
'
/cache/templates_c
'
))
mkdir
(
WEBPATH
.
'
/cache/templates_c
'
,
0777
);
if
(!
is_dir
(
WEBPATH
.
'
/cache/filecache
'
))
mkdir
(
WEBPATH
.
'
/cache/filecache
'
,
0777
);
/**
* Smarty的模板目录
*/
if
(!
is_dir
(
WEBPATH
.
'
/templates
'
))
mkdir
(
WEBPATH
.
'
/templates
'
,
0755
);
/**
* 建立静态文件的目录
*/
if
(!
is_dir
(
WEBPATH
.
'
/static
'
))
mkdir
(
WEBPATH
.
'
/static
'
,
0755
);
if
(!
is_dir
(
WEBPATH
.
'
/static/images
'
))
mkdir
(
WEBPATH
.
'
/static/images
'
,
0755
);
if
(!
is_dir
(
WEBPATH
.
'
/static/css
'
))
mkdir
(
WEBPATH
.
'
/static/css
'
,
0755
);
if
(!
is_dir
(
WEBPATH
.
'
/static/uploads
'
))
mkdir
(
WEBPATH
.
'
/static/uploads
'
,
0755
);
if
(!
is_dir
(
WEBPATH
.
'
/static/js
'
))
mkdir
(
WEBPATH
.
'
/static/js
'
,
0755
);
/**
* 建立外部扩展类目录
*/
if
(!
is_dir
(
WEBPATH
.
'
/class
'
))
mkdir
(
WEBPATH
.
'
/class
'
,
0755
);
/**
* 建立网站字典目录
*/
if
(!
is_dir
(
WEBPATH
.
'
/dict
'
))
mkdir
(
WEBPATH
.
'
/dict
'
,
0755
);
/**
* 建立Swoole插件系统目录
*/
if
(!
is_dir
(
WEBPATH
.
'
/swoole_plugin
'
))
mkdir
(
WEBPATH
.
'
/swoole_plugin
'
,
0755
);
}
Back
|
FazBrowse Home
|
New Git URL