summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Fragment.php7
-rw-r--r--src/Fragments/ArrayFragment.php2
-rw-r--r--src/Fragments/CallKeyword.php2
-rw-r--r--src/Fragments/FieldFragment.php2
-rw-r--r--src/Fragments/LimitKeyword.php2
-rw-r--r--src/Fragments/OptionsFragment.php2
-rw-r--r--src/Fragments/WhereKeyword.php31
-rw-r--r--src/Statements/SelectStatement.php2
-rw-r--r--src/Token.php86
9 files changed, 69 insertions, 67 deletions
diff --git a/src/Fragment.php b/src/Fragment.php
index 6ae85da..29ec8a9 100644
--- a/src/Fragment.php
+++ b/src/Fragment.php
@@ -41,11 +41,14 @@ abstract class Fragment
/**
* Builds the string representation of a fragment of this type.
*
- * @param Fragment $fragment The fragment to be built.
+ * In other words, this function represents the inverse function of
+ * `static::parse`.
+ *
+ * @param mixed $fragment The fragment to be built.
*
* @return string
*/
- public static function build(Fragment $fragment)
+ public static function build($fragment)
{
return null;
}
diff --git a/src/Fragments/ArrayFragment.php b/src/Fragments/ArrayFragment.php
index db12622..8c91fc2 100644
--- a/src/Fragments/ArrayFragment.php
+++ b/src/Fragments/ArrayFragment.php
@@ -131,7 +131,7 @@ class ArrayFragment extends Fragment
*
* @return string
*/
- public static function build(ArrayFragment $fragment)
+ public static function build($fragment)
{
$values = array();
if (!empty($fragment->raw)) {
diff --git a/src/Fragments/CallKeyword.php b/src/Fragments/CallKeyword.php
index 3b8cc80..e56940b 100644
--- a/src/Fragments/CallKeyword.php
+++ b/src/Fragments/CallKeyword.php
@@ -116,7 +116,7 @@ class CallKeyword extends Fragment
*
* @return string
*/
- public static function build(CallKeyword $fragment)
+ public static function build($fragment)
{
return $fragment->name . ArrayFragment::build($fragment->parameters);
}
diff --git a/src/Fragments/FieldFragment.php b/src/Fragments/FieldFragment.php
index 8b0f0ef..a6c5777 100644
--- a/src/Fragments/FieldFragment.php
+++ b/src/Fragments/FieldFragment.php
@@ -299,8 +299,6 @@ class FieldFragment extends Fragment
*/
public static function build($fragment)
{
- $ret = '';
-
if (!empty($fragment->expr)) {
$ret = $fragment->expr;
} else {
diff --git a/src/Fragments/LimitKeyword.php b/src/Fragments/LimitKeyword.php
index af8d92d..36efa02 100644
--- a/src/Fragments/LimitKeyword.php
+++ b/src/Fragments/LimitKeyword.php
@@ -45,7 +45,7 @@ class LimitKeyword extends Fragment
* @param int $rowCount The row count.
* @param int $offset The offset.
*/
- public function __construct($rowCount = null, $offset = null)
+ public function __construct($rowCount = 0, $offset = 0)
{
$this->rowCount = $rowCount;
$this->offset = $offset;
diff --git a/src/Fragments/OptionsFragment.php b/src/Fragments/OptionsFragment.php
index 16459cc..00ac282 100644
--- a/src/Fragments/OptionsFragment.php
+++ b/src/Fragments/OptionsFragment.php
@@ -142,7 +142,7 @@ class OptionsFragment extends Fragment
*
* @return string
*/
- public static function build(OptionsFragment $fragment)
+ public static function build($fragment)
{
$options = array();
foreach ($fragment->options as $option) {
diff --git a/src/Fragments/WhereKeyword.php b/src/Fragments/WhereKeyword.php
index d2143f3..0710738 100644
--- a/src/Fragments/WhereKeyword.php
+++ b/src/Fragments/WhereKeyword.php
@@ -44,16 +44,16 @@ class WhereKeyword extends Fragment
*
* @var string
*/
- public $condition;
+ public $expr;
/**
* Constructor.
*
- * @param string $condition The condition or the operator.
+ * @param string $expr The condition or the operator.
*/
- public function __construct($condition = null)
+ public function __construct($expr = null)
{
- $this->condition = trim($condition);
+ $this->expr = trim($expr);
}
/**
@@ -71,9 +71,10 @@ class WhereKeyword extends Fragment
* The condition that was parsed so far.
* @var string
*/
- $condition = '';
+ $tmp = '';
for (; $list->idx < $list->count; ++$list->idx) {
+
/**
* Token parsed at this moment.
* @var Token
@@ -92,10 +93,10 @@ class WhereKeyword extends Fragment
// Conditions are delimited by logical operators.
if (in_array($token->value, static::$OPERATORS, true)) {
- if (!empty(trim($condition))) {
+ if (!empty(trim($tmp))) {
// Adding the condition that is delimited by this operator.
- $ret[] = new WhereKeyword($condition);
- $condition = '';
+ $ret[] = new WhereKeyword($tmp);
+ $tmp = '';
}
// Adding the operator.
@@ -111,13 +112,13 @@ class WhereKeyword extends Fragment
break;
}
- $condition .= $token->token;
+ $tmp .= $token->token;
}
// Last iteration was not processed.
- if (!empty(trim($condition))) {
- $ret[] = new WhereKeyword($condition);
+ if (!empty(trim($tmp))) {
+ $ret[] = new WhereKeyword($tmp);
}
--$list->idx;
@@ -125,16 +126,16 @@ class WhereKeyword extends Fragment
}
/**
- * @param WhereKeyword $fragment The fragment to be built.
+ * @param WhereKeyword[] $fragment The fragment to be built.
*
* @return string
*/
public static function build($fragment)
{
- $conditions = array();
+ $ret = array();
foreach ($fragment as $f) {
- $conditions[] = $f->condition;
+ $ret[] = $f->expr;
}
- return implode(' ', $conditions);
+ return implode(' ', $ret);
}
}
diff --git a/src/Statements/SelectStatement.php b/src/Statements/SelectStatement.php
index 7704e26..84ec5a2 100644
--- a/src/Statements/SelectStatement.php
+++ b/src/Statements/SelectStatement.php
@@ -70,7 +70,7 @@ class SelectStatement extends Statement
/**
* The clauses of this statement, in order.
*
- * @see Statement::$CLAUSES
+ * @see Statement::$CLAUSES
*
* @var array
*/
diff --git a/src/Token.php b/src/Token.php
index 1db0d1d..fa23d28 100644
--- a/src/Token.php
+++ b/src/Token.php
@@ -217,52 +217,52 @@ class Token
public function extract()
{
switch ($this->type) {
- case Token::TYPE_KEYWORD:
- if (!($this->flags & Token::FLAG_KEYWORD_RESERVED)) {
- // Unreserved keywords should stay the way they are because they
- // might represent field names.
- return $this->token;
- }
- return strtoupper($this->token);
- case Token::TYPE_WHITESPACE:
- return ' ';
- case Token::TYPE_BOOL:
- return strtoupper($this->token) === 'TRUE';
- case Token::TYPE_NUMBER:
- $ret = str_replace('--', '', $this->token); // e.g. ---42 === -42
- if ($this->flags & Token::FLAG_NUMBER_HEX) {
- if ($this->flags & Token::FLAG_NUMBER_NEGATIVE) {
- $ret = str_replace('-', '', $this->token);
- sscanf($ret, "%x", $ret);
- $ret = -$ret;
- } else {
- sscanf($ret, "%x", $ret);
- }
- } elseif (($this->flags & Token::FLAG_NUMBER_APPROXIMATE)
- || ($this->flags & Token::FLAG_NUMBER_FLOAT)
- ) {
- sscanf($ret, "%f", $ret);
+ case Token::TYPE_KEYWORD:
+ if (!($this->flags & Token::FLAG_KEYWORD_RESERVED)) {
+ // Unreserved keywords should stay the way they are because they
+ // might represent field names.
+ return $this->token;
+ }
+ return strtoupper($this->token);
+ case Token::TYPE_WHITESPACE:
+ return ' ';
+ case Token::TYPE_BOOL:
+ return strtoupper($this->token) === 'TRUE';
+ case Token::TYPE_NUMBER:
+ $ret = str_replace('--', '', $this->token); // e.g. ---42 === -42
+ if ($this->flags & Token::FLAG_NUMBER_HEX) {
+ if ($this->flags & Token::FLAG_NUMBER_NEGATIVE) {
+ $ret = str_replace('-', '', $this->token);
+ sscanf($ret, "%x", $ret);
+ $ret = -$ret;
} else {
- sscanf($ret, "%d", $ret);
- }
- return $ret;
- case Token::TYPE_STRING:
- $quote = $this->token[0];
- $str = str_replace($quote . $quote, $quote, $this->token);
- return mb_substr($str, 1, -1); // trims quotes
- case Token::TYPE_SYMBOL:
- $str = $this->token;
- if ((isset($str[0])) && ($str[0] === '@')) {
- $str = mb_substr($str, 1);
+ sscanf($ret, "%x", $ret);
}
- if ((isset($str[0])) && (($str[0] === '`')
+ } elseif (($this->flags & Token::FLAG_NUMBER_APPROXIMATE)
+ || ($this->flags & Token::FLAG_NUMBER_FLOAT)
+ ) {
+ sscanf($ret, "%f", $ret);
+ } else {
+ sscanf($ret, "%d", $ret);
+ }
+ return $ret;
+ case Token::TYPE_STRING:
+ $quote = $this->token[0];
+ $str = str_replace($quote . $quote, $quote, $this->token);
+ return mb_substr($str, 1, -1); // trims quotes
+ case Token::TYPE_SYMBOL:
+ $str = $this->token;
+ if ((isset($str[0])) && ($str[0] === '@')) {
+ $str = mb_substr($str, 1);
+ }
+ if ((isset($str[0])) && (($str[0] === '`')
|| ($str[0] === '"') || ($str[0] === '\''))
- ) {
- $quote = $str[0];
- $str = str_replace($quote . $quote, $quote, $str);
- $str = mb_substr($str, 1, -1);
- }
- return $str;
+ ) {
+ $quote = $str[0];
+ $str = str_replace($quote . $quote, $quote, $str);
+ $str = mb_substr($str, 1, -1);
+ }
+ return $str;
}
return $this->token;
}