|
1 | 1 | <?php |
| 2 | + |
2 | 3 | namespace Baum\Console; |
3 | 4 |
|
4 | 5 | use Baum\Generators\MigrationGenerator; |
5 | 6 | use Baum\Generators\ModelGenerator; |
6 | 7 | use Illuminate\Console\Command; |
7 | 8 | use Symfony\Component\Console\Input\InputArgument; |
8 | 9 |
|
9 | | -class InstallCommand extends Command { |
10 | | - |
11 | | - /** |
12 | | - * The console command name. |
13 | | - * |
14 | | - * @var string |
15 | | - */ |
16 | | - protected $name = 'baum:install'; |
17 | | - |
18 | | - /** |
19 | | - * The console command description. |
20 | | - * |
21 | | - * @var string |
22 | | - */ |
23 | | - protected $description = 'Scaffolds a new migration and model suitable for Baum.'; |
24 | | - |
25 | | - /** |
26 | | - * Migration generator instance |
27 | | - * |
28 | | - * @var Baum\Generators\MigrationGenerator |
29 | | - */ |
30 | | - protected $migrator; |
31 | | - |
32 | | - /** |
33 | | - * Model generator instance |
34 | | - * |
35 | | - * @var Baum\Generators\ModelGenerator |
36 | | - */ |
37 | | - protected $modeler; |
38 | | - |
39 | | - /** |
40 | | - * Create a new command instance |
41 | | - * |
42 | | - * @return void |
43 | | - */ |
44 | | - public function __construct(MigrationGenerator $migrator, ModelGenerator $modeler) { |
45 | | - parent::__construct(); |
46 | | - |
47 | | - $this->migrator = $migrator; |
48 | | - $this->modeler = $modeler; |
49 | | - } |
50 | | - |
51 | | - /** |
52 | | - * Execute the console command. |
53 | | - * |
54 | | - * Basically, we'll write the migration and model stubs out to disk inflected |
55 | | - * with the name provided. Once its done, we'll `dump-autoload` for the entire |
56 | | - * framework to make sure that the new classes are registered by the class |
57 | | - * loaders. |
58 | | - * |
59 | | - * @return void |
60 | | - */ |
61 | | - public function fire() { |
62 | | - $name = $this->input->getArgument('name'); |
63 | | - |
64 | | - $this->writeMigration($name); |
65 | | - |
66 | | - $this->writeModel($name); |
67 | | - |
68 | | - } |
69 | | - |
70 | | - /** |
71 | | - * Get the command arguments |
72 | | - * |
73 | | - * @return array |
74 | | - */ |
75 | | - protected function getArguments() { |
76 | | - return array( |
77 | | - array('name', InputArgument::REQUIRED, 'Name to use for the scaffolding of the migration and model.') |
78 | | - ); |
79 | | - } |
80 | | - |
81 | | - /** |
82 | | - * Write the migration file to disk. |
83 | | - * |
84 | | - * @param string $name |
85 | | - * @return string |
86 | | - */ |
87 | | - protected function writeMigration($name) { |
88 | | - $output = pathinfo($this->migrator->create($name, $this->getMigrationsPath()), PATHINFO_FILENAME); |
89 | | - |
90 | | - $this->line(" <fg=green;options=bold>create</fg=green;options=bold> $output"); |
91 | | - } |
92 | | - |
93 | | - /** |
94 | | - * Write the model file to disk. |
95 | | - * |
96 | | - * @param string $name |
97 | | - * @return string |
98 | | - */ |
99 | | - protected function writeModel($name) { |
100 | | - $output = pathinfo($this->modeler->create($name, $this->getModelsPath()), PATHINFO_FILENAME); |
101 | | - |
102 | | - $this->line(" <fg=green;options=bold>create</fg=green;options=bold> $output"); |
103 | | - } |
104 | | - |
105 | | - /** |
106 | | - * Get the path to the migrations directory. |
107 | | - * |
108 | | - * @return string |
109 | | - */ |
110 | | - protected function getMigrationsPath() { |
111 | | - return $this->laravel['path.database'].'/migrations'; |
112 | | - } |
113 | | - |
114 | | - /** |
115 | | - * Get the path to the models directory. |
116 | | - * |
117 | | - * @return string |
118 | | - */ |
119 | | - protected function getModelsPath() { |
120 | | - return $this->laravel['path.base']; |
121 | | - } |
| 10 | +class InstallCommand extends Command |
| 11 | +{ |
| 12 | + |
| 13 | + /** |
| 14 | + * The console command name. |
| 15 | + * |
| 16 | + * @var string |
| 17 | + */ |
| 18 | + protected $name = 'baum:install'; |
| 19 | + |
| 20 | + /** |
| 21 | + * The console command description. |
| 22 | + * |
| 23 | + * @var string |
| 24 | + */ |
| 25 | + protected $description = 'Scaffolds a new migration and model suitable for Baum.'; |
| 26 | + |
| 27 | + /** |
| 28 | + * Migration generator instance |
| 29 | + * |
| 30 | + * @var Baum\Generators\MigrationGenerator |
| 31 | + */ |
| 32 | + protected $migrator; |
| 33 | + |
| 34 | + /** |
| 35 | + * Model generator instance |
| 36 | + * |
| 37 | + * @var Baum\Generators\ModelGenerator |
| 38 | + */ |
| 39 | + protected $modeler; |
| 40 | + |
| 41 | + /** |
| 42 | + * Create a new command instance |
| 43 | + * |
| 44 | + * @return void |
| 45 | + */ |
| 46 | + public function __construct(MigrationGenerator $migrator, ModelGenerator $modeler) |
| 47 | + { |
| 48 | + parent::__construct(); |
| 49 | + |
| 50 | + $this->migrator = $migrator; |
| 51 | + $this->modeler = $modeler; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Execute the console command. |
| 56 | + * |
| 57 | + * Basically, we'll write the migration and model stubs out to disk inflected |
| 58 | + * with the name provided. Once its done, we'll `dump-autoload` for the entire |
| 59 | + * framework to make sure that the new classes are registered by the class |
| 60 | + * loaders. |
| 61 | + * |
| 62 | + * @return void |
| 63 | + */ |
| 64 | + public function fire() |
| 65 | + { |
| 66 | + $name = $this->input->getArgument('name'); |
| 67 | + |
| 68 | + $this->writeMigration($name); |
| 69 | + |
| 70 | + $this->writeModel($name); |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Get the command arguments |
| 76 | + * |
| 77 | + * @return array |
| 78 | + */ |
| 79 | + protected function getArguments() |
| 80 | + { |
| 81 | + return array( |
| 82 | + array('name', InputArgument::REQUIRED, 'Name to use for the scaffolding of the migration and model.') |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Write the migration file to disk. |
| 88 | + * |
| 89 | + * @param string $name |
| 90 | + * @return string |
| 91 | + */ |
| 92 | + protected function writeMigration($name) |
| 93 | + { |
| 94 | + $output = pathinfo($this->migrator->create($name, $this->getMigrationsPath()), PATHINFO_FILENAME); |
| 95 | + |
| 96 | + $this->line(" <fg=green;options=bold>create</fg=green;options=bold> $output"); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Write the model file to disk. |
| 101 | + * |
| 102 | + * @param string $name |
| 103 | + * @return string |
| 104 | + */ |
| 105 | + protected function writeModel($name) |
| 106 | + { |
| 107 | + $output = pathinfo($this->modeler->create($name, $this->getModelsPath()), PATHINFO_FILENAME); |
| 108 | + |
| 109 | + $this->line(" <fg=green;options=bold>create</fg=green;options=bold> $output"); |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Get the path to the migrations directory. |
| 114 | + * |
| 115 | + * @return string |
| 116 | + */ |
| 117 | + protected function getMigrationsPath() |
| 118 | + { |
| 119 | + return $this->laravel['path.database'] . '/migrations'; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Get the path to the models directory. |
| 124 | + * |
| 125 | + * @return string |
| 126 | + */ |
| 127 | + protected function getModelsPath() |
| 128 | + { |
| 129 | + return $this->laravel['path.base']; |
| 130 | + } |
122 | 131 |
|
123 | 132 | } |
0 commit comments