-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateApp.php
163 lines (141 loc) · 5.54 KB
/
CreateApp.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
namespace MiraCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
class CreateApp extends Command
{
public function configure()
{
$this->setName("new:app")
->setDescription('Make a new app')
->addArgument('app', InputArgument::REQUIRED, "Model Name");
}
public function execute(InputInterface $input, OutputInterface $output)
{
$app= $input->getArgument('app');
$this->new($app, $output);
}
public static function new($app, OutputInterface $output)
{
$created = true;
if (file_exists("application/App/$app")) {
$output->writeln("App already exists. Please rename your app.");
return false;
}
$output->writeln("Creating app folder ... ");
if (mkdir("application/App/$app")) {
$output->writeln("created successfully!\n");
} else {
echo "failed\n";
$created = false;
}
$output->writeln("Creating app config file ... ");
// Create config file
$configfile = "<?php\n\n";
$configfile .= "return [\n";
$configfile .= "\x20\x20\x20\x20\x20//'header' => '$app.header',\n";
$configfile .= "\x20\x20\x20\x20\x20//'footer' => '$app.footer',\n";
$configfile .= "];\n";
if (file_put_contents("application/App/$app/config.php", $configfile)) {
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
// Create templates folder
$output->writeln("Creating app template folder ... ");
if (mkdir("application/App/$app/templates")) {
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
// Create resources folder
$output->writeln("Creating app images folder ... ");
if (mkdir("application/App/$app/images")) {
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
// Create resources folder
$output->writeln("Creating app js folder ... ");
if (mkdir("application/App/$app/js")) {
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
// Create css folder
$output->writeln("Creating app css folder ... ");
if (mkdir("application/App/$app/css")) {
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
$output->writeln("Creating app routes folder ... ");
if (mkdir("application/App/$app/Routes")) {
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
$output->writeln("Creating app routes/routes.php file ... ");
if (fopen("application/App/$app/Routes/Routes.php", "a")) {
$startroute = "<?php\n\n";
$startroute .= "use Mira\Route;\n";
$startroute .= "use Mira\Render\Render;\n\n";
$startroute .= "// Routes Here\n";
file_put_contents("application/App/$app/Routes/Routes.php", $startroute);
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
$output->writeln("Creating app controller folder ... ");
if (mkdir("application/App/$app/Controller")) {
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
$output->writeln("Creating app controller/controller.php file ... ");
if (fopen("application/App/$app/Controller/Controller.php", "a")) {
$startcontroller = "<?php\n\n";
$startcontroller .= "use Mira\Controller\Controller;\n\n";
$startcontroller .= "// Controllers Here\n";
file_put_contents("application/App/$app/Controller/Controller.php", $startcontroller);
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
$output->writeln("Creating app model folder ... ");
if (mkdir("application/App/$app/Models")) {
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed");
$created = false;
}
$output->writeln("Creating app models/models.php file ... ");
if (fopen("application/App/$app/Models/StarterModel.php", "w")) {
$startmodel = "<?php\n\n";
$startmodel .= "namespace App\\$app\Models;\n\n";
$startmodel .= "use Mira\Models\Model;\n\n";
$startmodel .= "// Models Here\n";
file_put_contents("application/App/$app/Models/StarterModel.php", $startmodel);
$output->writeln("created successfully!\n");
} else {
$output->writeln("failed!");
$created = false;
}
if ($created) {
$output->writeln("App Successfully Created!");
} else {
$output->writeln("App could not be created ...");
}
}
}