Skip to content

Commit

Permalink
Check whether the dependency phpmyadmin/sql-parser is installed (#655)
Browse files Browse the repository at this point in the history
* Updated SqlParser, allowed package missing.

* Update composer.json

* chore: Update composer.json to include sentry/sentry dependency

---------

Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia committed May 31, 2024
1 parent ff98af9 commit fa3cf00
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
"hyperf/http-server": "~3.1.0",
"hyperf/support": "~3.1.0",
"hyperf/tappable": "~3.1.0",
"phpmyadmin/sql-parser": "^5.9",
"sentry/sentry": "^4.4.0"
},
"suggest": {
"elasticsearch/elasticsearch": "Required to use the elasticsearch client (^7.0|^8.0).",
"hyperf/amqp": "Required to use the amqp event (~3.1.9).",
"hyperf/crontab": "Required to use the crontab event (~3.1.7).",
"hyperf/database": "Required to use the crontab event (~3.1.0)."
"hyperf/database": "Required to use the crontab event (~3.1.0).",
"phpmyadmin/sql-parser": "Required to use the sql parser (^5.9)."
},
"config": {
"sort-packages": true
Expand Down
5 changes: 3 additions & 2 deletions src/Util/SqlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FriendsOfHyperf\Sentry\Util;

use PhpMyAdmin\SqlParser\Components\JoinKeyword;
use PhpMyAdmin\SqlParser\Parser as BaseSqlParser;
use PhpMyAdmin\SqlParser\Statements\InsertStatement;
use PhpMyAdmin\SqlParser\Statements\SelectStatement;
use PhpMyAdmin\SqlParser\Statements\UpdateStatement;
Expand All @@ -23,15 +24,15 @@ class SqlParser
*/
public static function parse(string $sql): array
{
if (empty($sql)) {
if (! class_exists(BaseSqlParser::class) || empty($sql)) {
return [
'operation' => '',
'table' => '',
'tables' => [],
];
}

$parser = new \PhpMyAdmin\SqlParser\Parser($sql);
$parser = new BaseSqlParser($sql);
$operation = $parser->list[0]->keyword;
$tables = [];

Expand Down

0 comments on commit fa3cf00

Please sign in to comment.