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
|
|
|
* fire. |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
7 |
|
public function fire() |
38
|
|
|
{ |
39
|
7 |
|
$this->handle(); |
40
|
7 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Parse the class name and format according to the root namespace. |
44
|
|
|
* |
45
|
|
|
* @param string $name |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
7 |
|
protected function qualifyClass($name) |
49
|
|
|
{ |
50
|
7 |
|
$rootNamespace = $this->rootNamespace(); |
51
|
|
|
|
52
|
7 |
|
if (Str::startsWith($name, $rootNamespace)) { |
53
|
7 |
|
return $name; |
54
|
|
|
} |
55
|
|
|
|
56
|
7 |
|
$name = str_replace('/', '\\', $name); |
57
|
|
|
|
58
|
7 |
|
return $this->qualifyClass( |
59
|
7 |
|
$this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get the root namespace for the class. |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
7 |
|
protected function rootNamespace() |
69
|
|
|
{ |
70
|
7 |
|
return $this->laravel->getNamespace(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* getStubResource. |
75
|
|
|
* |
76
|
|
|
* @param string $stub |
77
|
|
|
* @param string $folder |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
7 |
|
protected function getStubResource($stub, $folder = 'app') |
81
|
|
|
{ |
82
|
7 |
|
$root = $this->laravel->basePath().'/resources/views/generator/'.$folder.'/'; |
83
|
|
|
|
84
|
7 |
|
return $this->files->exists($root.$stub) === true |
85
|
|
|
? $root.$stub |
86
|
7 |
|
: __DIR__.'/../../resources/stubs/'.$folder.'/'.$stub; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|