-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathartisan.php
More file actions
144 lines (122 loc) · 4.6 KB
/
Copy pathartisan.php
File metadata and controls
144 lines (122 loc) · 4.6 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/php
<?php
declare(strict_types=1);
define("CONTROLL_PATH", dirname(__FILE__) . DIRECTORY_SEPARATOR . "application" . DIRECTORY_SEPARATOR . "controller" . DIRECTORY_SEPARATOR);
define("MODEL_PATH", dirname(__FILE__) . DIRECTORY_SEPARATOR . "application" . DIRECTORY_SEPARATOR . "model" . DIRECTORY_SEPARATOR);
$avaible_cmd = [
'--help',
'-help',
'-h',
'--controller',
'--model',
'--view'
];
$file = $argc;
$cmd = $argv;
function writeFile($name = "", string $type = "*") {
if($type == "controller") {
$controller = "<?php\r\nnamespace App\controller;".
"\r\n\r\n\r\nclass ". ucfirst($name) ." extends Controller {\r\n".
" public function __construct() {\n".
" parent::__construct();\r\n".
" // load other functions\r\n".
" //#this->load_model('ModelName')\n".
" //#this->pageName('Page Title')".
"\r\n }\r\n".
// Public index function
"\n public function index() {\n".
" //View::view('view_name');\r\n".
"\r\n }".
"\r\n}";
$fh = fopen(CONTROLL_PATH . ucfirst($name) . ".php", 'w+');
fwrite($fh, $controller);
fclose($fh);
echo "\033[35;2m\e[78m" . "Controller ". ucfirst($name) ." created!";
}
if($type == "model") {
$model = "<?php\r\nnamespace App\model;".
"\r\n\r\nuse Core\Model;".
"\r\n\r\nclass ". ucfirst($name) ." extends Model {\r\n".
" protected @fillable = [];\r\n".
" protected @table = '';\r\n".
" public @errors = [];\r\n".
"\r\n\r\n".
" public function rules() : array {\r\n".
" return [];\r\n".
" }".
"\r\n}";
$fh = fopen(MODEL_PATH . ucfirst($name) . ".php", 'w+');
$model = preg_replace("/@/i", "$", $model);
fwrite($fh, $model);
fclose($fh);
echo "\033[35;2m\e[78m" . "Model {$name} created!";
}
}
function getParams(string $parms, string $name) {
global $argv;
if(isset($argv) && $name != "") {
switch($parms) {
case "controller":
if(!file_exists(CONTROLL_PATH . ucfirst($name) . ".php")) {
writeFile($name, "controller");
} else {
echo "\033[35;2m\e[78m" . "Controller ". ucfirst($name) ." exists!";
}
break;
case "model":
if(!file_exists(MODEL_PATH . ucfirst($name) . ".php")) {
writeFile($name, "model");
} else {
echo "\033[35;2m\e[78m" . "Model ". ucfirst($name) ." exists!";
}
break;
}
}
}
if($file != 2 || in_array($cmd[1], $avaible_cmd)) {
if($cmd[1] == "") {
echo "\033[35;2m\e[78m" . "This is a command line PHP script with one option.\r\n";
echo "Usage:\r\n";
echo "php " . $argv[0]. " <option>\r\n";
echo "\r\n<option> can be some word you would like to print out. With the --help, -help, -h, or --? options, you can get this help.";
return;
}
switch($cmd[1]) {
case '--help':
case '-help':
case '-h':
echo "\033[35;2m\e[78m" . "Welcome to Artisan Command\r\n".
"\033[32m" . "Usage Avaible CMD: \r\n".
"\033[32m" . "--help\r\n-help\r\n-h\r\n".
"\033[32m" . "--controller\r\n--model";
break;
case '--controller':
echo "Are you sure you want to do this?\r\nType 'yes' or 'y' to continue: ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim($line) != 'yes' && trim($line) != 'y') {
echo "ABORTING!\n";
exit;
}
echo "\n";
echo "Thank you, continuing...\n";
// getParams('controller');
break;
case '--model':
echo "Are you sure you want to do this?\r\nType 'yes' or 'y' to continue: ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim($line) != 'yes' && trim($line) != 'y') {
echo "ABORTING!\n";
exit;
}
echo "\n";
echo "Thank you, continuing...\n";
echo "Please enter an model name: ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
getParams('model', trim($line, "\n\r"));
break;
}
}
?>