1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace R\Hive\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\GeneratorCommand; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
|
9
|
|
|
class MakeInstanceCommand extends GeneratorCommand |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The console command name. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $name = 'hive:instance'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Create a new Hive instance class.'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The type of class being generated. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $type = 'Instance'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Execute the console command. |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
public function fire() |
38
|
|
|
{ |
39
|
|
|
if (parent::fire() !== false) { |
40
|
|
|
if ($this->option('migration')) { |
41
|
|
|
$table = Str::plural(Str::snake(class_basename($this->argument('name')))); |
|
|
|
|
42
|
|
|
|
43
|
|
|
$this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get the stub file for the generator. |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
protected function getStub() |
54
|
|
|
{ |
55
|
|
|
if ($this->option('eloquent')) { |
56
|
|
|
return __DIR__.'/stubs/instance-eloquent.stub'; |
57
|
|
|
} else { |
58
|
|
|
return __DIR__.'/stubs/instance-no-eloquent.stub'; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the default namespace for the class. |
64
|
|
|
* |
65
|
|
|
* @param string $rootNamespace |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
protected function getDefaultNamespace($rootNamespace) |
70
|
|
|
{ |
71
|
|
|
return $rootNamespace; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get the console command options. |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
protected function getOptions() |
80
|
|
|
{ |
81
|
|
|
return [ |
82
|
|
|
['eloquent', 'e', InputOption::VALUE_NONE, 'Extend the eloquent model class.'], |
83
|
|
|
['migration', 'm', InputOption::VALUE_NONE, 'Create a new migration file for the model.'], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.