forked from unikent/baum
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathInstallCommand.php
128 lines (113 loc) · 2.76 KB
/
InstallCommand.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
<?php
namespace Baum\Console;
use Baum\Generators\MigrationGenerator;
use Baum\Generators\ModelGenerator;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
class InstallCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'baum:install';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Scaffolds a new migration and model suitable for Baum.';
/**
* Migration generator instance.
*
* @var \Baum\Generators\MigrationGenerator
*/
protected $migrator;
/**
* Model generator instance.
*
* @var \Baum\Generators\ModelGenerator
*/
protected $modeler;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(MigrationGenerator $migrator, ModelGenerator $modeler)
{
parent::__construct();
$this->migrator = $migrator;
$this->modeler = $modeler;
}
/**
* Execute the console command.
*
* Basically, we'll write the migration and model stubs out to disk inflected
* with the name provided. Once its done, we'll `dump-autoload` for the entire
* framework to make sure that the new classes are registered by the class
* loaders.
*
* @return void
*/
public function fire()
{
$name = $this->input->getArgument('name');
$this->writeMigration($name);
$this->writeModel($name);
}
/**
* Get the command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['name', InputArgument::REQUIRED, 'Name to use for the scaffolding of the migration and model.'],
];
}
/**
* Write the migration file to disk.
*
* @param string $name
*
* @return void
*/
protected function writeMigration($name)
{
$output = pathinfo($this->migrator->create($name, $this->getMigrationsPath()), PATHINFO_FILENAME);
$this->line(" <fg=green;options=bold>create</fg=green;options=bold> $output");
}
/**
* Write the model file to disk.
*
* @param string $name
*
* @return void
*/
protected function writeModel($name)
{
$output = pathinfo($this->modeler->create($name, $this->getModelsPath()), PATHINFO_FILENAME);
$this->line(" <fg=green;options=bold>create</fg=green;options=bold> $output");
}
/**
* Get the path to the migrations directory.
*
* @return string
*/
protected function getMigrationsPath()
{
return $this->laravel->databasePath();
}
/**
* Get the path to the models directory.
*
* @return string
*/
protected function getModelsPath()
{
return $this->laravel->basePath();
}
}