Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SchemaExportController.php « Controllers « classes « libraries - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3a935fe7f2f22b2ec61fa95fe9ecc5c4d8be6c5f (plain)
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
<?php

declare(strict_types=1);

namespace PhpMyAdmin\Controllers;

use PhpMyAdmin\Dbal\DatabaseName;
use PhpMyAdmin\Export;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use RuntimeException;

use function __;
use function is_string;

/**
 * Schema export handler
 */
class SchemaExportController
{
    /** @var Export */
    private $export;

    /** @var ResponseRenderer */
    private $response;

    public function __construct(Export $export, ResponseRenderer $response)
    {
        $this->export = $export;
        $this->response = $response;
    }

    public function __invoke(ServerRequest $request): void
    {
        $db = DatabaseName::tryFromValue($request->getParsedBodyParam('db'));
        /** @var mixed $exportType */
        $exportType = $request->getParsedBodyParam('export_type');
        if ($db === null || ! is_string($exportType) || $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;
        }

        /**
         * Include the appropriate Schema Class depending on $exportType, default is PDF.
         */
        try {
            $this->export->processExportSchema($db, $exportType);
        } catch (RuntimeException $exception) {
            $this->response->setRequestStatus(false);
            $this->response->addHTML(Message::error($exception->getMessage())->getDisplay());
        }
    }
}