diff --git a/src/Parser/AbstractParser.php b/src/Parser/AbstractParser.php index e084ec13..b580ac0a 100644 --- a/src/Parser/AbstractParser.php +++ b/src/Parser/AbstractParser.php @@ -29,7 +29,7 @@ abstract class AbstractParser implements ParserInterface * @var array * */ - protected $handlers = array(); + protected $handlers = []; /** * @@ -40,26 +40,32 @@ abstract class AbstractParser implements ParserInterface */ protected $numberedPlaceHolderCharacter = "?"; + protected $charset = 'UTF-8'; + + public function __construct($charset = 'UTF-8') + { + $this->charset = $charset; + } + /** * * Given a query string and parameters, rebuilds it so that parameters all * match up, and replaces array-based placeholders. * - * @param string $string The query statement string. + * @param string $statement The query statement string. * - * @param array $parameters Bind these values into the query. + * @param array $values Bind these values into the query. * * @return Query[] * */ - public function rebuild($string, array $parameters = []) + public function rebuild($statement, array $values = []) { - $query = new Query($string, $parameters); + $query = new Query($statement, $values); $queries = array(); - $charset = 'UTF-8'; /** @var State $state */ - $state = new State($query->getStatement(), $query->getValues(), $charset); + $state = new State($query->getStatement(), $query->getValues(), $this->charset); $last_check_index = -1; diff --git a/src/Parser/MysqlParser.php b/src/Parser/MysqlParser.php index bb6a15c5..18587b70 100644 --- a/src/Parser/MysqlParser.php +++ b/src/Parser/MysqlParser.php @@ -17,22 +17,16 @@ */ class MysqlParser extends AbstractParser { - /** - * Constructor. Sets up the array of callbacks. - */ - public function __construct() - { - $this->handlers = array( - '-' => 'handleSingleLineComment', - '/' => 'handleMultiLineComment', - '"' => 'handleMySQLQuotedString', - "'" => 'handleMySQLQuotedString', - "`" => 'handleQuotedString', - ':' => 'handleColon', - '?' => 'handleNumberedParameter', - ';' => 'handleSemiColon', - ); - } + protected $handlers = [ + '-' => 'handleSingleLineComment', + '/' => 'handleMultiLineComment', + '"' => 'handleMySQLQuotedString', + "'" => 'handleMySQLQuotedString', + "`" => 'handleQuotedString', + ':' => 'handleColon', + '?' => 'handleNumberedParameter', + ';' => 'handleSemiColon', + ]; /** * diff --git a/src/Parser/NullParser.php b/src/Parser/NullParser.php index 1118c0a8..2d5f6644 100644 --- a/src/Parser/NullParser.php +++ b/src/Parser/NullParser.php @@ -22,15 +22,15 @@ class NullParser implements ParserInterface * * Leaves the query and parameters alone. * - * @param string $string The query statement string. + * @param string $statement The query statement string. * - * @param array $parameters Bind these values into the query. + * @param array $values Bind these values into the query. * * @return Query[] * */ - public function rebuild($string, array $parameters = []) + public function rebuild($statement, array $values = []) { - return [new Query($string, $parameters)]; + return [new Query($statement, $values)]; } } diff --git a/src/Parser/PgsqlParser.php b/src/Parser/PgsqlParser.php index be584555..145bcc98 100644 --- a/src/Parser/PgsqlParser.php +++ b/src/Parser/PgsqlParser.php @@ -17,25 +17,19 @@ */ class PgsqlParser extends AbstractParser { - /** - * Constructor. Sets up the array of callbacks. - */ - public function __construct() - { - $this->handlers = array( - '-' => 'handleSingleLineComment', - '/' => 'handleMultiLineComment', - '"' => 'handleQuotedString', - "'" => 'handleQuotedString', - 'E' => 'handlePossibleCStyleString', - 'e' => 'handlePossibleCStyleString', - ':' => 'handleColon', - '?' => 'handleNumberedParameter', - ';' => 'handleSemiColon', - '$' => 'handleDollar', - '[' => 'handleArray', - ); - } + protected $handlers = [ + '-' => 'handleSingleLineComment', + '/' => 'handleMultiLineComment', + '"' => 'handleQuotedString', + "'" => 'handleQuotedString', + 'E' => 'handlePossibleCStyleString', + 'e' => 'handlePossibleCStyleString', + ':' => 'handleColon', + '?' => 'handleNumberedParameter', + ';' => 'handleSemiColon', + '$' => 'handleDollar', + '[' => 'handleArray', + ]; /** * diff --git a/src/Parser/Query.php b/src/Parser/Query.php index 431b5a08..663c6020 100644 --- a/src/Parser/Query.php +++ b/src/Parser/Query.php @@ -18,7 +18,7 @@ class Query { /** - * @var string A query statement + * @var string A query statement string */ private $statement = ''; diff --git a/src/Parser/SqliteParser.php b/src/Parser/SqliteParser.php index 3f1f1ab7..c6c5e3f3 100644 --- a/src/Parser/SqliteParser.php +++ b/src/Parser/SqliteParser.php @@ -17,21 +17,15 @@ */ class SqliteParser extends AbstractParser { - /** - * Constructor. Sets up the array of callbacks. - */ - public function __construct() - { - $this->handlers = array( - '-' => 'handleSingleLineComment', - '/' => 'handleMultiLineComment', - '"' => 'handleQuotedString', - "'" => 'handleSqliteQuotedString', - ':' => 'handleColon', - '?' => 'handleNumberedParameter', - ';' => 'handleSemiColon', - ); - } + protected $handlers = [ + '-' => 'handleSingleLineComment', + '/' => 'handleMultiLineComment', + '"' => 'handleQuotedString', + "'" => 'handleSqliteQuotedString', + ':' => 'handleColon', + '?' => 'handleNumberedParameter', + ';' => 'handleSemiColon', + ]; /** * diff --git a/src/Parser/SqlsrvParser.php b/src/Parser/SqlsrvParser.php index acc17d68..ad299eaa 100644 --- a/src/Parser/SqlsrvParser.php +++ b/src/Parser/SqlsrvParser.php @@ -17,22 +17,16 @@ */ class SqlsrvParser extends AbstractParser { - /** - * Constructor. Sets up the array of callbacks. - */ - public function __construct() - { - $this->handlers = array( - '-' => 'handleSingleLineComment', - '/' => 'handleMultiLineComment', - '"' => 'handleQuotedString', - "'" => 'handleQuotedString', - "[" => 'handleIdentifier', - ':' => 'handleColon', - '?' => 'handleNumberedParameter', - ';' => 'handleSemiColon', - ); - } + protected $handlers = [ + '-' => 'handleSingleLineComment', + '/' => 'handleMultiLineComment', + '"' => 'handleQuotedString', + "'" => 'handleQuotedString', + "[" => 'handleIdentifier', + ':' => 'handleColon', + '?' => 'handleNumberedParameter', + ';' => 'handleSemiColon', + ]; /** *