diff options
author | Dan Ungureanu <udan1107@gmail.com> | 2015-06-22 14:40:39 +0300 |
---|---|---|
committer | Dan Ungureanu <udan1107@gmail.com> | 2015-06-22 14:40:39 +0300 |
commit | 928478f86310f767a8948786470ac895b714cae3 (patch) | |
tree | ea238adb8ce6c2812ccc53e10f0bbcbe5509c8cc | |
parent | e822d7a43e9561760cd682d9c92070857ac98359 (diff) | |
download | sql-parser-928478f86310f767a8948786470ac895b714cae3.zip sql-parser-928478f86310f767a8948786470ac895b714cae3.tar.gz sql-parser-928478f86310f767a8948786470ac895b714cae3.tar.bz2 |
Refactoring.
-rw-r--r-- | src/Context.php | 54 | ||||
-rw-r--r-- | src/Contexts/ContextMySql50000.php (renamed from src/Contexts/Context_MySQL50000.php) | 2 | ||||
-rw-r--r-- | src/Contexts/ContextMySql50100.php (renamed from src/Contexts/Context_MySQL50100.php) | 2 | ||||
-rw-r--r-- | src/Contexts/ContextMySql50500.php (renamed from src/Contexts/Context_MySQL50500.php) | 2 | ||||
-rw-r--r-- | src/Contexts/ContextMySql50600.php (renamed from src/Contexts/Context_MySQL50600.php) | 2 | ||||
-rw-r--r-- | src/Contexts/ContextMySql50700.php (renamed from src/Contexts/Context_MySQL50700.php) | 2 | ||||
-rw-r--r-- | src/Utils/Misc.php | 10 | ||||
-rw-r--r-- | tests/lexer/ContextTest.php | 12 |
8 files changed, 47 insertions, 39 deletions
diff --git a/src/Context.php b/src/Context.php index e46a047..b04adc1 100644 --- a/src/Context.php +++ b/src/Context.php @@ -36,14 +36,22 @@ abstract class Context * * @var string */ - public static $defaultContext = '\\SqlParser\\Contexts\\Context_MySQL50700'; + public static $defaultContext = '\\SqlParser\\Contexts\\ContextMySql50700'; /** * The name of the loaded context. * * @var string */ - public static $loadedContext = '\\SqlParser\\Contexts\\Context_MySQL50700'; + public static $loadedContext = '\\SqlParser\\Contexts\\ContextMySql50700'; + + /** + * The prefix concatenated to the context name when an incomplete class name + * is specified. + * + * @var string + */ + public static $contextPrefix = '\\SqlParser\\Contexts\\Context'; // ------------------------------------------------------------------------- // Keywords. @@ -474,13 +482,13 @@ abstract class Context /** * Checks if the given character is a whitespace. * - * @param string $ch String to be checked. + * @param string $str String to be checked. * * @return bool */ - public static function isWhitespace($ch) + public static function isWhitespace($str) { - return ($ch === ' ') || ($ch === "\r") || ($ch === "\n") || ($ch === "\t"); + return ($str === ' ') || ($str === "\r") || ($str === "\n") || ($str === "\t"); } // ------------------------------------------------------------------------- @@ -519,14 +527,14 @@ abstract class Context * This actually check only for `TRUE` and `FALSE` because `1` or `0` are * actually numbers and are parsed by specific methods. * - * @param string $ch String to be checked. + * @param string $str String to be checked. * * @return bool */ - public static function isBool($ch) + public static function isBool($str) { - $ch = strtoupper($ch); - return ($ch === 'TRUE') || ($ch === 'FALSE'); + $str = strtoupper($str); + return ($str === 'TRUE') || ($str === 'FALSE'); } // ------------------------------------------------------------------------- @@ -535,14 +543,14 @@ abstract class Context /** * Checks if the given character can be a part of a number. * - * @param string $ch String to be checked. + * @param string $str String to be checked. * * @return bool */ - public static function isNumber($ch) + public static function isNumber($str) { - return (($ch >= '0') && ($ch <= '9')) || ($ch === '.') - || ($ch === '-') || ($ch === '+') || ($ch === 'e') || ($ch === 'E'); + return (($str >= '0') && ($str <= '9')) || ($str === '.') + || ($str === '-') || ($str === '+') || ($str === 'e') || ($str === 'E'); } // ------------------------------------------------------------------------- @@ -552,15 +560,15 @@ abstract class Context * Checks if the given character is the beginning of a symbol. A symbol * can be either a variable or a field name. * - * @param string $ch String to be checked. + * @param string $str String to be checked. * * @return int The appropriate flag for the symbol type. */ - public static function isSymbol($ch) + public static function isSymbol($str) { - if ($ch[0] === '@') { + if ($str[0] === '@') { return Token::FLAG_SYMBOL_VARIABLE; - } elseif ($ch[0] === '`') { + } elseif ($str[0] === '`') { return Token::FLAG_SYMBOL_BACKTICK; } return null; @@ -592,13 +600,13 @@ abstract class Context /** * Checks if the given character can be a separator for two lexems. * - * @param string $ch String to be checked. + * @param string $str String to be checked. * * @return bool */ - public static function isSeparator($ch) + public static function isSeparator($str) { - return !ctype_alnum($ch) && $ch !== '_'; + return !ctype_alnum($str) && $str !== '_'; } /** @@ -618,12 +626,12 @@ abstract class Context } if ($context[0] !== '\\') { // Short context name (must be formatted into class name). - $context = '\\SqlParser\\Contexts\\Context_' . $context; + $context = self::$contextPrefix . $context; } if (!class_exists($context)) { throw new \Exception('Specified context ("' . $context . '") doesn\'t exist.'); } - static::$loadedContext = $context; - static::$KEYWORDS = $context::$KEYWORDS; + self::$loadedContext = $context; + self::$KEYWORDS = $context::$KEYWORDS; } } diff --git a/src/Contexts/Context_MySQL50000.php b/src/Contexts/ContextMySql50000.php index 830399e..e54373d 100644 --- a/src/Contexts/Context_MySQL50000.php +++ b/src/Contexts/ContextMySql50000.php @@ -13,7 +13,7 @@ use SqlParser\Context; * @author Dan Ungureanu <udan1107@gmail.com> * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ -class Context_MySQL50000 extends Context +class ContextMySql50000 extends Context { public static $KEYWORDS = array( diff --git a/src/Contexts/Context_MySQL50100.php b/src/Contexts/ContextMySql50100.php index f70ecef..f853c9a 100644 --- a/src/Contexts/Context_MySQL50100.php +++ b/src/Contexts/ContextMySql50100.php @@ -13,7 +13,7 @@ use SqlParser\Context; * @author Dan Ungureanu <udan1107@gmail.com> * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ -class Context_MySQL50100 extends Context +class ContextMySql50100 extends Context { public static $KEYWORDS = array( diff --git a/src/Contexts/Context_MySQL50500.php b/src/Contexts/ContextMySql50500.php index 6febe72..9fe3e87 100644 --- a/src/Contexts/Context_MySQL50500.php +++ b/src/Contexts/ContextMySql50500.php @@ -13,7 +13,7 @@ use SqlParser\Context; * @author Dan Ungureanu <udan1107@gmail.com> * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ -class Context_MySQL50500 extends Context +class ContextMySql50500 extends Context { public static $KEYWORDS = array( diff --git a/src/Contexts/Context_MySQL50600.php b/src/Contexts/ContextMySql50600.php index dfd114a..b465026 100644 --- a/src/Contexts/Context_MySQL50600.php +++ b/src/Contexts/ContextMySql50600.php @@ -13,7 +13,7 @@ use SqlParser\Context; * @author Dan Ungureanu <udan1107@gmail.com> * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ -class Context_MySQL50600 extends Context +class ContextMySql50600 extends Context { public static $KEYWORDS = array( diff --git a/src/Contexts/Context_MySQL50700.php b/src/Contexts/ContextMySql50700.php index b795b2d..5f9014c 100644 --- a/src/Contexts/Context_MySQL50700.php +++ b/src/Contexts/ContextMySql50700.php @@ -13,7 +13,7 @@ use SqlParser\Context; * @author Dan Ungureanu <udan1107@gmail.com> * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ -class Context_MySQL50700 extends Context +class ContextMySql50700 extends Context { public static $KEYWORDS = array( diff --git a/src/Utils/Misc.php b/src/Utils/Misc.php index a29951e..2174060 100644 --- a/src/Utils/Misc.php +++ b/src/Utils/Misc.php @@ -20,11 +20,11 @@ class Misc * Gets a list of all aliases and their original names. * * @param SelectStatement $tree The tree that was generated after parsing. - * @param string $db The name of the database. + * @param string $database The name of the database. * * @return array */ - public static function getAliases(SelectStatement $tree, $db) + public static function getAliases(SelectStatement $tree, $database) { $retval = array(); @@ -34,7 +34,7 @@ class Misc && (!empty($tree->join->expr->alias)) ) { $thisDb = empty($tree->join->expr->database) ? - $db : $tree->join->expr->database; + $database : $tree->join->expr->database; $retval = array( $thisDb => array( @@ -56,7 +56,7 @@ class Misc continue; } - $thisDb = empty($expr->database) ? $db : $expr->database; + $thisDb = empty($expr->database) ? $database : $expr->database; if (!isset($retval[$thisDb])) { $retval[$thisDb] = array( @@ -83,7 +83,7 @@ class Misc continue; } - $thisDb = empty($expr->database) ? $db : $expr->database; + $thisDb = empty($expr->database) ? $database : $expr->database; if (empty($expr->table)) { foreach ($retval[$thisDb]['tables'] as &$table) { diff --git a/tests/lexer/ContextTest.php b/tests/lexer/ContextTest.php index cb52e1d..b630d03 100644 --- a/tests/lexer/ContextTest.php +++ b/tests/lexer/ContextTest.php @@ -12,28 +12,28 @@ class ContextTest extends TestCase public function testLoad() { // Default context is 5.7.0. - $this->assertEquals('\\SqlParser\\Contexts\\Context_MySQL50700', Context::$loadedContext); + $this->assertEquals('\\SqlParser\\Contexts\\ContextMySql50700', Context::$loadedContext); $this->assertTrue(isset(Context::$KEYWORDS['STORED'])); $this->assertFalse(isset(Context::$KEYWORDS['AUTHORS'])); - Context::load('MySQL50600'); - $this->assertEquals('\\SqlParser\\Contexts\\Context_MySQL50600', Context::$loadedContext); + Context::load('MySql50600'); + $this->assertEquals('\\SqlParser\\Contexts\\ContextMySql50600', Context::$loadedContext); $this->assertFalse(isset(Context::$KEYWORDS['STORED'])); $this->assertTrue(isset(Context::$KEYWORDS['AUTHORS'])); // Restoring context. Context::load(''); - $this->assertEquals('\\SqlParser\\Contexts\\Context_MySQL50700', Context::$defaultContext); + $this->assertEquals('\\SqlParser\\Contexts\\ContextMySql50700', Context::$defaultContext); $this->assertTrue(isset(Context::$KEYWORDS['STORED'])); $this->assertFalse(isset(Context::$KEYWORDS['AUTHORS'])); } /** * @expectedException Exception - * @expectedExceptionMessage Specified context ("\SqlParser\Contexts\Context_foo") doesn't exist. + * @expectedExceptionMessage Specified context ("\SqlParser\Contexts\ContextFoo") doesn't exist. */ public function testLoadError() { - Context::load('foo'); + Context::load('Foo'); } } |