Skip to content

Commit

Permalink
SqlPreprocessor: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 20, 2018
1 parent 800f6a8 commit 298fca9
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/Database/SqlPreprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ class SqlPreprocessor
/** @var array */
private const MODE_LIST = ['and', 'or', 'set', 'values', 'order'];

private const ARRAY_MODES = [
'INSERT' => 'values',
'REPLACE' => 'values',
'KEY UPDATE' => 'set',
'SET' => 'set',
'WHERE' => 'and',
'HAVING' => 'and',
'ORDER BY' => 'order',
'GROUP BY' => 'order',
];

/** @var Connection */
private $connection;

Expand Down Expand Up @@ -98,17 +109,8 @@ public function callback(array $m): string
return $m;

} else { // command
static $modes = [
'INSERT' => 'values',
'REPLACE' => 'values',
'KEY UPDATE' => 'set',
'SET' => 'set',
'WHERE' => 'and',
'HAVING' => 'and',
'ORDER BY' => 'order',
'GROUP BY' => 'order',
];
$this->arrayMode = $modes[ltrim(strtoupper($m))];
$cmd = ltrim(strtoupper($m));
$this->arrayMode = self::ARRAY_MODES[$cmd];
return $m;
}
}
Expand Down

0 comments on commit 298fca9

Please sign in to comment.