-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreator.php
97 lines (87 loc) · 2.78 KB
/
creator.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
<?php
define('ROOT_PATH', __DIR__);
define('DS', DIRECTORY_SEPARATOR);
define('DATA_PATH', ROOT_PATH.DS.'data');
define('DICT_PATH', DATA_PATH.DS.'dict');
define('NOTE_PATH', DATA_PATH.DS.'notes');
define('OUTPUT_PATH', DATA_PATH.DS.'output');
require_once ROOT_PATH.'/Autoloader.php';
class Creator {
private static $_docs = array();
public static function run($argv) {
self::init();
$bin = isset($argv[0]) ? $argv[0] : '';
$package = isset($argv[1]) ? $argv[1] : '';
$cmd = isset($argv[2]) ? $argv[2] : '';
if ($package == '') {
exit("请选择扩展名\n");
}
switch ($cmd) {
case 'create':
self::create($package);
break;
case 'transform':
self::transform($package);
break;
case 'note':
self::note($package);
break;
default:
self::help($package, $bin);
}
}
public static function create($package) {
try {
$doc = self::getDocument($package);
$doc->create();
} catch (Exception $ex) {
echo "create error:\n".$ex->getMessage();
}
}
public static function transform($package) {
try {
$doc = self::getDocument($package);
$path = NOTE_PATH.DS.$package;
$fileName = NOTE_PATH.DS.$package.'.php';
if (is_dir($path)) {
$fileName = $path;
}
$transform = new \phpDocumentCreator\Transform($fileName);
$data = $transform->info('X', "_");
$doc->updateDict('swoole', $data);
self::create($package);
} catch (Exception $ex) {
echo "create error:\n".$ex->getMessage();
}
}
public static function note($package) {
$fileName = NOTE_PATH.DS.$package.DS.'swoole_async.php';
require_once($fileName);
$data = \phpDocumentCreator\Tool::export('swooleX', true);
}
public static function getDocument($package) {
if (isset(self::$_docs[$package])) {
return self::$_docs[$package];
}
self::$_docs[$package] = new \phpDocumentCreator\Document($package);
return self::$_docs[$package];
}
public static function help($package, $bin) {
echo "Usage: ".$bin." ".$package." create | transform \n";
}
public static function init() {
if (!file_exists(DATA_PATH)) {
mkdir(DATA_PATH);
}
if (!file_exists(DICT_PATH)) {
mkdir(DICT_PATH);
}
if (!file_exists(NOTE_PATH)) {
mkdir(NOTE_PATH);
}
if (!file_exists(OUTPUT_PATH)) {
mkdir(OUTPUT_PATH);
}
}
}
Creator::run($argv);