|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use File; |
|
7
|
|
|
|
|
8
|
|
|
class AddGraph extends Command |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The name and signature of the console command. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $signature = 'make:graph |
|
16
|
|
|
{filename : The Filename to add} |
|
17
|
|
|
{namespace? : The namespace to use (optional) }'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The console command description. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $description = 'Generate new graph template class to help speed up building new graphs'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create a new command instance. |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
87 |
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
87 |
|
parent::__construct(); |
|
34
|
87 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Execute the console command. |
|
38
|
|
|
* |
|
39
|
|
|
* @return mixed |
|
40
|
|
|
*/ |
|
41
|
|
|
public function handle() |
|
42
|
|
|
{ |
|
43
|
|
|
$filename = $this->argument('filename'); |
|
44
|
|
|
$contents = File::get(storage_path('stubs/graph.stub')); |
|
45
|
|
|
$contents = str_replace('namespace App\Graphs;', "namespace App\Graphs\\".$this->argument('namespace').";", $contents); |
|
46
|
|
|
$contents = str_replace('GraphDummy', $this->argument('filename'), $contents); |
|
47
|
|
|
$filepath = base_path('app/Graphs/') . str_replace('\\','/', $this->argument('namespace')); |
|
48
|
|
|
|
|
49
|
|
|
if (!file_exists($filepath)) { |
|
50
|
|
|
File::makeDirectory($filepath, 0755, true); |
|
51
|
|
|
} |
|
52
|
|
|
if (file_exists($filepath.'/'.ucfirst($this->argument('filename')).'.php')) { |
|
53
|
|
|
if (!$this->confirm("$filename alredy exists in $filepath, do you want to overwrite it?")) { |
|
54
|
|
|
$this->error('Exiting...'); |
|
55
|
|
|
exit; |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
File::put($filepath.'/'.ucfirst($this->argument('filename')).'.php', $contents, 'private'); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$this->info("Created file $filename in $filepath"); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.