1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Scaling\Playbook\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Illuminate\Console\GeneratorCommand; |
7
|
|
|
|
8
|
|
|
class MakePlaybookCommand extends GeneratorCommand |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The name and signature of the console command. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $signature = 'make:playbook |
16
|
|
|
{name : The name of the playbook}'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Create a new playbook.'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The type of class being generated. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $type = 'Playbook'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Replace the class name for the given stub. |
34
|
|
|
* |
35
|
|
|
* @param string $stub |
36
|
|
|
* @param string $name |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
protected function replaceClass($stub, $name) |
40
|
|
|
{ |
41
|
|
|
return str_replace('DummyClass', $this->getNameInput(), $stub); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the stub file for the playbook. |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
protected function getStub() |
50
|
|
|
{ |
51
|
|
|
return __DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'playbook.stub'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the destination class path. |
56
|
|
|
* |
57
|
|
|
* @param string $name |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
protected function getPath($name) |
61
|
|
|
{ |
62
|
|
|
return config('laravel-playbook.path').$name.'.php'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the full namespace for a given class, without the class name. |
67
|
|
|
* |
68
|
|
|
* @param string $name |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
protected function getNamespace($name) |
72
|
|
|
{ |
73
|
|
|
return config('laravel-playbook.namespace'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the desired class name from the input. |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
protected function getNameInput() |
82
|
|
|
{ |
83
|
|
|
return sprintf('%sPlaybook', Str::studly(trim($this->argument('name')))); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Parse the class name and format according to the root namespace. |
88
|
|
|
* |
89
|
|
|
* @param string $name |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
protected function qualifyClass($name) |
93
|
|
|
{ |
94
|
|
|
return $this->getNameInput(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|