|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: vernerd |
|
5
|
|
|
* Date: 2019-09-23 |
|
6
|
|
|
* Time: 17:44. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace DanielWerner\LaravelSchemaCrawler; |
|
10
|
|
|
|
|
11
|
|
|
use Illuminate\Support\Str; |
|
12
|
|
|
|
|
13
|
|
|
class SchemaCrawlerArguments |
|
14
|
|
|
{ |
|
15
|
|
|
protected $user; |
|
16
|
|
|
|
|
17
|
|
|
protected $password; |
|
18
|
|
|
|
|
19
|
|
|
protected $infoLevel; |
|
20
|
|
|
|
|
21
|
|
|
protected $command; |
|
22
|
|
|
|
|
23
|
|
|
protected $url; |
|
24
|
|
|
|
|
25
|
|
|
protected $outputFile; |
|
26
|
|
|
|
|
27
|
|
|
protected $outputFormat; |
|
28
|
|
|
|
|
29
|
|
|
protected $schemas; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* SchemaCrawlerArguments constructor. |
|
33
|
|
|
* @param string|null $outputFile |
|
34
|
|
|
* @param string|null $outputFormat |
|
35
|
|
|
* @param string|null $connection |
|
36
|
|
|
* @param string|null $infoLevel |
|
37
|
|
|
* @param string|null $command |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct( |
|
40
|
|
|
?string $outputFile = null, |
|
41
|
|
|
?string $outputFormat = null, |
|
42
|
|
|
?string $connection = null, |
|
43
|
|
|
?string $infoLevel = null, |
|
44
|
|
|
?string $command = null |
|
45
|
|
|
) { |
|
46
|
|
|
$connection = config('database.'.($connection ?? config('laravel-schemacrawler.connection'))); |
|
47
|
|
|
|
|
48
|
|
|
$this->user = config('database.connections.'.$connection.'.username'); |
|
49
|
|
|
$this->password = config('database.connections.'.$connection.'.password'); |
|
50
|
|
|
$this->infoLevel = $infoLevel ?? config('laravel-schemacrawler.info_level'); |
|
51
|
|
|
$this->command = $command ?? 'schema'; |
|
52
|
|
|
|
|
53
|
|
|
$databaseDriver = config('database.connections.'.$connection.'.driver'); |
|
54
|
|
|
$host = config('database.connections.'.$connection.'.host'); |
|
55
|
|
|
$port = config('database.connections.'.$connection.'.port'); |
|
56
|
|
|
$this->url = JDBC::url($databaseDriver, $host, $port); |
|
57
|
|
|
|
|
58
|
|
|
$this->outputFile = config('laravel-schemacrawler.output_base_path').DIRECTORY_SEPARATOR. |
|
59
|
|
|
($outputFile ?? config('laravel-schemacrawler.output_file')); |
|
60
|
|
|
|
|
61
|
|
|
$this->outputFormat = $outputFormat ?? config('laravel-schemacrawler.output_format'); |
|
62
|
|
|
$this->schemas = config('database.connections.'.$connection.'.database'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public function toArray(): array |
|
69
|
|
|
{ |
|
70
|
|
|
$arguments = []; |
|
71
|
|
|
|
|
72
|
|
|
foreach ($this as $key => $value) { |
|
|
|
|
|
|
73
|
|
|
$arguments[] = '--'.Str::snake($key, '-'); |
|
74
|
|
|
$arguments[] = $value; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $arguments; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getOutputFile(): string |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->outputFile; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|