1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: vernerd |
5
|
|
|
* Date: 2019-09-24 |
6
|
|
|
* Time: 20:07. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace DanielWerner\LaravelSchemaCrawler\Http\Controllers; |
10
|
|
|
|
11
|
|
|
use Illuminate\Http\Request; |
12
|
|
|
use Illuminate\Routing\Controller; |
13
|
|
|
use Symfony\Component\Process\Process; |
14
|
|
|
use DanielWerner\LaravelSchemaCrawler\Facades\SchemaCrawler; |
15
|
|
|
use DanielWerner\LaravelSchemaCrawler\SchemaCrawlerArguments; |
16
|
|
|
|
17
|
|
|
class SchemaController extends Controller |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param Request $request |
21
|
|
|
* @return SchemaCrawlerArguments |
22
|
|
|
*/ |
23
|
|
|
private function createArgumentsFromRequest(Request $request): SchemaCrawlerArguments |
24
|
|
|
{ |
25
|
|
|
// If the requested output format is not html, first generate scdot, and convert it manually afterwards |
26
|
|
|
return new SchemaCrawlerArguments( |
27
|
|
|
$request->output_file, |
28
|
|
|
$request->output_format !== 'html' ? 'scdot' : $request->output_format, |
|
|
|
|
29
|
|
|
$request->connection, |
30
|
|
|
$request->info_level, |
31
|
|
|
$request->command |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param Request $request |
37
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
38
|
|
|
*/ |
39
|
|
|
public function show(Request $request) |
40
|
|
|
{ |
41
|
|
|
$outputFormat = $request->output_format ?? config('laravel-schemacrawler.output_format'); |
|
|
|
|
42
|
|
|
$file = SchemaCrawler::crawl($this->createArgumentsFromRequest($request)); |
43
|
|
|
$file = $this->convertOutputFile($outputFormat, $file); |
44
|
|
|
|
45
|
|
|
return response()->file($file)->deleteFileAfterSend(); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $outputFormat |
50
|
|
|
* @param string $file |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
private function convertOutputFile(string $outputFormat, string $file): string |
54
|
|
|
{ |
55
|
|
|
// Workaround, the schemacrawler cannot call the dot, when called from php using Valet. |
56
|
|
|
// It is necessary to generate the schema in scdot format, and manually convert the to the output format |
57
|
|
|
// @see: https://github.com/schemacrawler/SchemaCrawler/issues/179 |
58
|
|
|
$process = new Process(['dot', '-T', $outputFormat, $file, '-o', $file]); |
59
|
|
|
$process->run(); |
60
|
|
|
|
61
|
|
|
return $file; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.