summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2016-03-01 16:33:59 +0100
committerMichal Čihař <michal@cihar.com>2016-12-21 15:02:38 +0100
commit94a89e8406428655d49d4534230708a9c9d0c521 (patch)
tree93332101b34a30d0f0d03d422f7dbb11a13391b7 /src
parent26f97bce06a7a857e456df75dff899c4d5d5df55 (diff)
downloadsql-parser-94a89e8406428655d49d4534230708a9c9d0c521.zip
sql-parser-94a89e8406428655d49d4534230708a9c9d0c521.tar.gz
sql-parser-94a89e8406428655d49d4534230708a9c9d0c521.tar.bz2
Move motranslator initialization to share core class
Signed-off-by: Michal Čihař <michal@cihar.com>
Diffstat (limited to 'src')
-rw-r--r--src/Component.php2
-rw-r--r--src/Core.php9
-rw-r--r--src/Lexer.php3
-rw-r--r--src/Parser.php3
-rw-r--r--src/common.php11
5 files changed, 11 insertions, 17 deletions
diff --git a/src/Component.php b/src/Component.php
index 08720cf..4210706 100644
--- a/src/Component.php
+++ b/src/Component.php
@@ -12,8 +12,6 @@
*/
namespace SqlParser;
-require_once 'common.php';
-
/**
* A component (of a statement) is a part of a statement that is common to
* multiple query types.
diff --git a/src/Core.php b/src/Core.php
index ecca4dc..80fd5ba 100644
--- a/src/Core.php
+++ b/src/Core.php
@@ -7,6 +7,7 @@
*/
namespace SqlParser;
+use MoTranslator;
class Core
{
@@ -34,6 +35,14 @@ class Core
public $errors = array();
/**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ MoTranslator\Loader::load_functions();
+ }
+
+ /**
* Creates a new error log.
*
* @param Exception $error The error exception.
diff --git a/src/Lexer.php b/src/Lexer.php
index 1a706d2..3a37fb1 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -11,8 +11,6 @@
*/
namespace SqlParser;
-require_once 'common.php';
-
use SqlParser\Exceptions\LexerException;
if (!defined('USE_UTF_STRINGS')) {
@@ -162,6 +160,7 @@ class Lexer extends Core
*/
public function __construct($str, $strict = false, $delimiter = null)
{
+ parent::__construct();
// `strlen` is used instead of `mb_strlen` because the lexer needs to
// parse each byte of the input.
$len = ($str instanceof UtfString) ? $str->length() : strlen($str);
diff --git a/src/Parser.php b/src/Parser.php
index b18b02d..d3698f6 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -9,8 +9,6 @@
*/
namespace SqlParser;
-require_once 'common.php';
-
use SqlParser\Exceptions\ParserException;
use SqlParser\Statements\SelectStatement;
use SqlParser\Statements\TransactionStatement;
@@ -340,6 +338,7 @@ class Parser extends Core
*/
public function __construct($list = null, $strict = false)
{
+ parent::__construct();
if ((is_string($list)) || ($list instanceof UtfString)) {
$lexer = new Lexer($list, $strict);
$this->list = $lexer->list;
diff --git a/src/common.php b/src/common.php
deleted file mode 100644
index 94b248c..0000000
--- a/src/common.php
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-
-/**
- * Defines common elements used by the library.
- *
- * @package SqlParser
- */
-
-if (!function_exists('__')) {
- MoTranslator\Loader::load_functions();
-}