Skip to content

Commit

Permalink
update docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Jan 23, 2017
1 parent b7f3dbf commit f054d65
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 35 deletions.
27 changes: 24 additions & 3 deletions src/AbstractExtendedPdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,25 @@ public function fetchValue($statement, array $values = [])
return $sth->fetchColumn(0);
}

/**
*
* Returns the Parser instance.
*
* @return ParserInterface
*
*/
public function getParser()
{
return $this->parser;
}

/**
*
* Returns the Profiler instance.
*
* @return ProfilerInterface
*
*/
public function getProfiler()
{
return $this->profiler;
Expand Down Expand Up @@ -416,7 +430,7 @@ public function inTransaction()
* Returns the last inserted autoincrement sequence value.
*
* @param string $name The name of the sequence to check; typically needed
* only for PostgreSQL, where it takes the form of `<table>_<column>_seq`.
* only for PostgreSQL, where it takes the form of `<table>_<column>_seq`.
*
* @return string
*
Expand Down Expand Up @@ -600,16 +614,23 @@ public function rollBack()

/**
*
* Registers a query parser
* Sets the Parser instance.
*
* @param ParserInterface $parser
* @param ParserInterface $parser The Parser instance.
*
*/
public function setParser(ParserInterface $parser)
{
$this->parser = $parser;
}

/**
*
* Sets the Profiler instance.
*
* @param ProfilerInterface $profiler The Profiler instance.
*
*/
public function setProfiler(ProfilerInterface $profiler)
{
$this->profiler = $profiler;
Expand Down
2 changes: 1 addition & 1 deletion src/ExtendedPdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ExtendedPdo extends AbstractExtendedPdo
*
* @param array $options Driver-specific options for the connection.
*
* @param array $attributes Attributes to set after the connection.
* @param array $queries Queries to execute after the connection.
*
* @param ProfilerInterface $profiler Tracks and logs query profiles.
*
Expand Down
2 changes: 1 addition & 1 deletion src/ExtendedPdoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function setParser(ParserInterface $parser);
*
* Sets the Profiler instance.
*
* @param ProfilerInterface $profiler The profiler instance.
* @param ProfilerInterface $profiler The Profiler instance.
*
*/
public function setProfiler(ProfilerInterface $profiler);
Expand Down
59 changes: 40 additions & 19 deletions src/Parser/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ abstract class AbstractParser implements ParserInterface
{
/**
*
* List of handlers to call when a character is found.
* The character set to use when parsing query statements.
*
* The key is the character, the value is a method name which takes a State
* as parameter and returns a State.
* @var string
*
*/
protected $charset = 'UTF-8';

/**
*
* Map of characters to handler methods.
*
* @var array
*
Expand All @@ -40,8 +46,14 @@ abstract class AbstractParser implements ParserInterface
*/
protected $numberedPlaceHolderCharacter = "?";

protected $charset = 'UTF-8';

/**
*
* Constructor.
*
* @param string $charset The character set to use when parsing query
* statements.
*
*/
public function __construct($charset = 'UTF-8')
{
$this->charset = $charset;
Expand All @@ -62,10 +74,14 @@ public function __construct($charset = 'UTF-8')
public function rebuild($statement, array $values = [])
{
$query = new Query($statement, $values);
$queries = array();

/** @var State $state */
$state = new State($query->getStatement(), $query->getValues(), $this->charset);
$queries = [];

$state = new State(
$query->getStatement(),
$query->getValues(),
$this->charset
);

$last_check_index = -1;

Expand Down Expand Up @@ -103,7 +119,7 @@ public function rebuild($statement, array $values = [])
* @param Query[] $queries reference to the array holding a list of queries.
*
*/
private function storeQuery($state, &$queries)
private function storeQuery(State $state, &$queries)
{
$statement = $state->getFinalStatement();
if (! $this->isStatementEmpty($statement)) {
Expand All @@ -127,12 +143,13 @@ private function isStatementEmpty($statement)

/**
*
* After a single or double quote string, advance the $current_index to the end of the string
* After a single or double quote string, advance the $current_index to the
* end of the string
*
* @param State $state The parser state.
*
*/
protected function handleQuotedString($state)
protected function handleQuotedString(State $state)
{
$quoteCharacter = $state->getCurrentCharacter();
$state->copyCurrentCharacter();
Expand All @@ -143,12 +160,13 @@ protected function handleQuotedString($state)

/**
*
* Check if a ':' colon character is followed by what can be a named placeholder.
* Check if a ':' colon character is followed by what can be a named
* placeholder.
*
* @param State $state The parser state.
*
*/
protected function handleColon($state)
protected function handleColon(State $state)
{
$colon_number = 0;
do {
Expand Down Expand Up @@ -186,13 +204,16 @@ protected function handleColon($state)

/**
*
* Replace a numbered placeholder character by multiple ones if a numbered placeholder contains an array.
* As the '?' character can't be used with PG queries, replace it with a named placeholder
* Replace a numbered placeholder character by multiple ones if a numbered
* placeholder contains an array.
*
* As the '?' character can't be used with PG queries, replace it with a
* named placeholder.
*
* @param State $state The parser state.
*
*/
protected function handleNumberedParameter($state)
protected function handleNumberedParameter(State $state)
{
$value = $state->getFirstUnusedNumberedValue();

Expand Down Expand Up @@ -221,7 +242,7 @@ protected function handleNumberedParameter($state)
* @param State $state The parser state.
*
*/
protected function handleSemiColon($state)
protected function handleSemiColon(State $state)
{
$uselessCharacters = $state->capture(';\\s*');
$state->passString($uselessCharacters);
Expand All @@ -236,7 +257,7 @@ protected function handleSemiColon($state)
* @param State $state The parser state.
*
*/
protected function handleSingleLineComment($state)
protected function handleSingleLineComment(State $state)
{
if ($state->nextCharactersAre('-')) {
$state->copyUntilCharacter("\n");
Expand All @@ -253,7 +274,7 @@ protected function handleSingleLineComment($state)
* @param State $state The parser state.
*
*/
protected function handleMultiLineComment($state)
protected function handleMultiLineComment(State $state)
{
if ($state->nextCharactersAre('*')) {
$state->copyUntilCharacter('*/');
Expand Down
11 changes: 9 additions & 2 deletions src/Parser/MysqlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
*/
class MysqlParser extends AbstractParser
{
/**
*
* Map of characters to handler methods.
*
* @var array
*
*/
protected $handlers = [
'-' => 'handleSingleLineComment',
'/' => 'handleMultiLineComment',
Expand All @@ -37,7 +44,7 @@ class MysqlParser extends AbstractParser
* @param State $state The parser state.
*
*/
protected function handleSingleLineComment($state)
protected function handleSingleLineComment(State $state)
{
$isComment = $state->nextCharactersAre("- ")
|| $state->nextCharactersAre("-\t")
Expand All @@ -58,7 +65,7 @@ protected function handleSingleLineComment($state)
* @param State $state The parser state.
*
*/
protected function handleMySQLQuotedString($state)
protected function handleMySQLQuotedString(State $state)
{
$quoteCharacter = $state->getCurrentCharacter();
$state->copyCurrentCharacter();
Expand Down
7 changes: 7 additions & 0 deletions src/Parser/ParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
*/
namespace Aura\Sql\Parser;

/**
*
* Interface for query parsing/rebuilding functionality.
*
* @package aura/sql
*
*/
interface ParserInterface
{
/**
Expand Down
15 changes: 11 additions & 4 deletions src/Parser/PgsqlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
*/
class PgsqlParser extends AbstractParser
{
/**
*
* Map of characters to handler methods.
*
* @var array
*
*/
protected $handlers = [
'-' => 'handleSingleLineComment',
'/' => 'handleMultiLineComment',
Expand All @@ -38,7 +45,7 @@ class PgsqlParser extends AbstractParser
* @param State $state The parser state.
*
*/
protected function handleMultiLineComment($state)
protected function handleMultiLineComment(State $state)
{
if ($state->nextCharactersAre('*')) {
// PG handled multiple levels of comments
Expand All @@ -64,7 +71,7 @@ protected function handleMultiLineComment($state)
* @param State $state The parser state.
*
*/
protected function handlePossibleCStyleString($state)
protected function handlePossibleCStyleString(State $state)
{
$state->copyCurrentCharacter();
if (! $state->done() && ($currentCharacter = $state->getCurrentCharacter()) === "'") {
Expand Down Expand Up @@ -102,7 +109,7 @@ protected function handlePossibleCStyleString($state)
* @param State $state The parser state.
*
*/
protected function handleDollar($state)
protected function handleDollar(State $state)
{
$identifier = $state->capture('\\$([a-zA-Z_]\\w*)*\\$');
if ($identifier) {
Expand All @@ -120,7 +127,7 @@ protected function handleDollar($state)
* @param State $state The parser state.
*
*/
protected function handleArray($state)
protected function handleArray(State $state)
{
$state->copyUntilCharacter(']');
}
Expand Down
9 changes: 8 additions & 1 deletion src/Parser/SqliteParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
*/
class SqliteParser extends AbstractParser
{
/**
*
* Map of characters to handler methods.
*
* @var array
*
*/
protected $handlers = [
'-' => 'handleSingleLineComment',
'/' => 'handleMultiLineComment',
Expand All @@ -34,7 +41,7 @@ class SqliteParser extends AbstractParser
* @param State $state The parser state.
*
*/
protected function handleSqliteQuotedString($state)
protected function handleSqliteQuotedString(State $state)
{
$quoteCharacter = $state->getCurrentCharacter();
$state->copyCurrentCharacter();
Expand Down
9 changes: 8 additions & 1 deletion src/Parser/SqlsrvParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
*/
class SqlsrvParser extends AbstractParser
{
/**
*
* Map of characters to handler methods.
*
* @var array
*
*/
protected $handlers = [
'-' => 'handleSingleLineComment',
'/' => 'handleMultiLineComment',
Expand All @@ -35,7 +42,7 @@ class SqlsrvParser extends AbstractParser
* @param State $state The parser state.
*
*/
protected function handleIdentifier($state)
protected function handleIdentifier(State $state)
{
$state->copyUntilCharacter(']');
}
Expand Down
Loading

0 comments on commit f054d65

Please sign in to comment.