forked from TIGERB/easy-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli
96 lines (84 loc) · 2.73 KB
/
cli
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
#!/usr/bin/php
<?php
/********************************************
* Easy PHP *
* *
* A lightweight PHP framework for studying *
* *
* TIERGB *
* <https://github.com/TIGERB> *
* *
********************************************/
/**
* cli模式
*
* 在php cli模式下运行框架运行框架
*/
// php cli --env=<environment> --<method|job>=<value> --<arguments>=<value> ...
// \033[33m env \033[0m: Script run environment
//
/**
* 命令行参数list
*/
$help = function () {
$string = <<<HELP
\033[36m Cli Usage \033[0m:
php cli --<method||job>=<value> --<arguments>=<value> ...
\033[36m Example \033[0m:
php cli --method=demo.index.get --username=test
php cli --job=demo.demo.test --username=test
\033[36m Params mean \033[0m:
\033[33m method \033[0m: The function will running, value format <module.controller.action>
\033[33m job \033[0m: The function will running, value format <module.job.action>
\033[33m arguments \033[0m: Input arguments
\033[33m help \033[0m: Display command list
\033[36m Web Server Usage \033[0m:
step 1: cd public
step 2: php -S <addr>:<port>
For example, php -S 'localhost:666', after that open website 'http://localhost:666/'
\033[32mEasy PHP: A Faster Lightweight Full-Stack PHP Framework. Version 0.7.0\033[0m
\033[32mAuthor : TIGERB <https://github.com/TIGERB>\033[0m
\n
HELP;
die($string);
};
/**
* 获取参数
*/
if (count($argv) === 1) {
$help();
}
$input = [];
foreach ($argv as $v) {
preg_match_all('/^--(.*)/', $v, $match);
if (isset($match[1][0]) && ! empty($match[1][0])) {
$match = explode('=', $match[1][0]);
if ($match[0] === 'help') {
$help();
}
if (isset($match[1])) {
$input[$match[0]] = $match[1];
}
}
}
// 设置cli模式
putenv('IS_CLI=yes');
if (isset($input['method'])) {
$method = $input['method'];
$method = explode('.', $method);
$input['module'] = $method[0];
$input['controller'] = $method[1];
$input['action'] = $method[2];
$input['router_mode']= 'controller';
unset($input['method']);
} else {
$job = $input['job'];
$job = explode('.', $job);
$input['module'] = $job[0];
$input['job'] = $job[1];
$input['action'] = $job[2];
$input['router_mode']= 'job';
}
$_REQUEST['argv'] = $input;
// 载入框架运行文件
require('framework/run.php');