1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yaro\Jarboe\Console\Commands\Make; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Support\Facades\File; |
7
|
|
|
use Illuminate\Support\Str; |
8
|
|
|
use Yaro\Jarboe\Table\Toolbar\Interfaces\ToolInterface; |
9
|
|
|
|
10
|
|
|
class Tool extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The name and signature of the console command. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $signature = 'jarboe:make:tool {class}'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Make tool for toolbar.'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Execute the console command. |
28
|
|
|
* |
29
|
|
|
* @return mixed |
30
|
|
|
*/ |
31
|
|
|
public function handle() |
32
|
|
|
{ |
33
|
|
|
$className = (string) $this->argument('class'); |
34
|
|
|
|
35
|
|
|
$packagePath = __DIR__ .'/../../../../'; |
36
|
|
|
$stub = file_get_contents($packagePath .'stubs/tool.stub'); |
37
|
|
|
|
38
|
|
|
$position = $this->choice('Tool position?', [ |
39
|
|
|
ToolInterface::POSITION_HEADER, |
40
|
|
|
ToolInterface::POSITION_BODY_TOP, |
41
|
|
|
ToolInterface::POSITION_BODY_BOTTOM, |
42
|
|
|
ToolInterface::POSITION_BODY_BOTH, |
43
|
|
|
]); |
44
|
|
|
$position = strtoupper('position_'. $position); |
45
|
|
|
$ident = Str::random(); |
46
|
|
|
$view = Str::snake($className); |
47
|
|
|
|
48
|
|
|
$tool = sprintf($stub, $className, $position, $ident, $view); |
49
|
|
|
$filepath = app_path(sprintf('Jarboe/Toolbar/%s.php', $className)); |
50
|
|
|
|
51
|
|
|
if (!File::exists(app_path('Jarboe/Toolbar'))) { |
52
|
|
|
File::makeDirectory(app_path('Jarboe/Toolbar'), 0775, true, false); |
53
|
|
|
} |
54
|
|
|
File::put($filepath, $tool); |
55
|
|
|
|
56
|
|
|
$this->info('Created: '. $filepath); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|