phpmyadmin/libraries/classes/Controllers/LintController.php
Maurício Meneghini Fauth 87a30b0977 Move lint entry point logic to routes file
Creates a new controller for the lint entry point.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2019-11-08 15:54:03 -03:00

60 lines
1.7 KiB
PHP

<?php
/**
* Represents the interface between the linter and the query editor.
* @package PhpMyAdmin\Controllers
*/
declare(strict_types=1);
namespace PhpMyAdmin\Controllers;
use PhpMyAdmin\Core;
use PhpMyAdmin\Linter;
/**
* Represents the interface between the linter and the query editor.
* @package PhpMyAdmin\Controllers
*/
class LintController extends AbstractController
{
/**
* @param array $params Request parameters
* @return void
*/
public function index(array $params): void
{
/**
* The SQL query to be analyzed.
*
* This does not need to be checked again XSS or MySQL injections because it is
* never executed, just parsed.
*
* The client, which will receive the JSON response will decode the message and
* and any HTML fragments that are displayed to the user will be encoded anyway.
*
* @var string
*/
$sqlQuery = ! empty($params['sql_query']) ? $params['sql_query'] : '';
$this->response->setAjax(true);
// Disabling standard response.
$this->response->disable();
Core::headerJSON();
if (! empty($params['options'])) {
$options = $params['options'];
if (! empty($options['routine_editor'])) {
$sqlQuery = 'CREATE PROCEDURE `a`() ' . $sqlQuery;
} elseif (! empty($options['trigger_editor'])) {
$sqlQuery = 'CREATE TRIGGER `a` AFTER INSERT ON `b` FOR EACH ROW ' . $sqlQuery;
} elseif (! empty($options['event_editor'])) {
$sqlQuery = 'CREATE EVENT `a` ON SCHEDULE EVERY MINUTE DO ' . $sqlQuery;
}
}
echo json_encode(Linter::lint($sqlQuery));
}
}