-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartisan
80 lines (62 loc) · 1.93 KB
/
artisan
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
#!/usr/bin/env php
<?php
$commands = '';
// Input
$input = $argv[1] ?? 'run';
switch ($input) {
case 'run':
$ports = $argv[2] ?? 8080;
$commands = 'php -S localhost:' . $ports . ' -t public';
break;
case 'make:migration':
$name = $argv[2] ?? 'R' . date('Y_m_d_H_i_s');
$commands = './vendor/bin/phinx create ' . $name;
break;
case 'make:seeder':
$name = $argv[2] ?? 'S' . date('Y_m_d_H_i_s');
$commands = './vendor/bin/phinx seed:create ' . $name;
break;
case 'make:controller':
$name = $argv[2] ?? 'C' . date('Y_m_d_H_i_s');
// Check if file exists
if (file_exists('src/Controller/' . $name . '.php')) {
echo 'File already exists';
exit;
}
// Create file
$file = fopen('src/Controller/' . $name . '.php', 'w');
$txt = file_get_contents('stubs/Controller.stub');
$txt = str_replace('{class}', $name, $txt);
fwrite($file, $txt);
fclose($file);
break;
case 'make:view':
$name = $argv[2] ?? 'M' . date('Y_m_d_H_i_s');
// Check if file exists
if (file_exists('src/View/' . $name . '.blade.php')) {
echo 'File already exists';
exit;
}
// Create file
$file = fopen('src/View/' . $name . '.blade.php', 'w');
$txt = file_get_contents('stubs/View.stub');
fwrite($file, $txt);
fclose($file);
break;
case 'migrate':
$commands = './vendor/bin/phinx migrate';
break;
case 'db:seed':
$name = isset($argv[2]) ? '-s ' . $argv[2] : '';
$commands = './vendor/bin/phinx seed:run ' . $name;
break;
case 'rollback':
$commands = './vendor/bin/phinx rollback';
break;
default:
echo 'Command not found';
break;
}
if($commands) {
shell_exec($commands);
}