-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateModel.php
More file actions
46 lines (39 loc) · 1.49 KB
/
CreateModel.php
File metadata and controls
46 lines (39 loc) · 1.49 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
<?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 CreateModel extends Command
{
public function configure()
{
$this->setName("new:model")
->setDescription('Make a new model')
->addArgument('model', InputArgument::REQUIRED, "Model Name")
->addArgument('app', InputArgument::REQUIRED, "Model Name");
}
public function execute(InputInterface $input, OutputInterface $output)
{
$model = $input->getArgument('model');
$app= $input->getArgument('app');
$this->new($model, $app, $output);
}
public static function new($model, $app, OutputInterface $output)
{
$basedir = $_SERVER['DOCUMENT_ROOT'];
if (file_exists('application/App/'.$app.'/Models/'.$model.'.php')) {
$output->writeln('Model already exists. Try renaming you model');
return false;
}
$file = fopen('application/App/'.$app.'/Models/'.$model.'.php', "w");
$data = "<?php\n\n";
$data .= "namespace App\\$app\\Models;\n\n";
$data .= "use Mira\Models\Model;\n\n";
$data .= "class $model extends Model\n";
$data .= "{\n\x20\x20\x20\x20\x20// A Model for the $app App\n}\n";
fwrite($file, $data);
fclose($file);
$output->writeln("Model Created");
}
}