|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Recca0120\Generator\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
use Recca0120\Generator\Generator; |
|
7
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
8
|
|
|
use Illuminate\Console\GeneratorCommand as BaseCommand; |
|
9
|
|
|
|
|
10
|
|
|
abstract class GeneratorCommand extends BaseCommand |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* $generator. |
|
14
|
|
|
* |
|
15
|
|
|
* @var \Recca0120\Generator\Generator |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $generator; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Create a new controller creator command instance. |
|
21
|
|
|
* |
|
22
|
|
|
* @param \Illuminate\Filesystem\Filesystem $files |
|
23
|
|
|
* @param \Recca0120\Generator\Generator |
|
24
|
|
|
*/ |
|
25
|
7 |
|
public function __construct(Filesystem $files, Generator $generator) |
|
26
|
|
|
{ |
|
27
|
7 |
|
parent::__construct($files); |
|
28
|
|
|
|
|
29
|
7 |
|
$this->generator = $generator; |
|
30
|
7 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Parse the class name and format according to the root namespace. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $name |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
7 |
|
protected function qualifyClass($name) |
|
39
|
|
|
{ |
|
40
|
7 |
|
$rootNamespace = $this->rootNamespace(); |
|
41
|
|
|
|
|
42
|
7 |
|
if (Str::startsWith($name, $rootNamespace)) { |
|
43
|
7 |
|
return $name; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
7 |
|
$name = str_replace('/', '\\', $name); |
|
47
|
|
|
|
|
48
|
7 |
|
return $this->qualifyClass( |
|
49
|
7 |
|
$this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get the root namespace for the class. |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
7 |
|
protected function rootNamespace() |
|
59
|
|
|
{ |
|
60
|
7 |
|
return $this->laravel->getNamespace(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* getStubResource. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $stub |
|
67
|
|
|
* @param string $folder |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
7 |
|
protected function getStubResource($stub, $folder = 'app') |
|
71
|
|
|
{ |
|
72
|
7 |
|
$root = $this->laravel->basePath().'/resources/views/generator/'.$folder.'/'; |
|
73
|
|
|
|
|
74
|
7 |
|
return $this->files->exists($root.$stub) === true |
|
75
|
|
|
? $root.$stub |
|
76
|
7 |
|
: __DIR__.'/../../resources/stubs/'.$folder.'/'.$stub; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* fire. |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function fire() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->handle(); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|