-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.php
More file actions
86 lines (80 loc) · 2.66 KB
/
cli.php
File metadata and controls
86 lines (80 loc) · 2.66 KB
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
<?php
use Model\Model;
use Utils\Util;
use Utils\Bcrypt;
use Utils\BuildInPageCSS;
if (php_sapi_name() == "cli") {
require_once dirname(__FILE__).'/Utils/functions.php';
switch ($argv[1]) {
case "modules:reread":
require_once dirname(__FILE__).'/'.$_ENV['ADMIN_FOLDER_URL']
.'/modules.php';
reread();
break;
case "generate":
$tableName = $argv[2];
$className = str_replace('_', '', Util::ucname($tableName));
$table = new Model($tableName);
$tableSchema = $table->schema;
$properties = '';
foreach ($tableSchema as $propertyName => $propertyDetails) {
$data_type = false;
switch ($propertyDetails['DATA_TYPE']) {
case 'int':
case 'tinyint':
case 'smallint':
case 'mediumint':
case 'bigint':
case 'boolean':
$data_type = 'int';
break;
case 'decimal':
case 'float':
case 'double':
case 'real':
$data_type = 'float';
break;
case 'varchar':
case 'text':
case 'tinyblob':
case 'mediumblob':
case 'blob':
case 'longblob':
$data_type = 'string';
break;
default:
break;
}
if ($data_type) {
if ($propertyDetails['null'] === 'YES') {
$data_type = '?'.$data_type;
}
$properties .= ' public '.$data_type.' $'
.$propertyName.';'.PHP_EOL;
}
}
file_put_contents($_ENV['APP_DIR'].'/Model/'.$className.'.php', '<?php
namespace Model {
class '.$className.' extends Model
{
'.$properties.'
public array $schema = '.str_replace("\n", "\n ",
var_export($tableSchema, true)).';
public function __construct() {
parent::__construct(\''.$tableName.'\');
}
}
}');
break;
case "buildcss":
$buildCss = new BuildInPageCSS($argv[2]);
break;
case "buildpass":
$bcrypt = new Bcrypt(10);
$pass = $bcrypt->hash($argv[2]);
debug($pass);
break;
default:
break;
}
}