forked from shenzhe/zphp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.php
101 lines (87 loc) · 2.9 KB
/
build.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
require 'ZPHP/Common/Dir.php';
echo "pls enter app path:".PHP_EOL;
$app_path = trim(fgets(STDIN));
if(is_dir($app_path)) {
echo 'dir is exist, continue~~ pls input Y or N'.PHP_EOL;
$ret = trim(fgets(STDIN));
if('y' !== strtolower($ret)) {
return;
}
}
if(ZPHP\Common\Dir::make($app_path)) {
$dirList = array(
'apps'.DIRECTORY_SEPARATOR.'ctrl'.DIRECTORY_SEPARATOR.'main',
'apps'.DIRECTORY_SEPARATOR.'entity',
'apps'.DIRECTORY_SEPARATOR.'dao',
'apps'.DIRECTORY_SEPARATOR.'service',
'apps'.DIRECTORY_SEPARATOR.'common',
'config'.DIRECTORY_SEPARATOR.'default',
'config'.DIRECTORY_SEPARATOR.'public',
'template',
'webroot'.DIRECTORY_SEPARATOR.'static',
);
foreach($dirList as $realPath) {
if(ZPHP\Common\Dir::make($app_path.DIRECTORY_SEPARATOR.$realPath)) {
echo $realPath." done...".PHP_EOL;
}
}
$mainTxt = '<?php
use ZPHP\ZPHP;
$rootPath = dirname(__DIR__);
require \''.__DIR__.'\'. DIRECTORY_SEPARATOR . \'ZPHP\' . DIRECTORY_SEPARATOR . \'ZPHP.php\';
ZPHP::run($rootPath);';
file_put_contents($app_path.DIRECTORY_SEPARATOR.'webroot'.DIRECTORY_SEPARATOR.'main.php', $mainTxt);
echo "main.php done...".PHP_EOL;
$ctrlTxt = '<?php
namespace ctrl\main;
use ZPHP\Controller\IController,
ZPHP\Core\Config,
ZPHP\View;
use ZPHP\Protocol\Request;
class main implements IController
{
public function _before()
{
return true;
}
public function _after()
{
//
}
public function main()
{
$project = Config::getField(\'project\', \'name\', \'zphp\');
$data = $project." runing!\n";
$params = Request::getParams();
if(!empty($params)) {
foreach($params as $key=>$val) {
$data.= "key:{$key}=>{$val}\n";
}
}
return $data;
}
}
';
file_put_contents($app_path.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.'ctrl'.DIRECTORY_SEPARATOR.'main'.DIRECTORY_SEPARATOR.'main.php', $ctrlTxt);
echo "ctrl done...".PHP_EOL;
echo "pls enter project_name:".PHP_EOL;
$project_name = trim(fgets(STDIN));
$configTxt = '<?php
return array(
\'server_mode\' => (PHP_SAPI === \'cli\') ? \'Cli\' : \'Http\',
\'app_path\'=>\'apps\',
\'ctrl_path\'=>\'ctrl\',
\'project\'=>array(
\'name\'=>\''.$project_name.'\',
\'view_mode\'=>\'Str\',
\'ctrl_name\'=>\'a\',
\'method_name\'=>\'m\',
)
);
';
file_put_contents($app_path.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.'config.php', $configTxt);
echo "config done...".PHP_EOL;
echo "finish...".PHP_EOL;
}
return;