Passed
Push — master ( d44413...7ff405 )
by Adrian
04:24
created
src/Traits/DefaultPriority.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -14,17 +14,17 @@
 block discarded – undo
14 14
 trait DefaultPriority
15 15
 {
16 16
 
17
-    use Objects;
17
+	use Objects;
18 18
 
19 19
 
20
-    /**
21
-     * @return $this
22
-     */
23
-    public function defaultPriority()
24
-    {
25
-        $this->queryStructure->setElement(QueryStructure::PRIORITY, '');
20
+	/**
21
+	 * @return $this
22
+	 */
23
+	public function defaultPriority()
24
+	{
25
+		$this->queryStructure->setElement(QueryStructure::PRIORITY, '');
26 26
 
27
-        return $this;
28
-    }
27
+		return $this;
28
+	}
29 29
 
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
src/Dependencies/QueryException.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -11,23 +11,23 @@
 block discarded – undo
11 11
 class QueryException extends \Exception
12 12
 {
13 13
 
14
-    const QUERY_ERROR_ELEMENT_NOT_FOUND = 10;
15
-    const QUERY_ERROR_ELEMENT_TYPE = 11;
16
-    const QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY = 20;
17
-    const QUERY_ERROR_WHERE_INVALID_OPERATOR = 30;
18
-    const QUERY_ERROR_INVALID_LIMIT = 40;
19
-    const QUERY_ERROR_INVALID_LIMIT_ZERO = 50;
20
-    const QUERY_ERROR_INVALID_LIMIT_OFFSET = 60;
21
-    const QUERY_ERROR_DELETE_NOT_FILTER = 70;
14
+	const QUERY_ERROR_ELEMENT_NOT_FOUND = 10;
15
+	const QUERY_ERROR_ELEMENT_TYPE = 11;
16
+	const QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY = 20;
17
+	const QUERY_ERROR_WHERE_INVALID_OPERATOR = 30;
18
+	const QUERY_ERROR_INVALID_LIMIT = 40;
19
+	const QUERY_ERROR_INVALID_LIMIT_ZERO = 50;
20
+	const QUERY_ERROR_INVALID_LIMIT_OFFSET = 60;
21
+	const QUERY_ERROR_DELETE_NOT_FILTER = 70;
22 22
 
23
-    const QUERY_ERROR_INVALID_FIELDS_COUNT = 91;
24
-    const QUERY_ERROR_INVALID_DISTINCT = 92;
25
-    const QUERY_ERROR_HAVING_INVALID_PARAM_ARRAY = 93;
26
-    const QUERY_ERROR_HAVING_INVALID_OPERATOR = 94;
27
-    const QUERY_ERROR_SELECT_INVALID_FIELD = 95;
28
-    const QUERY_ERROR_SELECT_INVALID_PARAM = 96;
29
-    const QUERY_ERROR_INVALID_TABLE_STATEMENT = 97;
30
-    const QUERY_ERROR_INVALID_COLUMN_NAME = 98;
31
-    const QUERY_ERROR_INVALID_CONDITION_TYPE = 99;
23
+	const QUERY_ERROR_INVALID_FIELDS_COUNT = 91;
24
+	const QUERY_ERROR_INVALID_DISTINCT = 92;
25
+	const QUERY_ERROR_HAVING_INVALID_PARAM_ARRAY = 93;
26
+	const QUERY_ERROR_HAVING_INVALID_OPERATOR = 94;
27
+	const QUERY_ERROR_SELECT_INVALID_FIELD = 95;
28
+	const QUERY_ERROR_SELECT_INVALID_PARAM = 96;
29
+	const QUERY_ERROR_INVALID_TABLE_STATEMENT = 97;
30
+	const QUERY_ERROR_INVALID_COLUMN_NAME = 98;
31
+	const QUERY_ERROR_INVALID_CONDITION_TYPE = 99;
32 32
 
33 33
 }
34 34
\ No newline at end of file
Please login to merge, or discard this patch.
src/Dependencies/QueryHelper.php 1 patch
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -11,147 +11,147 @@
 block discarded – undo
11 11
 class QueryHelper
12 12
 {
13 13
 
14
-    /**
15
-     * @param string $string
16
-     * @return mixed|string
17
-     */
18
-    public static function clearMultipleSpaces($string = '')
19
-    {
20
-        $string = preg_replace('/\s+/', ' ', $string);
21
-        $string = trim($string);
22
-
23
-        return $string;
24
-    }
25
-
26
-    /**
27
-     * @param $val
28
-     * @return bool
29
-     */
30
-    public static function isInteger($val)
31
-    {
32
-        $val = trim($val);
33
-
34
-        return is_numeric($val) && floor($val) == $val;
35
-    }
36
-
37
-    /**
38
-     * @param $val
39
-     * @return bool
40
-     * @i
41
-     */
42
-    public static function isDecimal($val)
43
-    {
44
-        $val = trim($val);
45
-
46
-        return is_numeric($val) && floor($val) != $val;
47
-    }
48
-
49
-    public static function isValidOrderBy($order_by_parameter)
50
-    {
51
-
52
-        $columns = array('first_name', 'last_name', 'zip', 'created_at');
53
-
54
-        $parts = preg_split("/[\s,]+/", $order_by_parameter);
55
-
56
-        foreach ($parts as $part) {
57
-            $subparts = preg_split("/\s+/", $part);
58
-
59
-            if (count($subparts) < 0 || count($subparts) > 2) {
60
-                // Too many or too few parts.
61
-                return false;
62
-            }
63
-
64
-            if (!in_array($subparts[0], $columns)) {
65
-                // Column name is invalid.
66
-                return false;
67
-            }
68
-
69
-            if (count($subparts) == 2 && !in_array(strtoupper($subparts[1]), array('ASC', 'DESC'))) {
70
-                // ASC or DESC is invalid
71
-                return false;
72
-            }
73
-        }
74
-
75
-        return true;
76
-    }
77
-
78
-
79
-    /**
80
-     * @param $string
81
-     * @param string $delimiter
82
-     * @return array
83
-     */
84
-    public static function explode($string, $delimiter = ',')
85
-    {
86
-        $brutArray = explode($delimiter, $string);
87
-        $newArray = array();
88
-        foreach ($brutArray as $value) {
89
-            $value = trim($value);
90
-            if ('' !== $value)
91
-                $newArray[] = $value;
92
-        }
93
-
94
-        return $newArray;
95
-    }
96
-
97
-    public static function alphaNum($string)
98
-    {
99
-        $string = preg_replace("/[^a-zA-Z0-9 _,]+/", "", $string);
100
-
101
-        return self::clearMultipleSpaces($string);
102
-    }
103
-
104
-    /**
105
-     * @param array $array
106
-     * @param string $delimiter
107
-     * @return string
108
-     */
109
-    public static function implode(array $array, $delimiter = ',')
110
-    {
111
-        $string = implode($delimiter, $array);
112
-        $string = trim($string);
113
-        $string = trim($string, trim($delimiter));
114
-        $string = trim($string);
115
-
116
-        return $string;
117
-    }
118
-
119
-    /**
120
-     * @param $string
121
-     * @return mixed|string
122
-     */
123
-    public static function clearQuotes($string)
124
-    {
125
-        $search = array('"', "'");
126
-        $replace = '';
127
-        $string = str_replace($search, $replace, $string);
128
-
129
-        return self::clearMultipleSpaces($string);
130
-    }
131
-
132
-    /**
133
-     * @param int $length
134
-     * @return string
135
-     */
136
-    public static function random($length = 5)
137
-    {
138
-        $characters = 'abcdefghijklmnopqrstuvwxyz';
139
-        $charactersLength = strlen($characters);
140
-        $randomString = '';
141
-        for ($i = 0; $i < $length; $i++)
142
-            $randomString .= $characters[ rand(0, $charactersLength - 1) ];
143
-
144
-        return str_shuffle($randomString);
145
-    }
146
-
147
-    public static function limitString($rowCount, $offset = null)
148
-    {
149
-        $rowCount = intval($rowCount);
150
-        if (is_null($offset))
151
-            return $rowCount;
152
-        $offset = intval($offset);
153
-
154
-        return "$offset, $rowCount";
155
-    }
14
+	/**
15
+	 * @param string $string
16
+	 * @return mixed|string
17
+	 */
18
+	public static function clearMultipleSpaces($string = '')
19
+	{
20
+		$string = preg_replace('/\s+/', ' ', $string);
21
+		$string = trim($string);
22
+
23
+		return $string;
24
+	}
25
+
26
+	/**
27
+	 * @param $val
28
+	 * @return bool
29
+	 */
30
+	public static function isInteger($val)
31
+	{
32
+		$val = trim($val);
33
+
34
+		return is_numeric($val) && floor($val) == $val;
35
+	}
36
+
37
+	/**
38
+	 * @param $val
39
+	 * @return bool
40
+	 * @i
41
+	 */
42
+	public static function isDecimal($val)
43
+	{
44
+		$val = trim($val);
45
+
46
+		return is_numeric($val) && floor($val) != $val;
47
+	}
48
+
49
+	public static function isValidOrderBy($order_by_parameter)
50
+	{
51
+
52
+		$columns = array('first_name', 'last_name', 'zip', 'created_at');
53
+
54
+		$parts = preg_split("/[\s,]+/", $order_by_parameter);
55
+
56
+		foreach ($parts as $part) {
57
+			$subparts = preg_split("/\s+/", $part);
58
+
59
+			if (count($subparts) < 0 || count($subparts) > 2) {
60
+				// Too many or too few parts.
61
+				return false;
62
+			}
63
+
64
+			if (!in_array($subparts[0], $columns)) {
65
+				// Column name is invalid.
66
+				return false;
67
+			}
68
+
69
+			if (count($subparts) == 2 && !in_array(strtoupper($subparts[1]), array('ASC', 'DESC'))) {
70
+				// ASC or DESC is invalid
71
+				return false;
72
+			}
73
+		}
74
+
75
+		return true;
76
+	}
77
+
78
+
79
+	/**
80
+	 * @param $string
81
+	 * @param string $delimiter
82
+	 * @return array
83
+	 */
84
+	public static function explode($string, $delimiter = ',')
85
+	{
86
+		$brutArray = explode($delimiter, $string);
87
+		$newArray = array();
88
+		foreach ($brutArray as $value) {
89
+			$value = trim($value);
90
+			if ('' !== $value)
91
+				$newArray[] = $value;
92
+		}
93
+
94
+		return $newArray;
95
+	}
96
+
97
+	public static function alphaNum($string)
98
+	{
99
+		$string = preg_replace("/[^a-zA-Z0-9 _,]+/", "", $string);
100
+
101
+		return self::clearMultipleSpaces($string);
102
+	}
103
+
104
+	/**
105
+	 * @param array $array
106
+	 * @param string $delimiter
107
+	 * @return string
108
+	 */
109
+	public static function implode(array $array, $delimiter = ',')
110
+	{
111
+		$string = implode($delimiter, $array);
112
+		$string = trim($string);
113
+		$string = trim($string, trim($delimiter));
114
+		$string = trim($string);
115
+
116
+		return $string;
117
+	}
118
+
119
+	/**
120
+	 * @param $string
121
+	 * @return mixed|string
122
+	 */
123
+	public static function clearQuotes($string)
124
+	{
125
+		$search = array('"', "'");
126
+		$replace = '';
127
+		$string = str_replace($search, $replace, $string);
128
+
129
+		return self::clearMultipleSpaces($string);
130
+	}
131
+
132
+	/**
133
+	 * @param int $length
134
+	 * @return string
135
+	 */
136
+	public static function random($length = 5)
137
+	{
138
+		$characters = 'abcdefghijklmnopqrstuvwxyz';
139
+		$charactersLength = strlen($characters);
140
+		$randomString = '';
141
+		for ($i = 0; $i < $length; $i++)
142
+			$randomString .= $characters[ rand(0, $charactersLength - 1) ];
143
+
144
+		return str_shuffle($randomString);
145
+	}
146
+
147
+	public static function limitString($rowCount, $offset = null)
148
+	{
149
+		$rowCount = intval($rowCount);
150
+		if (is_null($offset))
151
+			return $rowCount;
152
+		$offset = intval($offset);
153
+
154
+		return "$offset, $rowCount";
155
+	}
156 156
 
157 157
 }
158 158
\ No newline at end of file
Please login to merge, or discard this patch.
src/Dependencies/QueryTimer.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -11,33 +11,33 @@
 block discarded – undo
11 11
 class QueryTimer
12 12
 {
13 13
 
14
-    /**
15
-     * @var mixed
16
-     */
17
-    private $queryStart;
18
-
19
-    /**
20
-     * @var mixed
21
-     */
22
-    private $queryEnd;
23
-
24
-
25
-    /**
26
-     * QueryTimer constructor.
27
-     */
28
-    public function __construct()
29
-    {
30
-        $this->queryStart = microtime(true);
31
-    }
32
-
33
-    /**
34
-     * @return float
35
-     */
36
-    public function getDuration()
37
-    {
38
-        $this->queryEnd = microtime(true);
39
-
40
-        return $this->queryEnd - $this->queryStart;
41
-    }
14
+	/**
15
+	 * @var mixed
16
+	 */
17
+	private $queryStart;
18
+
19
+	/**
20
+	 * @var mixed
21
+	 */
22
+	private $queryEnd;
23
+
24
+
25
+	/**
26
+	 * QueryTimer constructor.
27
+	 */
28
+	public function __construct()
29
+	{
30
+		$this->queryStart = microtime(true);
31
+	}
32
+
33
+	/**
34
+	 * @return float
35
+	 */
36
+	public function getDuration()
37
+	{
38
+		$this->queryEnd = microtime(true);
39
+
40
+		return $this->queryEnd - $this->queryStart;
41
+	}
42 42
 
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
src/Dependencies/QueryStructure.php 1 patch
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -13,234 +13,234 @@
 block discarded – undo
13 13
 class QueryStructure
14 14
 {
15 15
 
16
-    const TABLE = 'table';
17
-    const EXPLAIN = 'explain';
18
-    const STATEMENT = 'statement';
19
-    const PRIORITY = 'priority';
20
-    const FIELDS = 'fields';
21
-    const SET_FIELDS = 'set_fields';
22
-    const WHERE = 'where';
23
-    const HAVING = 'having';
24
-    const WHERE_INVERT = 'where_invert';
25
-    const HAVING_INVERT = 'having_invert';
26
-    const LIMIT = 'limit_rows';
27
-    const ORDER_BY = 'order_by';
28
-    const GROUP_BY = 'group_by';
29
-    const COUNT = 'count';
30
-    const COLUMN = 'column';
31
-    const FIRST = 'first';
32
-    const DISTINCT = 'distinct';
33
-    const JOIN = 'join';
34
-    const IGNORE = 'ignore';
35
-    const MULTIPLE_ROWS = 'multiple_rows';
36
-    const QUERY = 'query';
37
-    const BIND_PARAMS = 'bind_params';
38
-    const REPLACEMENT = 'replacement';
39
-    const QUERY_TYPE = 'query_type';
40
-    const QUERY_STRING = 'query_string';
41
-    const QUERY_COMMENT = 'query_comment';
42
-    const QUERY_IDENTIFIER = 'query_identifier';
43
-    const WHERE_TRIGGER = 'where_trigger';
44
-    const INSTANCE = 'instance';
45
-
46
-    /**
47
-     *  Elements type
48
-     */
49
-
50
-    const ELEMENT_TYPE_BOOLEAN = 'boolean';
51
-    const ELEMENT_TYPE_INTEGER = 'integer';
52
-    const ELEMENT_TYPE_DOUBLE = 'double';
53
-    const ELEMENT_TYPE_STRING = 'string';
54
-    const ELEMENT_TYPE_ARRAY = 'array';
55
-    const ELEMENT_TYPE_OBJECT = 'object';
56
-    const ELEMENT_TYPE_RESOURCE = 'resource';
57
-    const ELEMENT_TYPE_NULL = 'NULL';
58
-    const ELEMENT_TYPE_UNKNOWN = 'unknown type';
59
-
60
-    /**
61
-     * @var array
62
-     */
63
-    private static $usedInstanceIds = [];
64
-
65
-    /**
66
-     * @var array
67
-     */
68
-    private $syntaxEL = array();
69
-
70
-    /**
71
-     * @var array
72
-     */
73
-    private $typeEL = array();
74
-
75
-    /**
76
-     * @var int
77
-     */
78
-    private $counter = 0;
79
-
80
-
81
-    /**
82
-     * QueryStructure constructor.
83
-     */
84
-    public function __construct()
85
-    {
86
-        $this->syntaxEL = $this->init();
87
-
88
-        foreach ($this->syntaxEL as $name => $value)
89
-            $this->typeEL[ $name ] = gettype($value);
90
-
91
-    }
92
-
93
-    private function init()
94
-    {
95
-        return [self::TABLE => '', self::EXPLAIN => 0, self::STATEMENT => '', self::PRIORITY => '', self::FIELDS => '*', self::SET_FIELDS => array(), self::WHERE => array(), self::HAVING => array(), self::WHERE_INVERT => 0, self::HAVING_INVERT => 0, self::LIMIT => 0, self::ORDER_BY => array(), self::GROUP_BY => array(), self::COUNT => 0, self::COLUMN => '', self::FIRST => 0, self::DISTINCT => 0, self::JOIN => array(), self::IGNORE => 0, self::MULTIPLE_ROWS => 0, self::QUERY => '', self::BIND_PARAMS => array(), self::REPLACEMENT => 0, self::QUERY_TYPE => 0, self::QUERY_STRING => '', self::QUERY_COMMENT => '', self::QUERY_IDENTIFIER => 'DEFAULT', self::WHERE_TRIGGER => 1, self::INSTANCE => $this->makeStatementInstance()];
96
-    }
97
-
98
-
99
-    private function makeStatementInstance()
100
-    {
101
-        $instance = QueryHelper::random(5);
102
-        while (in_array($instance, self::$usedInstanceIds)) {
103
-            $instance = QueryHelper::random(7);
104
-        }
105
-        self::$usedInstanceIds[] = $instance;
106
-
107
-        return $instance;
108
-    }
109
-
110
-
111
-    /**
112
-     * @return array
113
-     */
114
-    public static function getUsedInstances()
115
-    {
116
-        return self::$usedInstanceIds;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return array
122
-     */
123
-    public function getAllElements()
124
-    {
125
-        return $this->syntaxEL;
126
-    }
127
-
128
-    /**
129
-     * @param $elements
130
-     */
131
-    public function setAllElements($elements)
132
-    {
133
-        $this->syntaxEL = $elements;
134
-    }
135
-
136
-
137
-    /**
138
-     * @param $name
139
-     * @param $value
140
-     * @return bool
141
-     * @throws QueryException
142
-     */
143
-    public function setElement($name, $value)
144
-    {
145
-        if (!array_key_exists($name, $this->syntaxEL))
146
-            throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND);
147
-
148
-        if ($name == self::TABLE && is_a($value, QueryStatement::class))
149
-            return true;
150
-
151
-        if ($this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY)
152
-            $this->syntaxEL[ $name ][] = $value; else
153
-            $this->syntaxEL[ $name ] = $value;
154
-
155
-        return true;
156
-    }
157
-
158
-
159
-    /**
160
-     * @param string $elementName
161
-     * @param $elementValue
162
-     * @throws QueryException
163
-     */
164
-    public function replaceElement($elementName, $elementValue)
165
-    {
166
-        if (!array_key_exists($elementName, $this->syntaxEL))
167
-            throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND);
168
-
169
-        $this->syntaxEL[ $elementName ] = $elementValue;
170
-    }
171
-
172
-
173
-    /**
174
-     * @param string $name
175
-     * @return mixed
176
-     */
177
-    public function getElement($name)
178
-    {
179
-        return $this->syntaxEL[ $name ];
180
-    }
181
-
182
-
183
-    /**
184
-     * @param $name
185
-     * @param $value
186
-     */
187
-    public function setParams($name, $value)
188
-    {
189
-        $this->syntaxEL[ QueryStructure::BIND_PARAMS ][ $name ] = $value;
190
-    }
191
-
192
-
193
-    /**
194
-     * @param $name
195
-     * @param $value
196
-     * @return string
197
-     */
198
-    public function bindParam($name, $value)
199
-    {
200
-        $pdoName = $this->index($name);
201
-        $this->syntaxEL[ QueryStructure::BIND_PARAMS ][ $pdoName ] = $value;
202
-
203
-        return ':' . $pdoName;
204
-    }
205
-
206
-
207
-    /**
208
-     * @param $expression
209
-     * @param array $params
210
-     * @param string $search
211
-     * @return string
212
-     */
213
-    public function bindParamsExpression($expression, array $params = [], $search = '?')
214
-    {
215
-        if (!count($params))
216
-            return $expression;
217
-
218
-        if (strpos($expression, $search) === false)
219
-            return $expression;
220
-
221
-        $params = array_slice($params, 0, substr_count($expression, $search));
222
-
223
-        $i = 0;
224
-        $arrayReturn = [];
225
-        $expressionToArray = explode($search, $expression);
226
-
227
-        foreach ($expressionToArray as $sub) {
228
-            $arrayReturn[] = $sub;
229
-            $arrayReturn[] = array_key_exists($i, $params) ? $this->bindParam('exp', $params[ $i ]) : '';
230
-            $i++;
231
-        }
232
-
233
-        return implode('', $arrayReturn);
234
-    }
235
-
236
-
237
-    /**
238
-     * @param string $fieldName
239
-     * @return string
240
-     */
241
-    public function index($fieldName = '')
242
-    {
243
-        return trim($fieldName) . '_' . $this->syntaxEL[ self::INSTANCE ] . '_' . ++$this->counter . 'i';
244
-    }
16
+	const TABLE = 'table';
17
+	const EXPLAIN = 'explain';
18
+	const STATEMENT = 'statement';
19
+	const PRIORITY = 'priority';
20
+	const FIELDS = 'fields';
21
+	const SET_FIELDS = 'set_fields';
22
+	const WHERE = 'where';
23
+	const HAVING = 'having';
24
+	const WHERE_INVERT = 'where_invert';
25
+	const HAVING_INVERT = 'having_invert';
26
+	const LIMIT = 'limit_rows';
27
+	const ORDER_BY = 'order_by';
28
+	const GROUP_BY = 'group_by';
29
+	const COUNT = 'count';
30
+	const COLUMN = 'column';
31
+	const FIRST = 'first';
32
+	const DISTINCT = 'distinct';
33
+	const JOIN = 'join';
34
+	const IGNORE = 'ignore';
35
+	const MULTIPLE_ROWS = 'multiple_rows';
36
+	const QUERY = 'query';
37
+	const BIND_PARAMS = 'bind_params';
38
+	const REPLACEMENT = 'replacement';
39
+	const QUERY_TYPE = 'query_type';
40
+	const QUERY_STRING = 'query_string';
41
+	const QUERY_COMMENT = 'query_comment';
42
+	const QUERY_IDENTIFIER = 'query_identifier';
43
+	const WHERE_TRIGGER = 'where_trigger';
44
+	const INSTANCE = 'instance';
45
+
46
+	/**
47
+	 *  Elements type
48
+	 */
49
+
50
+	const ELEMENT_TYPE_BOOLEAN = 'boolean';
51
+	const ELEMENT_TYPE_INTEGER = 'integer';
52
+	const ELEMENT_TYPE_DOUBLE = 'double';
53
+	const ELEMENT_TYPE_STRING = 'string';
54
+	const ELEMENT_TYPE_ARRAY = 'array';
55
+	const ELEMENT_TYPE_OBJECT = 'object';
56
+	const ELEMENT_TYPE_RESOURCE = 'resource';
57
+	const ELEMENT_TYPE_NULL = 'NULL';
58
+	const ELEMENT_TYPE_UNKNOWN = 'unknown type';
59
+
60
+	/**
61
+	 * @var array
62
+	 */
63
+	private static $usedInstanceIds = [];
64
+
65
+	/**
66
+	 * @var array
67
+	 */
68
+	private $syntaxEL = array();
69
+
70
+	/**
71
+	 * @var array
72
+	 */
73
+	private $typeEL = array();
74
+
75
+	/**
76
+	 * @var int
77
+	 */
78
+	private $counter = 0;
79
+
80
+
81
+	/**
82
+	 * QueryStructure constructor.
83
+	 */
84
+	public function __construct()
85
+	{
86
+		$this->syntaxEL = $this->init();
87
+
88
+		foreach ($this->syntaxEL as $name => $value)
89
+			$this->typeEL[ $name ] = gettype($value);
90
+
91
+	}
92
+
93
+	private function init()
94
+	{
95
+		return [self::TABLE => '', self::EXPLAIN => 0, self::STATEMENT => '', self::PRIORITY => '', self::FIELDS => '*', self::SET_FIELDS => array(), self::WHERE => array(), self::HAVING => array(), self::WHERE_INVERT => 0, self::HAVING_INVERT => 0, self::LIMIT => 0, self::ORDER_BY => array(), self::GROUP_BY => array(), self::COUNT => 0, self::COLUMN => '', self::FIRST => 0, self::DISTINCT => 0, self::JOIN => array(), self::IGNORE => 0, self::MULTIPLE_ROWS => 0, self::QUERY => '', self::BIND_PARAMS => array(), self::REPLACEMENT => 0, self::QUERY_TYPE => 0, self::QUERY_STRING => '', self::QUERY_COMMENT => '', self::QUERY_IDENTIFIER => 'DEFAULT', self::WHERE_TRIGGER => 1, self::INSTANCE => $this->makeStatementInstance()];
96
+	}
97
+
98
+
99
+	private function makeStatementInstance()
100
+	{
101
+		$instance = QueryHelper::random(5);
102
+		while (in_array($instance, self::$usedInstanceIds)) {
103
+			$instance = QueryHelper::random(7);
104
+		}
105
+		self::$usedInstanceIds[] = $instance;
106
+
107
+		return $instance;
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return array
113
+	 */
114
+	public static function getUsedInstances()
115
+	{
116
+		return self::$usedInstanceIds;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return array
122
+	 */
123
+	public function getAllElements()
124
+	{
125
+		return $this->syntaxEL;
126
+	}
127
+
128
+	/**
129
+	 * @param $elements
130
+	 */
131
+	public function setAllElements($elements)
132
+	{
133
+		$this->syntaxEL = $elements;
134
+	}
135
+
136
+
137
+	/**
138
+	 * @param $name
139
+	 * @param $value
140
+	 * @return bool
141
+	 * @throws QueryException
142
+	 */
143
+	public function setElement($name, $value)
144
+	{
145
+		if (!array_key_exists($name, $this->syntaxEL))
146
+			throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND);
147
+
148
+		if ($name == self::TABLE && is_a($value, QueryStatement::class))
149
+			return true;
150
+
151
+		if ($this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY)
152
+			$this->syntaxEL[ $name ][] = $value; else
153
+			$this->syntaxEL[ $name ] = $value;
154
+
155
+		return true;
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param string $elementName
161
+	 * @param $elementValue
162
+	 * @throws QueryException
163
+	 */
164
+	public function replaceElement($elementName, $elementValue)
165
+	{
166
+		if (!array_key_exists($elementName, $this->syntaxEL))
167
+			throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND);
168
+
169
+		$this->syntaxEL[ $elementName ] = $elementValue;
170
+	}
171
+
172
+
173
+	/**
174
+	 * @param string $name
175
+	 * @return mixed
176
+	 */
177
+	public function getElement($name)
178
+	{
179
+		return $this->syntaxEL[ $name ];
180
+	}
181
+
182
+
183
+	/**
184
+	 * @param $name
185
+	 * @param $value
186
+	 */
187
+	public function setParams($name, $value)
188
+	{
189
+		$this->syntaxEL[ QueryStructure::BIND_PARAMS ][ $name ] = $value;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param $name
195
+	 * @param $value
196
+	 * @return string
197
+	 */
198
+	public function bindParam($name, $value)
199
+	{
200
+		$pdoName = $this->index($name);
201
+		$this->syntaxEL[ QueryStructure::BIND_PARAMS ][ $pdoName ] = $value;
202
+
203
+		return ':' . $pdoName;
204
+	}
205
+
206
+
207
+	/**
208
+	 * @param $expression
209
+	 * @param array $params
210
+	 * @param string $search
211
+	 * @return string
212
+	 */
213
+	public function bindParamsExpression($expression, array $params = [], $search = '?')
214
+	{
215
+		if (!count($params))
216
+			return $expression;
217
+
218
+		if (strpos($expression, $search) === false)
219
+			return $expression;
220
+
221
+		$params = array_slice($params, 0, substr_count($expression, $search));
222
+
223
+		$i = 0;
224
+		$arrayReturn = [];
225
+		$expressionToArray = explode($search, $expression);
226
+
227
+		foreach ($expressionToArray as $sub) {
228
+			$arrayReturn[] = $sub;
229
+			$arrayReturn[] = array_key_exists($i, $params) ? $this->bindParam('exp', $params[ $i ]) : '';
230
+			$i++;
231
+		}
232
+
233
+		return implode('', $arrayReturn);
234
+	}
235
+
236
+
237
+	/**
238
+	 * @param string $fieldName
239
+	 * @return string
240
+	 */
241
+	public function index($fieldName = '')
242
+	{
243
+		return trim($fieldName) . '_' . $this->syntaxEL[ self::INSTANCE ] . '_' . ++$this->counter . 'i';
244
+	}
245 245
 
246 246
 }
247 247
\ No newline at end of file
Please login to merge, or discard this patch.
src/QueryBuild.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -17,71 +17,71 @@
 block discarded – undo
17 17
 class QueryBuild
18 18
 {
19 19
 
20
-    /**
21
-     * @var integer
22
-     */
23
-    private $queryType;
20
+	/**
21
+	 * @var integer
22
+	 */
23
+	private $queryType;
24 24
 
25
-    /**
26
-     * QueryBuild constructor.
27
-     * @param $queryType
28
-     */
29
-    protected function __construct($queryType)
30
-    {
31
-        $this->queryType = $queryType;
32
-    }
25
+	/**
26
+	 * QueryBuild constructor.
27
+	 * @param $queryType
28
+	 */
29
+	protected function __construct($queryType)
30
+	{
31
+		$this->queryType = $queryType;
32
+	}
33 33
 
34
-    /**
35
-     * @param $table
36
-     * @return QuerySelect
37
-     */
38
-    public static function select($table)
39
-    {
40
-        return new QuerySelect(new QueryBuild(0), $table);
41
-    }
34
+	/**
35
+	 * @param $table
36
+	 * @return QuerySelect
37
+	 */
38
+	public static function select($table)
39
+	{
40
+		return new QuerySelect(new QueryBuild(0), $table);
41
+	}
42 42
 
43
-    /**
44
-     * @param $table
45
-     * @return QueryUpdate
46
-     */
47
-    public static function update($table)
48
-    {
49
-        return new QueryUpdate(new QueryBuild(0), $table);
50
-    }
43
+	/**
44
+	 * @param $table
45
+	 * @return QueryUpdate
46
+	 */
47
+	public static function update($table)
48
+	{
49
+		return new QueryUpdate(new QueryBuild(0), $table);
50
+	}
51 51
 
52
-    /**
53
-     * @param $table
54
-     * @return QueryInsert
55
-     */
56
-    public static function insert($table)
57
-    {
58
-        return new QueryInsert(new QueryBuild(0), $table);
59
-    }
52
+	/**
53
+	 * @param $table
54
+	 * @return QueryInsert
55
+	 */
56
+	public static function insert($table)
57
+	{
58
+		return new QueryInsert(new QueryBuild(0), $table);
59
+	}
60 60
 
61
-    /**
62
-     * @param $table
63
-     * @return QueryDelete
64
-     */
65
-    public static function delete($table)
66
-    {
67
-        return new QueryDelete(new QueryBuild(0), $table);
68
-    }
61
+	/**
62
+	 * @param $table
63
+	 * @return QueryDelete
64
+	 */
65
+	public static function delete($table)
66
+	{
67
+		return new QueryDelete(new QueryBuild(0), $table);
68
+	}
69 69
 
70
-    /**
71
-     * @param $query
72
-     * @return QueryCustom
73
-     */
74
-    public static function query($query)
75
-    {
76
-        return new QueryCustom(new QueryBuild(1), $query);
77
-    }
70
+	/**
71
+	 * @param $query
72
+	 * @return QueryCustom
73
+	 */
74
+	public static function query($query)
75
+	{
76
+		return new QueryCustom(new QueryBuild(1), $query);
77
+	}
78 78
 
79
-    /**
80
-     * @return integer
81
-     */
82
-    public function getType()
83
-    {
84
-        return $this->queryType;
85
-    }
79
+	/**
80
+	 * @return integer
81
+	 */
82
+	public function getType()
83
+	{
84
+		return $this->queryType;
85
+	}
86 86
 
87 87
 }
88 88
\ No newline at end of file
Please login to merge, or discard this patch.
src/Statements/QuerySelect.php 1 patch
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -29,179 +29,179 @@
 block discarded – undo
29 29
 class QuerySelect extends QueryStatement implements QueryStatementInterface
30 30
 {
31 31
 
32
-    use SelectFields, Limit, Distinct, Where, Having, WhereAndHavingBuilder, Replacement, OrderBy, GroupBy, Join, DefaultPriority, HighPriority, Utilities;
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    protected $statement = self::QUERY_STATEMENT_SELECT;
38
-
39
-
40
-    /**
41
-     * QuerySelect constructor.
42
-     * @param QueryBuild $queryBuild
43
-     * @param string|QueryStatement $table
44
-     */
45
-    public function __construct(QueryBuild $queryBuild, $table)
46
-    {
47
-        parent::__construct($queryBuild, $table);
48
-
49
-        if (is_a($table, QuerySelect::class)) {
50
-
51
-            /**
52
-             * @var QuerySelect $table
53
-             */
54
-            $tableName = '( ' . $table->getSyntax() . ' )';
55
-            $this->queryStructure->setElement(QueryStructure::TABLE, $tableName);
56
-
57
-            $tableSelectParams = $table->getBindParams();
58
-            foreach ($tableSelectParams as $key => $value)
59
-                $this->queryStructure->setParams($key, $value);
60
-
61
-        }
62
-    }
63
-
64
-    /**
65
-     * @return $this
66
-     */
67
-    public function first()
68
-    {
69
-        $this->queryStructure->setElement(QueryStructure::FIRST, 1);
70
-
71
-        return $this;
72
-    }
73
-
74
-    /**
75
-     * @return $this
76
-     */
77
-    public function count()
78
-    {
79
-        $this->queryStructure->setElement(QueryStructure::COUNT, 1);
80
-
81
-        return $this;
82
-    }
83
-
84
-    /**
85
-     * @param $column
86
-     * @return $this
87
-     */
88
-    public function column($column)
89
-    {
90
-        $column = QueryHelper::clearMultipleSpaces($column);
91
-        $this->queryStructure->setElement(QueryStructure::COLUMN, $column);
92
-
93
-        return $this;
94
-    }
95
-
96
-
97
-    /**
98
-     * @param bool|int $replacement
99
-     * @return mixed|string
100
-     */
101
-    public function getSyntax($replacement = self::REPLACEMENT_NONE)
102
-    {
103
-
104
-        if ($this->queryStructure->getElement(QueryStructure::COUNT)) {
105
-            $this->queryStructure->setElement(QueryStructure::FIELDS, 'COUNT(*)');
106
-            $this->queryStructure->setElement(QueryStructure::LIMIT, 1);
107
-            $this->queryStructure->setElement(QueryStructure::DISTINCT, 0); //???
108
-        }
109
-
110
-        if ($this->queryStructure->getElement(QueryStructure::FIRST))
111
-            $this->queryStructure->setElement(QueryStructure::LIMIT, 1);
112
-
113
-        $syntax = array();
114
-
115
-        /**
116
-         *  Explain
117
-         */
118
-        $syntax[] = $this->getExplainSyntax();
119
-
120
-        /**
121
-         * SELECT statement
122
-         */
123
-        $syntax[] = $this->statement;
124
-
125
-        /**
126
-         * PRIORITY
127
-         */
128
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
129
-
130
-        /**
131
-         * DISTINCT clause
132
-         */
133
-        $syntax[] = $this->getDistinctSyntax();
134
-
135
-        /**
136
-         * FIELDS
137
-         */
138
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::FIELDS);
139
-
140
-        /**
141
-         * FROM table or queryStructure
142
-         */
143
-        $syntax[] = 'FROM ' . $this->queryStructure->getElement(QueryStructure::TABLE);
144
-
145
-        /**
146
-         * JOIN CLAUSES
147
-         */
148
-        $syntax[] = $this->getJoinSyntax();
149
-
150
-        /**
151
-         * WHERE clause
152
-         */
153
-        $syntax[] = $this->getWhereSyntax();
154
-
155
-        /**
156
-         * GROUP BY clause
157
-         */
158
-        $syntax[] = $this->getGroupBySyntax();
159
-
160
-        /**
161
-         * HAVING clause
162
-         */
163
-        $syntax[] = $this->getHavingSyntax();
164
-
165
-        /**
166
-         * ORDER BY clause
167
-         */
168
-        $syntax[] = $this->getOrderBySyntax();
169
-
170
-        /**
171
-         * LIMIT clause
172
-         */
173
-        $syntax[] = $this->getLimitSyntax();
174
-
175
-        $syntax = implode(' ', $syntax);
176
-
177
-        return $this->getSyntaxReplace($syntax, $replacement);
178
-
179
-    }
180
-
181
-
182
-    /**
183
-     * @return array|int|mixed|null|string
184
-     */
185
-    public function execute()
186
-    {
187
-
188
-        switch (true) {
189
-            case $this->queryStructure->getElement(QueryStructure::COUNT):
190
-                return DbService::getInstance()->single($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
191
-                break;
192
-            case $this->queryStructure->getElement(QueryStructure::FIRST):
193
-                if ($this->queryStructure->getElement(QueryStructure::COLUMN))
194
-                    return DbService::getInstance()->single($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
195
-
196
-                return DbService::getInstance()->row($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
197
-                break;
198
-            case $this->queryStructure->getElement(QueryStructure::COLUMN):
199
-                return DbService::getInstance()->column($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
200
-                break;
201
-            default:
202
-                return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
203
-                break;
204
-        }
205
-    }
32
+	use SelectFields, Limit, Distinct, Where, Having, WhereAndHavingBuilder, Replacement, OrderBy, GroupBy, Join, DefaultPriority, HighPriority, Utilities;
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	protected $statement = self::QUERY_STATEMENT_SELECT;
38
+
39
+
40
+	/**
41
+	 * QuerySelect constructor.
42
+	 * @param QueryBuild $queryBuild
43
+	 * @param string|QueryStatement $table
44
+	 */
45
+	public function __construct(QueryBuild $queryBuild, $table)
46
+	{
47
+		parent::__construct($queryBuild, $table);
48
+
49
+		if (is_a($table, QuerySelect::class)) {
50
+
51
+			/**
52
+			 * @var QuerySelect $table
53
+			 */
54
+			$tableName = '( ' . $table->getSyntax() . ' )';
55
+			$this->queryStructure->setElement(QueryStructure::TABLE, $tableName);
56
+
57
+			$tableSelectParams = $table->getBindParams();
58
+			foreach ($tableSelectParams as $key => $value)
59
+				$this->queryStructure->setParams($key, $value);
60
+
61
+		}
62
+	}
63
+
64
+	/**
65
+	 * @return $this
66
+	 */
67
+	public function first()
68
+	{
69
+		$this->queryStructure->setElement(QueryStructure::FIRST, 1);
70
+
71
+		return $this;
72
+	}
73
+
74
+	/**
75
+	 * @return $this
76
+	 */
77
+	public function count()
78
+	{
79
+		$this->queryStructure->setElement(QueryStructure::COUNT, 1);
80
+
81
+		return $this;
82
+	}
83
+
84
+	/**
85
+	 * @param $column
86
+	 * @return $this
87
+	 */
88
+	public function column($column)
89
+	{
90
+		$column = QueryHelper::clearMultipleSpaces($column);
91
+		$this->queryStructure->setElement(QueryStructure::COLUMN, $column);
92
+
93
+		return $this;
94
+	}
95
+
96
+
97
+	/**
98
+	 * @param bool|int $replacement
99
+	 * @return mixed|string
100
+	 */
101
+	public function getSyntax($replacement = self::REPLACEMENT_NONE)
102
+	{
103
+
104
+		if ($this->queryStructure->getElement(QueryStructure::COUNT)) {
105
+			$this->queryStructure->setElement(QueryStructure::FIELDS, 'COUNT(*)');
106
+			$this->queryStructure->setElement(QueryStructure::LIMIT, 1);
107
+			$this->queryStructure->setElement(QueryStructure::DISTINCT, 0); //???
108
+		}
109
+
110
+		if ($this->queryStructure->getElement(QueryStructure::FIRST))
111
+			$this->queryStructure->setElement(QueryStructure::LIMIT, 1);
112
+
113
+		$syntax = array();
114
+
115
+		/**
116
+		 *  Explain
117
+		 */
118
+		$syntax[] = $this->getExplainSyntax();
119
+
120
+		/**
121
+		 * SELECT statement
122
+		 */
123
+		$syntax[] = $this->statement;
124
+
125
+		/**
126
+		 * PRIORITY
127
+		 */
128
+		$syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
129
+
130
+		/**
131
+		 * DISTINCT clause
132
+		 */
133
+		$syntax[] = $this->getDistinctSyntax();
134
+
135
+		/**
136
+		 * FIELDS
137
+		 */
138
+		$syntax[] = $this->queryStructure->getElement(QueryStructure::FIELDS);
139
+
140
+		/**
141
+		 * FROM table or queryStructure
142
+		 */
143
+		$syntax[] = 'FROM ' . $this->queryStructure->getElement(QueryStructure::TABLE);
144
+
145
+		/**
146
+		 * JOIN CLAUSES
147
+		 */
148
+		$syntax[] = $this->getJoinSyntax();
149
+
150
+		/**
151
+		 * WHERE clause
152
+		 */
153
+		$syntax[] = $this->getWhereSyntax();
154
+
155
+		/**
156
+		 * GROUP BY clause
157
+		 */
158
+		$syntax[] = $this->getGroupBySyntax();
159
+
160
+		/**
161
+		 * HAVING clause
162
+		 */
163
+		$syntax[] = $this->getHavingSyntax();
164
+
165
+		/**
166
+		 * ORDER BY clause
167
+		 */
168
+		$syntax[] = $this->getOrderBySyntax();
169
+
170
+		/**
171
+		 * LIMIT clause
172
+		 */
173
+		$syntax[] = $this->getLimitSyntax();
174
+
175
+		$syntax = implode(' ', $syntax);
176
+
177
+		return $this->getSyntaxReplace($syntax, $replacement);
178
+
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return array|int|mixed|null|string
184
+	 */
185
+	public function execute()
186
+	{
187
+
188
+		switch (true) {
189
+			case $this->queryStructure->getElement(QueryStructure::COUNT):
190
+				return DbService::getInstance()->single($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
191
+				break;
192
+			case $this->queryStructure->getElement(QueryStructure::FIRST):
193
+				if ($this->queryStructure->getElement(QueryStructure::COLUMN))
194
+					return DbService::getInstance()->single($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
195
+
196
+				return DbService::getInstance()->row($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
197
+				break;
198
+			case $this->queryStructure->getElement(QueryStructure::COLUMN):
199
+				return DbService::getInstance()->column($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
200
+				break;
201
+			default:
202
+				return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
203
+				break;
204
+		}
205
+	}
206 206
 
207 207
 }
208 208
\ No newline at end of file
Please login to merge, or discard this patch.
src/Statements/QueryCustom.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -17,81 +17,81 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    protected $statement = QueryStatement::QUERY_STATEMENT_CUSTOM;
24
-
25
-    /**
26
-     * @var QueryBuild
27
-     */
28
-    protected $queryBuild;
29
-
30
-    /**
31
-     * @var QueryStructure
32
-     */
33
-    protected $queryStructure;
34
-
35
-    /**
36
-     * @var array
37
-     */
38
-    protected $usedInstanceIds = [];
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    protected $tablePrefix;
44
-
45
-
46
-    /**
47
-     * QueryCustom constructor.
48
-     * @param QueryBuild $queryBuild
49
-     * @param string $query
50
-     */
51
-    public function __construct(QueryBuild $queryBuild, $query = '')
52
-    {
53
-        $this->queryBuild = $queryBuild;
54
-        $this->queryStructure = new QueryStructure();
55
-        $this->queryStructure->setElement(QueryStructure::STATEMENT, $this->statement);
56
-        $this->queryStructure->setElement(QueryStructure::QUERY_TYPE, $this->queryBuild->getType());
57
-        $this->queryStructure->setElement(QueryStructure::QUERY_STRING, $query);
58
-    }
59
-
60
-    /**
61
-     * @param array $params
62
-     * @return $this
63
-     */
64
-    public function withBindParams(array $params = [])
65
-    {
66
-        $this->queryStructure->replaceElement(QueryStructure::BIND_PARAMS, $params);
67
-
68
-        return $this;
69
-    }
70
-
71
-    /**
72
-     * @param bool|int $replacement
73
-     * @return mixed
74
-     */
75
-    public function getSyntax($replacement = self::REPLACEMENT_NONE)
76
-    {
77
-        return $this->queryStructure->getElement(QueryStructure::QUERY_STRING);
78
-    }
79
-
80
-    /**
81
-     * @return array
82
-     */
83
-    public function getBindParams()
84
-    {
85
-        return $this->queryStructure->getElement(QueryStructure::BIND_PARAMS);
86
-    }
87
-
88
-    /**
89
-     * @return array|int|null
90
-     */
91
-    public function execute()
92
-    {
93
-        return DbService::getInstance()->query($this->queryStructure->getElement(QueryStructure::QUERY_STRING), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
94
-    }
20
+	/**
21
+	 * @var string
22
+	 */
23
+	protected $statement = QueryStatement::QUERY_STATEMENT_CUSTOM;
24
+
25
+	/**
26
+	 * @var QueryBuild
27
+	 */
28
+	protected $queryBuild;
29
+
30
+	/**
31
+	 * @var QueryStructure
32
+	 */
33
+	protected $queryStructure;
34
+
35
+	/**
36
+	 * @var array
37
+	 */
38
+	protected $usedInstanceIds = [];
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	protected $tablePrefix;
44
+
45
+
46
+	/**
47
+	 * QueryCustom constructor.
48
+	 * @param QueryBuild $queryBuild
49
+	 * @param string $query
50
+	 */
51
+	public function __construct(QueryBuild $queryBuild, $query = '')
52
+	{
53
+		$this->queryBuild = $queryBuild;
54
+		$this->queryStructure = new QueryStructure();
55
+		$this->queryStructure->setElement(QueryStructure::STATEMENT, $this->statement);
56
+		$this->queryStructure->setElement(QueryStructure::QUERY_TYPE, $this->queryBuild->getType());
57
+		$this->queryStructure->setElement(QueryStructure::QUERY_STRING, $query);
58
+	}
59
+
60
+	/**
61
+	 * @param array $params
62
+	 * @return $this
63
+	 */
64
+	public function withBindParams(array $params = [])
65
+	{
66
+		$this->queryStructure->replaceElement(QueryStructure::BIND_PARAMS, $params);
67
+
68
+		return $this;
69
+	}
70
+
71
+	/**
72
+	 * @param bool|int $replacement
73
+	 * @return mixed
74
+	 */
75
+	public function getSyntax($replacement = self::REPLACEMENT_NONE)
76
+	{
77
+		return $this->queryStructure->getElement(QueryStructure::QUERY_STRING);
78
+	}
79
+
80
+	/**
81
+	 * @return array
82
+	 */
83
+	public function getBindParams()
84
+	{
85
+		return $this->queryStructure->getElement(QueryStructure::BIND_PARAMS);
86
+	}
87
+
88
+	/**
89
+	 * @return array|int|null
90
+	 */
91
+	public function execute()
92
+	{
93
+		return DbService::getInstance()->query($this->queryStructure->getElement(QueryStructure::QUERY_STRING), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
94
+	}
95 95
 
96 96
 
97 97
 }
98 98
\ No newline at end of file
Please login to merge, or discard this patch.
src/Statements/QueryUpdate.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -26,89 +26,89 @@
 block discarded – undo
26 26
 class QueryUpdate extends QueryStatement implements QueryStatementInterface
27 27
 {
28 28
 
29
-    use Limit, Where, WhereAndHavingBuilder, Replacement, OrderBy, SetFields, Ignore, DefaultPriority, LowPriority, Utilities;
30
-
31
-    /**
32
-     * @var string
33
-     */
34
-    protected $statement = self::QUERY_STATEMENT_UPDATE;
35
-
36
-
37
-    /**
38
-     * QueryUpdate constructor.
39
-     * @param QueryBuild $queryBuild
40
-     * @param string $table
41
-     */
42
-    public function __construct(QueryBuild $queryBuild, $table = null)
43
-    {
44
-        parent::__construct($queryBuild, $table);
45
-    }
46
-
47
-    public function getSyntax($replacement = self::REPLACEMENT_NONE)
48
-    {
49
-
50
-        $syntax = array();
51
-
52
-        /**
53
-         *  Explain
54
-         */
55
-        $syntax[] = $this->getExplainSyntax();
56
-
57
-        /**
58
-         * UPDATE statement
59
-         */
60
-        $syntax[] = $this->statement;
61
-
62
-        /**
63
-         * PRIORITY
64
-         */
65
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
66
-
67
-        /**
68
-         * IGNORE clause
69
-         */
70
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::IGNORE) ? 'IGNORE' : '';
71
-
72
-        /**
73
-         * TABLE update
74
-         */
75
-        $syntax[] = $this->queryStructure->getElement(QueryStructure::TABLE);
76
-
77
-        /**
78
-         * FIELDS update
79
-         */
80
-        $syntax[] = $this->getSettingFieldsSyntax();
81
-
82
-        /**
83
-         * WHERE clause
84
-         */
85
-        $syntax[] = $this->getWhereSyntax();
86
-
87
-        /**
88
-         * ORDER BY clause
89
-         */
90
-        $syntax[] = $this->getOrderBySyntax();
91
-
92
-        /**
93
-         * LIMIT clause
94
-         */
95
-        $syntax[] = $this->getLimitSyntax();
96
-
97
-        $syntax = implode(' ', $syntax);
98
-
99
-        return $this->getSyntaxReplace($syntax, $replacement);
100
-
101
-    }
102
-
103
-    /**
104
-     * @return array|int|null
105
-     * @throws QueryException
106
-     */
107
-    public function execute()
108
-    {
109
-        if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE)))
110
-            throw new QueryException('Where clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER);
111
-
112
-        return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
113
-    }
29
+	use Limit, Where, WhereAndHavingBuilder, Replacement, OrderBy, SetFields, Ignore, DefaultPriority, LowPriority, Utilities;
30
+
31
+	/**
32
+	 * @var string
33
+	 */
34
+	protected $statement = self::QUERY_STATEMENT_UPDATE;
35
+
36
+
37
+	/**
38
+	 * QueryUpdate constructor.
39
+	 * @param QueryBuild $queryBuild
40
+	 * @param string $table
41
+	 */
42
+	public function __construct(QueryBuild $queryBuild, $table = null)
43
+	{
44
+		parent::__construct($queryBuild, $table);
45
+	}
46
+
47
+	public function getSyntax($replacement = self::REPLACEMENT_NONE)
48
+	{
49
+
50
+		$syntax = array();
51
+
52
+		/**
53
+		 *  Explain
54
+		 */
55
+		$syntax[] = $this->getExplainSyntax();
56
+
57
+		/**
58
+		 * UPDATE statement
59
+		 */
60
+		$syntax[] = $this->statement;
61
+
62
+		/**
63
+		 * PRIORITY
64
+		 */
65
+		$syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY);
66
+
67
+		/**
68
+		 * IGNORE clause
69
+		 */
70
+		$syntax[] = $this->queryStructure->getElement(QueryStructure::IGNORE) ? 'IGNORE' : '';
71
+
72
+		/**
73
+		 * TABLE update
74
+		 */
75
+		$syntax[] = $this->queryStructure->getElement(QueryStructure::TABLE);
76
+
77
+		/**
78
+		 * FIELDS update
79
+		 */
80
+		$syntax[] = $this->getSettingFieldsSyntax();
81
+
82
+		/**
83
+		 * WHERE clause
84
+		 */
85
+		$syntax[] = $this->getWhereSyntax();
86
+
87
+		/**
88
+		 * ORDER BY clause
89
+		 */
90
+		$syntax[] = $this->getOrderBySyntax();
91
+
92
+		/**
93
+		 * LIMIT clause
94
+		 */
95
+		$syntax[] = $this->getLimitSyntax();
96
+
97
+		$syntax = implode(' ', $syntax);
98
+
99
+		return $this->getSyntaxReplace($syntax, $replacement);
100
+
101
+	}
102
+
103
+	/**
104
+	 * @return array|int|null
105
+	 * @throws QueryException
106
+	 */
107
+	public function execute()
108
+	{
109
+		if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE)))
110
+			throw new QueryException('Where clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER);
111
+
112
+		return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS));
113
+	}
114 114
 }
115 115
\ No newline at end of file
Please login to merge, or discard this patch.