Skip to content

Commit cf67057

Browse files
author
宋非凡
committed
add model generating
1 parent d8d2a49 commit cf67057

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/bin/make.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
# TODO
44
# AUTO-GENERATING MY_MODELS
55

6-
$my_models = " *";
6+
static $my_models = " *\n";
7+
8+
$app_path = dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/application/models';
9+
10+
work($app_path, $my_models);
711

812
$my_models_tpl = <<<MY_MODELS_TPL
913
<?php die();
@@ -29,4 +33,36 @@ class my_models
2933
MY_MODELS_TPL;
3034

3135
$filename = dirname(dirname(__FILE__)) . '/my_models.php';
32-
file_put_contents($filename, $my_models_tpl);
36+
file_put_contents($filename, $my_models_tpl);
37+
38+
function work($file, &$my_models)
39+
{
40+
if (is_dir($file)) {
41+
$list = scandir($file);
42+
foreach ($list as $item) {
43+
if ($item == '.') continue;
44+
if ($item == '..') continue;
45+
$item = $file . '/' . $item;
46+
if (is_dir($item)) { // 目录,继续向下遍历
47+
work($item, $my_models);
48+
} else { // 文件,则判断是否PHP,cd
49+
50+
if (pathinfo($item, PATHINFO_EXTENSION) == 'php') {
51+
$model_name = get_model_name($item);
52+
$my_models .= " * @property $model_name $model_name\n";
53+
}
54+
}
55+
}
56+
} else {
57+
echo "not dir!!";
58+
}
59+
}
60+
61+
echo $my_models;
62+
63+
function get_model_name($file)
64+
{
65+
$file = basename($file);
66+
$file = str_replace('.php', '', $file);
67+
return $file;
68+
}

0 commit comments

Comments
 (0)