Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract controllers from AjaxController
Extracts the config set and get to the ConfigController, the databases list to the DatabaseController, the tables list to the TableController and the columns list to the ColumnController. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
- Loading branch information
1 parent
bd99f52
commit 111cb5d
Showing
9 changed files
with
195 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers; | ||
|
||
use PhpMyAdmin\DatabaseInterface; | ||
use PhpMyAdmin\Message; | ||
use PhpMyAdmin\Response; | ||
use PhpMyAdmin\Template; | ||
|
||
final class ColumnController extends AbstractController | ||
{ | ||
/** @var DatabaseInterface */ | ||
private $dbi; | ||
|
||
/** | ||
* @param Response $response | ||
* @param DatabaseInterface $dbi | ||
*/ | ||
public function __construct($response, Template $template, $dbi) | ||
{ | ||
parent::__construct($response, $template); | ||
$this->dbi = $dbi; | ||
} | ||
|
||
public function all(): void | ||
{ | ||
if (! isset($_POST['db'], $_POST['table'])) { | ||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON(['message' => Message::error()]); | ||
|
||
return; | ||
} | ||
|
||
$this->response->addJSON(['columns' => $this->dbi->getColumnNames($_POST['db'], $_POST['table'])]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers; | ||
|
||
use PhpMyAdmin\Config; | ||
use PhpMyAdmin\Message; | ||
use PhpMyAdmin\Response; | ||
use PhpMyAdmin\Template; | ||
use function json_decode; | ||
|
||
final class ConfigController extends AbstractController | ||
{ | ||
/** @var Config */ | ||
private $config; | ||
|
||
/** | ||
* @param Response $response | ||
*/ | ||
public function __construct($response, Template $template, Config $config) | ||
{ | ||
parent::__construct($response, $template); | ||
$this->config = $config; | ||
} | ||
|
||
public function get(): void | ||
{ | ||
if (! isset($_POST['key'])) { | ||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON(['message' => Message::error()]); | ||
|
||
return; | ||
} | ||
|
||
$this->response->addJSON(['value' => $this->config->get($_POST['key'])]); | ||
} | ||
|
||
public function set(): void | ||
{ | ||
if (! isset($_POST['key'], $_POST['value'])) { | ||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON(['message' => Message::error()]); | ||
|
||
return; | ||
} | ||
|
||
$result = $this->config->setUserValue(null, $_POST['key'], json_decode($_POST['value'])); | ||
|
||
if ($result === true) { | ||
return; | ||
} | ||
|
||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON(['message' => $result]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers; | ||
|
||
final class DatabaseController extends AbstractController | ||
{ | ||
public function all(): void | ||
{ | ||
global $dblist; | ||
|
||
$this->response->addJSON(['databases' => $dblist->databases]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers; | ||
|
||
use PhpMyAdmin\DatabaseInterface; | ||
use PhpMyAdmin\Message; | ||
use PhpMyAdmin\Response; | ||
use PhpMyAdmin\Template; | ||
|
||
final class TableController extends AbstractController | ||
{ | ||
/** @var DatabaseInterface */ | ||
private $dbi; | ||
|
||
/** | ||
* @param Response $response | ||
* @param DatabaseInterface $dbi | ||
*/ | ||
public function __construct($response, Template $template, $dbi) | ||
{ | ||
parent::__construct($response, $template); | ||
$this->dbi = $dbi; | ||
} | ||
|
||
public function all(): void | ||
{ | ||
if (! isset($_POST['db'])) { | ||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON(['message' => Message::error()]); | ||
|
||
return; | ||
} | ||
|
||
$this->response->addJSON(['tables' => $this->dbi->getTables($_POST['db'])]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.