|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Talal\Exporter\Console\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
7
|
|
|
use Talal\Exporter\Exporter; |
|
8
|
|
|
|
|
9
|
|
|
class Export extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The name and signature of the console command. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $signature = 'env:export {server : A supported web server} |
|
17
|
|
|
{--file=.env : The environment file}'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The console command description. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $description = 'Export the environment file to a capable web server format.'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var \Illuminate\Filesystem\Filesystem |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $filesystem; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Create a new export command instance. |
|
33
|
|
|
* |
|
34
|
|
|
* @param \Illuminate\Filesystem\Filesystem $filesystem |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(Filesystem $filesystem) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->filesystem = $filesystem; |
|
39
|
|
|
|
|
40
|
|
|
parent::__construct(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Execute the console command. |
|
45
|
|
|
*/ |
|
46
|
|
|
public function handle() |
|
47
|
|
|
{ |
|
48
|
|
|
$fileContents = $this->filesystem->get( |
|
49
|
|
|
$this->laravel->basePath() . '/' . $this->option('file') |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$this->export($fileContents); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Export the environment file. |
|
57
|
|
|
* |
|
58
|
|
|
* @param $fileContents |
|
59
|
|
|
* @return int |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function export($fileContents) |
|
62
|
|
|
{ |
|
63
|
|
|
$server = strtolower($this->argument('server')); |
|
64
|
|
|
$server = sprintf('Talal\Exporter\Output\%s', ucfirst($server)); |
|
65
|
|
|
|
|
66
|
|
|
if (! class_exists($server)) { |
|
67
|
|
|
$this->error('The provided server is not exportable.'); |
|
68
|
|
|
return 0; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$exporter = new Exporter(new $server($fileContents)); |
|
72
|
|
|
$this->line($exporter->output()); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|