-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathSchemaExportController.php
More file actions
70 lines (59 loc) · 2.2 KB
/
SchemaExportController.php
File metadata and controls
70 lines (59 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers;
use PhpMyAdmin\Core;
use PhpMyAdmin\Exceptions\ExportException;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use function __;
use function mb_strlen;
/**
* Schema export handler
*/
#[Route('/schema-export', ['GET', 'POST'])]
final readonly class SchemaExportController implements InvocableController
{
public function __construct(
private Export $export,
private ResponseRenderer $response,
private ResponseFactory $responseFactory,
) {
}
public function __invoke(ServerRequest $request): Response
{
$db = DatabaseName::tryFrom($request->getParsedBodyParam('db'));
$exportType = $request->getParsedBodyParamAsString('export_type');
if ($db === null || $exportType === '') {
$errorMessage = __('Missing parameter:') . ($db === null ? ' db' : ' export_type')
. MySQLDocumentation::showDocumentation('faq', 'faqmissingparameters', true)
. '[br]';
$this->response->setRequestStatus(false);
$this->response->addHTML(Message::error($errorMessage)->getDisplay());
return $this->response->response();
}
/**
* Include the appropriate Schema Class depending on $exportType, default is PDF.
*/
try {
$exportInfo = $this->export->getExportSchemaInfo($db, $exportType);
} catch (ExportException $exception) {
$this->response->setRequestStatus(false);
$this->response->addHTML(Message::error($exception->getMessage())->getDisplay());
return $this->response->response();
}
$response = $this->responseFactory->createResponse();
Core::downloadHeader(
$exportInfo['fileName'],
$exportInfo['mediaType'],
mb_strlen($exportInfo['fileData'], '8bit'),
);
return $response->write($exportInfo['fileData']);
}
}