@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | * @param string $string |
16 | 16 | * @return mixed|string |
17 | 17 | */ |
18 | - public static function clearMultipleSpaces( $string = '' ) |
|
18 | + public static function clearMultipleSpaces($string = '') |
|
19 | 19 | { |
20 | - $string = preg_replace( '/\s+/', ' ', $string ); |
|
21 | - $string = trim( $string ); |
|
20 | + $string = preg_replace('/\s+/', ' ', $string); |
|
21 | + $string = trim($string); |
|
22 | 22 | |
23 | 23 | return $string; |
24 | 24 | } |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | * @param $val |
28 | 28 | * @return bool |
29 | 29 | */ |
30 | - public static function isInteger( $val ) |
|
30 | + public static function isInteger($val) |
|
31 | 31 | { |
32 | - $val = trim( $val ); |
|
32 | + $val = trim($val); |
|
33 | 33 | |
34 | - return is_numeric( $val ) && floor( $val ) == $val; |
|
34 | + return is_numeric($val) && floor($val) == $val; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -39,34 +39,34 @@ discard block |
||
39 | 39 | * @return bool |
40 | 40 | * @i |
41 | 41 | */ |
42 | - public static function isDecimal( $val ) |
|
42 | + public static function isDecimal($val) |
|
43 | 43 | { |
44 | - $val = trim( $val ); |
|
44 | + $val = trim($val); |
|
45 | 45 | |
46 | - return is_numeric( $val ) && floor( $val ) != $val; |
|
46 | + return is_numeric($val) && floor($val) != $val; |
|
47 | 47 | } |
48 | 48 | |
49 | - public static function isValidOrderBy( $order_by_parameter ) |
|
49 | + public static function isValidOrderBy($order_by_parameter) |
|
50 | 50 | { |
51 | 51 | |
52 | - $columns = array( 'first_name', 'last_name', 'zip', 'created_at' ); |
|
52 | + $columns = array('first_name', 'last_name', 'zip', 'created_at'); |
|
53 | 53 | |
54 | - $parts = preg_split( "/[\s,]+/", $order_by_parameter ); |
|
54 | + $parts = preg_split("/[\s,]+/", $order_by_parameter); |
|
55 | 55 | |
56 | - foreach ( $parts as $part ) { |
|
57 | - $subparts = preg_split( "/\s+/", $part ); |
|
56 | + foreach ($parts as $part) { |
|
57 | + $subparts = preg_split("/\s+/", $part); |
|
58 | 58 | |
59 | - if ( count( $subparts ) < 0 || count( $subparts ) > 2 ) { |
|
59 | + if (count($subparts) < 0 || count($subparts) > 2) { |
|
60 | 60 | // Too many or too few parts. |
61 | 61 | return false; |
62 | 62 | } |
63 | 63 | |
64 | - if ( !in_array( $subparts[0], $columns ) ) { |
|
64 | + if (!in_array($subparts[0], $columns)) { |
|
65 | 65 | // Column name is invalid. |
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - if ( count( $subparts ) == 2 && !in_array( strtoupper( $subparts[1] ), array( 'ASC', 'DESC' ) ) ) { |
|
69 | + if (count($subparts) == 2 && !in_array(strtoupper($subparts[1]), array('ASC', 'DESC'))) { |
|
70 | 70 | // ASC or DESC is invalid |
71 | 71 | return false; |
72 | 72 | } |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | * @param string $delimiter |
82 | 82 | * @return array |
83 | 83 | */ |
84 | - public static function explode( $string, $delimiter = ',' ) |
|
84 | + public static function explode($string, $delimiter = ',') |
|
85 | 85 | { |
86 | - $brutArray = explode( $delimiter, $string ); |
|
86 | + $brutArray = explode($delimiter, $string); |
|
87 | 87 | $newArray = array(); |
88 | - foreach ( $brutArray as $value ) { |
|
89 | - $value = trim( $value ); |
|
90 | - if ( '' !== $value ) $newArray[] = $value; |
|
88 | + foreach ($brutArray as $value) { |
|
89 | + $value = trim($value); |
|
90 | + if ('' !== $value) $newArray[] = $value; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return $newArray; |
94 | 94 | } |
95 | 95 | |
96 | - public static function alphaNum( $string ) |
|
96 | + public static function alphaNum($string) |
|
97 | 97 | { |
98 | - $string = preg_replace( "/[^a-zA-Z0-9 _,]+/", "", $string ); |
|
98 | + $string = preg_replace("/[^a-zA-Z0-9 _,]+/", "", $string); |
|
99 | 99 | |
100 | - return self::clearMultipleSpaces( $string ); |
|
100 | + return self::clearMultipleSpaces($string); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | * @param string $delimiter |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - public static function implode( array $array, $delimiter = ',' ) |
|
108 | + public static function implode(array $array, $delimiter = ',') |
|
109 | 109 | { |
110 | - $string = implode( $delimiter, $array ); |
|
111 | - $string = trim( $string ); |
|
112 | - $string = trim( $string, trim( $delimiter ) ); |
|
113 | - $string = trim( $string ); |
|
110 | + $string = implode($delimiter, $array); |
|
111 | + $string = trim($string); |
|
112 | + $string = trim($string, trim($delimiter)); |
|
113 | + $string = trim($string); |
|
114 | 114 | |
115 | 115 | return $string; |
116 | 116 | } |
@@ -119,36 +119,36 @@ discard block |
||
119 | 119 | * @param $string |
120 | 120 | * @return mixed|string |
121 | 121 | */ |
122 | - public static function clearQuotes( $string ) |
|
122 | + public static function clearQuotes($string) |
|
123 | 123 | { |
124 | - $search = array( '"', "'" ); |
|
124 | + $search = array('"', "'"); |
|
125 | 125 | $replace = ''; |
126 | - $string = str_replace( $search, $replace, $string ); |
|
126 | + $string = str_replace($search, $replace, $string); |
|
127 | 127 | |
128 | - return self::clearMultipleSpaces( $string ); |
|
128 | + return self::clearMultipleSpaces($string); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | 132 | * @param int $length |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public static function random( $length = 5 ) |
|
135 | + public static function random($length = 5) |
|
136 | 136 | { |
137 | 137 | $characters = 'abcdefghijklmnopqrstuvwxyz'; |
138 | - $charactersLength = strlen( $characters ); |
|
138 | + $charactersLength = strlen($characters); |
|
139 | 139 | $randomString = ''; |
140 | - for ( $i = 0; $i < $length; $i++ ) |
|
141 | - $randomString .= $characters[ rand( 0, $charactersLength - 1 ) ]; |
|
140 | + for ($i = 0; $i < $length; $i++) |
|
141 | + $randomString .= $characters[rand(0, $charactersLength - 1)]; |
|
142 | 142 | |
143 | - return str_shuffle( $randomString ); |
|
143 | + return str_shuffle($randomString); |
|
144 | 144 | } |
145 | 145 | |
146 | - public static function limitString( $rowCount, $offset = null ) |
|
146 | + public static function limitString($rowCount, $offset = null) |
|
147 | 147 | { |
148 | - $rowCount = intval( $rowCount ); |
|
149 | - if ( is_null( $offset ) ) |
|
148 | + $rowCount = intval($rowCount); |
|
149 | + if (is_null($offset)) |
|
150 | 150 | return $rowCount; |
151 | - $offset = intval( $offset ); |
|
151 | + $offset = intval($offset); |
|
152 | 152 | |
153 | 153 | return "$offset, $rowCount"; |
154 | 154 | } |
@@ -87,7 +87,9 @@ discard block |
||
87 | 87 | $newArray = array(); |
88 | 88 | foreach ( $brutArray as $value ) { |
89 | 89 | $value = trim( $value ); |
90 | - if ( '' !== $value ) $newArray[] = $value; |
|
90 | + if ( '' !== $value ) { |
|
91 | + $newArray[] = $value; |
|
92 | + } |
|
91 | 93 | } |
92 | 94 | |
93 | 95 | return $newArray; |
@@ -137,8 +139,9 @@ discard block |
||
137 | 139 | $characters = 'abcdefghijklmnopqrstuvwxyz'; |
138 | 140 | $charactersLength = strlen( $characters ); |
139 | 141 | $randomString = ''; |
140 | - for ( $i = 0; $i < $length; $i++ ) |
|
141 | - $randomString .= $characters[ rand( 0, $charactersLength - 1 ) ]; |
|
142 | + for ( $i = 0; $i < $length; $i++ ) { |
|
143 | + $randomString .= $characters[ rand( 0, $charactersLength - 1 ) ]; |
|
144 | + } |
|
142 | 145 | |
143 | 146 | return str_shuffle( $randomString ); |
144 | 147 | } |
@@ -146,8 +149,9 @@ discard block |
||
146 | 149 | public static function limitString( $rowCount, $offset = null ) |
147 | 150 | { |
148 | 151 | $rowCount = intval( $rowCount ); |
149 | - if ( is_null( $offset ) ) |
|
150 | - return $rowCount; |
|
152 | + if ( is_null( $offset ) ) { |
|
153 | + return $rowCount; |
|
154 | + } |
|
151 | 155 | $offset = intval( $offset ); |
152 | 156 | |
153 | 157 | return "$offset, $rowCount"; |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | { |
86 | 86 | $this->syntaxEL = $this->init(); |
87 | 87 | |
88 | - foreach ( $this->syntaxEL as $name => $value ) |
|
89 | - $this->typeEL[ $name ] = gettype( $value ); |
|
88 | + foreach ($this->syntaxEL as $name => $value) |
|
89 | + $this->typeEL[$name] = gettype($value); |
|
90 | 90 | |
91 | 91 | } |
92 | 92 | |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | |
129 | 129 | private function makeStatementInstance() |
130 | 130 | { |
131 | - $instance = QueryHelper::random( 5 ); |
|
132 | - while ( in_array( $instance, self::$usedInstanceIds ) ) { |
|
133 | - $instance = QueryHelper::random( 7 ); |
|
131 | + $instance = QueryHelper::random(5); |
|
132 | + while (in_array($instance, self::$usedInstanceIds)) { |
|
133 | + $instance = QueryHelper::random(7); |
|
134 | 134 | } |
135 | 135 | self::$usedInstanceIds[] = $instance; |
136 | 136 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | /** |
159 | 159 | * @param $elements |
160 | 160 | */ |
161 | - public function setAllElements( $elements ) |
|
161 | + public function setAllElements($elements) |
|
162 | 162 | { |
163 | 163 | $this->syntaxEL = $elements; |
164 | 164 | } |
@@ -170,18 +170,18 @@ discard block |
||
170 | 170 | * @return bool |
171 | 171 | * @throws QueryException |
172 | 172 | */ |
173 | - public function setElement( $name, $value ) |
|
173 | + public function setElement($name, $value) |
|
174 | 174 | { |
175 | - if ( !array_key_exists( $name, $this->syntaxEL ) ) |
|
176 | - throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
175 | + if (!array_key_exists($name, $this->syntaxEL)) |
|
176 | + throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND); |
|
177 | 177 | |
178 | - if ( $name == self::TABLE && is_a( $value, QueryStatement::class ) ) |
|
178 | + if ($name == self::TABLE && is_a($value, QueryStatement::class)) |
|
179 | 179 | return true; |
180 | 180 | |
181 | - if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY ) |
|
182 | - $this->syntaxEL[ $name ][] = $value; |
|
181 | + if ($this->typeEL[$name] === self::ELEMENT_TYPE_ARRAY) |
|
182 | + $this->syntaxEL[$name][] = $value; |
|
183 | 183 | else |
184 | - $this->syntaxEL[ $name ] = $value; |
|
184 | + $this->syntaxEL[$name] = $value; |
|
185 | 185 | |
186 | 186 | return true; |
187 | 187 | } |
@@ -192,12 +192,12 @@ discard block |
||
192 | 192 | * @param $elementValue |
193 | 193 | * @throws QueryException |
194 | 194 | */ |
195 | - public function replaceElement( $elementName, $elementValue ) |
|
195 | + public function replaceElement($elementName, $elementValue) |
|
196 | 196 | { |
197 | - if ( !array_key_exists( $elementName, $this->syntaxEL ) ) |
|
198 | - throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
197 | + if (!array_key_exists($elementName, $this->syntaxEL)) |
|
198 | + throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND); |
|
199 | 199 | |
200 | - $this->syntaxEL[ $elementName ] = $elementValue; |
|
200 | + $this->syntaxEL[$elementName] = $elementValue; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | |
@@ -205,9 +205,9 @@ discard block |
||
205 | 205 | * @param string $name |
206 | 206 | * @return mixed |
207 | 207 | */ |
208 | - public function getElement( $name ) |
|
208 | + public function getElement($name) |
|
209 | 209 | { |
210 | - return $this->syntaxEL[ $name ]; |
|
210 | + return $this->syntaxEL[$name]; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | * @param $name |
216 | 216 | * @param $value |
217 | 217 | */ |
218 | - public function setParams( $name, $value ) |
|
218 | + public function setParams($name, $value) |
|
219 | 219 | { |
220 | - $this->syntaxEL[ QueryStructure::BIND_PARAMS ][ $name ] = $value; |
|
220 | + $this->syntaxEL[QueryStructure::BIND_PARAMS][$name] = $value; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | * @param $value |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public function bindParam( $name, $value ) |
|
229 | + public function bindParam($name, $value) |
|
230 | 230 | { |
231 | - $pdoName = $this->index( $name ); |
|
232 | - $this->syntaxEL[ QueryStructure::BIND_PARAMS ][ $pdoName ] = $value; |
|
231 | + $pdoName = $this->index($name); |
|
232 | + $this->syntaxEL[QueryStructure::BIND_PARAMS][$pdoName] = $value; |
|
233 | 233 | |
234 | 234 | return ':' . $pdoName; |
235 | 235 | } |
@@ -241,27 +241,27 @@ discard block |
||
241 | 241 | * @param string $search |
242 | 242 | * @return string |
243 | 243 | */ |
244 | - public function bindParamsExpression( $expression, array $params = [], $search = '?' ) |
|
244 | + public function bindParamsExpression($expression, array $params = [], $search = '?') |
|
245 | 245 | { |
246 | - if ( !count( $params ) ) |
|
246 | + if (!count($params)) |
|
247 | 247 | return $expression; |
248 | 248 | |
249 | - if ( strpos( $expression, $search ) === false ) |
|
249 | + if (strpos($expression, $search) === false) |
|
250 | 250 | return $expression; |
251 | 251 | |
252 | - $params = array_slice( $params, 0, substr_count( $expression, $search ) ); |
|
252 | + $params = array_slice($params, 0, substr_count($expression, $search)); |
|
253 | 253 | |
254 | 254 | $i = 0; |
255 | 255 | $arrayReturn = []; |
256 | - $expressionToArray = explode( $search, $expression ); |
|
256 | + $expressionToArray = explode($search, $expression); |
|
257 | 257 | |
258 | - foreach ( $expressionToArray as $sub ) { |
|
258 | + foreach ($expressionToArray as $sub) { |
|
259 | 259 | $arrayReturn[] = $sub; |
260 | - $arrayReturn[] = array_key_exists( $i, $params ) ? $this->bindParam( 'exp', $params[ $i ] ) : ''; |
|
260 | + $arrayReturn[] = array_key_exists($i, $params) ? $this->bindParam('exp', $params[$i]) : ''; |
|
261 | 261 | $i++; |
262 | 262 | } |
263 | 263 | |
264 | - return implode( '', $arrayReturn ); |
|
264 | + return implode('', $arrayReturn); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | |
@@ -269,9 +269,9 @@ discard block |
||
269 | 269 | * @param string $fieldName |
270 | 270 | * @return string |
271 | 271 | */ |
272 | - public function index( $fieldName = '' ) |
|
272 | + public function index($fieldName = '') |
|
273 | 273 | { |
274 | - return trim( $fieldName ) . '_' . $this->syntaxEL[ self::INSTANCE ] . '_' . ++$this->counter . 'i'; |
|
274 | + return trim($fieldName) . '_' . $this->syntaxEL[self::INSTANCE] . '_' . ++$this->counter . 'i'; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | } |
278 | 278 | \ No newline at end of file |
@@ -85,8 +85,9 @@ discard block |
||
85 | 85 | { |
86 | 86 | $this->syntaxEL = $this->init(); |
87 | 87 | |
88 | - foreach ( $this->syntaxEL as $name => $value ) |
|
89 | - $this->typeEL[ $name ] = gettype( $value ); |
|
88 | + foreach ( $this->syntaxEL as $name => $value ) { |
|
89 | + $this->typeEL[ $name ] = gettype( $value ); |
|
90 | + } |
|
90 | 91 | |
91 | 92 | } |
92 | 93 | |
@@ -172,16 +173,19 @@ discard block |
||
172 | 173 | */ |
173 | 174 | public function setElement( $name, $value ) |
174 | 175 | { |
175 | - if ( !array_key_exists( $name, $this->syntaxEL ) ) |
|
176 | - throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
176 | + if ( !array_key_exists( $name, $this->syntaxEL ) ) { |
|
177 | + throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
178 | + } |
|
177 | 179 | |
178 | - if ( $name == self::TABLE && is_a( $value, QueryStatement::class ) ) |
|
179 | - return true; |
|
180 | + if ( $name == self::TABLE && is_a( $value, QueryStatement::class ) ) { |
|
181 | + return true; |
|
182 | + } |
|
180 | 183 | |
181 | - if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY ) |
|
182 | - $this->syntaxEL[ $name ][] = $value; |
|
183 | - else |
|
184 | - $this->syntaxEL[ $name ] = $value; |
|
184 | + if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY ) { |
|
185 | + $this->syntaxEL[ $name ][] = $value; |
|
186 | + } else { |
|
187 | + $this->syntaxEL[ $name ] = $value; |
|
188 | + } |
|
185 | 189 | |
186 | 190 | return true; |
187 | 191 | } |
@@ -194,8 +198,9 @@ discard block |
||
194 | 198 | */ |
195 | 199 | public function replaceElement( $elementName, $elementValue ) |
196 | 200 | { |
197 | - if ( !array_key_exists( $elementName, $this->syntaxEL ) ) |
|
198 | - throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
201 | + if ( !array_key_exists( $elementName, $this->syntaxEL ) ) { |
|
202 | + throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
203 | + } |
|
199 | 204 | |
200 | 205 | $this->syntaxEL[ $elementName ] = $elementValue; |
201 | 206 | } |
@@ -243,11 +248,13 @@ discard block |
||
243 | 248 | */ |
244 | 249 | public function bindParamsExpression( $expression, array $params = [], $search = '?' ) |
245 | 250 | { |
246 | - if ( !count( $params ) ) |
|
247 | - return $expression; |
|
251 | + if ( !count( $params ) ) { |
|
252 | + return $expression; |
|
253 | + } |
|
248 | 254 | |
249 | - if ( strpos( $expression, $search ) === false ) |
|
250 | - return $expression; |
|
255 | + if ( strpos( $expression, $search ) === false ) { |
|
256 | + return $expression; |
|
257 | + } |
|
251 | 258 | |
252 | 259 | $params = array_slice( $params, 0, substr_count( $expression, $search ) ); |
253 | 260 |
@@ -85,12 +85,10 @@ |
||
85 | 85 | $fh = fopen( $log, 'a+' ) or die( "Fatal Error !" ); |
86 | 86 | fwrite( $fh, $messageFormat ); |
87 | 87 | fclose( $fh ); |
88 | - } |
|
89 | - else { |
|
88 | + } else { |
|
90 | 89 | $this->edit( $log, $date, $messageFormat ); |
91 | 90 | } |
92 | - } |
|
93 | - else { |
|
91 | + } else { |
|
94 | 92 | if ( mkdir( $this->path, 0777 ) === true ) { |
95 | 93 | $this->write( $message ); |
96 | 94 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | */ |
31 | 31 | private function __construct() |
32 | 32 | { |
33 | - $this->dateTimeZone = new \DateTimeZone( 'Europe/Bucharest' ); |
|
33 | + $this->dateTimeZone = new \DateTimeZone('Europe/Bucharest'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | |
@@ -38,61 +38,61 @@ discard block |
||
38 | 38 | * @param $query |
39 | 39 | * @param $duration |
40 | 40 | */ |
41 | - public function writeQueryDuration( $query, $duration ) |
|
41 | + public function writeQueryDuration($query, $duration) |
|
42 | 42 | { |
43 | - $backtrace = end( debug_backtrace() ); |
|
43 | + $backtrace = end(debug_backtrace()); |
|
44 | 44 | $location = $backtrace['file'] . " Line: " . $backtrace['line']; |
45 | 45 | |
46 | 46 | $this->path = DbConfig::getInstance()->getLogPathQueryDuration(); //my comments |
47 | - $message = "Duration: " . round( $duration, 5 ) . "\r\n"; |
|
47 | + $message = "Duration: " . round($duration, 5) . "\r\n"; |
|
48 | 48 | $message .= "Location: $location\r\n"; |
49 | 49 | $message .= "Query: $query"; |
50 | - $this->write( $message ); |
|
50 | + $this->write($message); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @param $query |
55 | 55 | * @param $duration |
56 | 56 | */ |
57 | - public function writeQueryErros( $query, $code, $error ) |
|
57 | + public function writeQueryErros($query, $code, $error) |
|
58 | 58 | { |
59 | - $backtrace = end( debug_backtrace() ); |
|
59 | + $backtrace = end(debug_backtrace()); |
|
60 | 60 | $location = $backtrace['file'] . " Line: " . $backtrace['line']; |
61 | 61 | |
62 | 62 | $this->path = DbConfig::getInstance()->getLogPathErrors(); //my comments |
63 | 63 | $message = "Query: $query" . "\r\n"; |
64 | 64 | $message .= "Location: $location\r\n"; |
65 | 65 | $message .= "Error code : " . $code . "\r\n"; |
66 | - $message .= "" . $error ; |
|
66 | + $message .= "" . $error; |
|
67 | 67 | |
68 | - $this->write( $message ); |
|
68 | + $this->write($message); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | |
72 | - public function write( $message ) |
|
72 | + public function write($message) |
|
73 | 73 | { |
74 | 74 | |
75 | 75 | $date = new \DateTime(); |
76 | - $date->setTimezone( $this->dateTimeZone ); |
|
76 | + $date->setTimezone($this->dateTimeZone); |
|
77 | 77 | |
78 | - $log = $this->path . $date->format( 'Y-m-d' ) . ".txt"; |
|
79 | - $time = $date->format( 'H:i:s' ); |
|
78 | + $log = $this->path . $date->format('Y-m-d') . ".txt"; |
|
79 | + $time = $date->format('H:i:s'); |
|
80 | 80 | |
81 | 81 | $messageFormat = "[$time]\r\n$message\r\n\r\n"; |
82 | 82 | |
83 | - if ( is_dir( $this->path ) ) { |
|
84 | - if ( !file_exists( $log ) ) { |
|
85 | - $fh = fopen( $log, 'a+' ) or die( "Fatal Error !" ); |
|
86 | - fwrite( $fh, $messageFormat ); |
|
87 | - fclose( $fh ); |
|
83 | + if (is_dir($this->path)) { |
|
84 | + if (!file_exists($log)) { |
|
85 | + $fh = fopen($log, 'a+') or die("Fatal Error !"); |
|
86 | + fwrite($fh, $messageFormat); |
|
87 | + fclose($fh); |
|
88 | 88 | } |
89 | 89 | else { |
90 | - $this->edit( $log, $date, $messageFormat ); |
|
90 | + $this->edit($log, $date, $messageFormat); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | else { |
94 | - if ( mkdir( $this->path, 0777 ) === true ) { |
|
95 | - $this->write( $message ); |
|
94 | + if (mkdir($this->path, 0777) === true) { |
|
95 | + $this->write($message); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | } |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | * @param \DateTime $date |
104 | 104 | * @param string $message |
105 | 105 | */ |
106 | - private function edit( $log, \DateTime $date, $message ) |
|
106 | + private function edit($log, \DateTime $date, $message) |
|
107 | 107 | { |
108 | - file_put_contents( $log, $message, FILE_APPEND ); |
|
108 | + file_put_contents($log, $message, FILE_APPEND); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public static function getInstance() |
116 | 116 | { |
117 | - if ( null === self::$instance ) { |
|
117 | + if (null === self::$instance) { |
|
118 | 118 | self::$instance = new self(); |
119 | 119 | } |
120 | 120 |
@@ -42,8 +42,9 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function getMasterConnection() |
44 | 44 | { |
45 | - if ( !is_a( $this->pdoMaster, \PDO::class ) ) |
|
46 | - $this->pdoMaster = $this->connect( $this->config->getMasterDataConnect() ); |
|
45 | + if ( !is_a( $this->pdoMaster, \PDO::class ) ) { |
|
46 | + $this->pdoMaster = $this->connect( $this->config->getMasterDataConnect() ); |
|
47 | + } |
|
47 | 48 | |
48 | 49 | return $this->pdoMaster; |
49 | 50 | } |
@@ -53,11 +54,13 @@ discard block |
||
53 | 54 | */ |
54 | 55 | public function getSlaveConnection() |
55 | 56 | { |
56 | - if ( !$this->config->getReplicationEnable() ) |
|
57 | - return $this->getMasterConnection(); |
|
57 | + if ( !$this->config->getReplicationEnable() ) { |
|
58 | + return $this->getMasterConnection(); |
|
59 | + } |
|
58 | 60 | |
59 | - if ( !is_a( $this->pdoSlave, \PDO::class ) ) |
|
60 | - $this->pdoSlave = $this->connect( $this->config->getSlaveDataConnect() ); |
|
61 | + if ( !is_a( $this->pdoSlave, \PDO::class ) ) { |
|
62 | + $this->pdoSlave = $this->connect( $this->config->getSlaveDataConnect() ); |
|
63 | + } |
|
61 | 64 | |
62 | 65 | return $this->pdoSlave; |
63 | 66 | } |
@@ -70,8 +73,9 @@ discard block |
||
70 | 73 | { |
71 | 74 | $statement = trim( strtolower( $statement ) ); |
72 | 75 | |
73 | - if ( $statement === DbService::QUERY_TYPE_SELECT ) |
|
74 | - return $this->getSlaveConnection(); |
|
76 | + if ( $statement === DbService::QUERY_TYPE_SELECT ) { |
|
77 | + return $this->getSlaveConnection(); |
|
78 | + } |
|
75 | 79 | |
76 | 80 | return $this->getMasterConnection(); |
77 | 81 | } |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function getMasterConnection() |
44 | 44 | { |
45 | - if ( !is_a( $this->pdoMaster, \PDO::class ) ) |
|
46 | - $this->pdoMaster = $this->connect( $this->config->getMasterDataConnect() ); |
|
45 | + if (!is_a($this->pdoMaster, \PDO::class)) |
|
46 | + $this->pdoMaster = $this->connect($this->config->getMasterDataConnect()); |
|
47 | 47 | |
48 | 48 | return $this->pdoMaster; |
49 | 49 | } |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function getSlaveConnection() |
55 | 55 | { |
56 | - if ( !$this->config->getReplicationEnable() ) |
|
56 | + if (!$this->config->getReplicationEnable()) |
|
57 | 57 | return $this->getMasterConnection(); |
58 | 58 | |
59 | - if ( !is_a( $this->pdoSlave, \PDO::class ) ) |
|
60 | - $this->pdoSlave = $this->connect( $this->config->getSlaveDataConnect() ); |
|
59 | + if (!is_a($this->pdoSlave, \PDO::class)) |
|
60 | + $this->pdoSlave = $this->connect($this->config->getSlaveDataConnect()); |
|
61 | 61 | |
62 | 62 | return $this->pdoSlave; |
63 | 63 | } |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | * @param $statement |
67 | 67 | * @return \PDO |
68 | 68 | */ |
69 | - public function getConnection( $statement ) |
|
69 | + public function getConnection($statement) |
|
70 | 70 | { |
71 | - $statement = trim( strtolower( $statement ) ); |
|
71 | + $statement = trim(strtolower($statement)); |
|
72 | 72 | |
73 | - if ( $statement === DbService::QUERY_TYPE_SELECT ) |
|
73 | + if ($statement === DbService::QUERY_TYPE_SELECT) |
|
74 | 74 | return $this->getSlaveConnection(); |
75 | 75 | |
76 | 76 | return $this->getMasterConnection(); |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * @param $string |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - public function quote( $string ) |
|
83 | + public function quote($string) |
|
84 | 84 | { |
85 | - return $this->getMasterConnection()->quote( $string ); |
|
85 | + return $this->getMasterConnection()->quote($string); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -97,22 +97,22 @@ discard block |
||
97 | 97 | * @param $dataConnect |
98 | 98 | * @return \PDO |
99 | 99 | */ |
100 | - private function connect( $dataConnect ) |
|
100 | + private function connect($dataConnect) |
|
101 | 101 | { |
102 | 102 | $dsn = 'mysql:dbname=' . $dataConnect["dbname"] . ';host=' . $dataConnect["host"] . ''; |
103 | 103 | try { |
104 | 104 | |
105 | - $pdo = new \PDO( $dsn, $dataConnect["user"], $dataConnect["password"], |
|
106 | - array( \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" ) |
|
105 | + $pdo = new \PDO($dsn, $dataConnect["user"], $dataConnect["password"], |
|
106 | + array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") |
|
107 | 107 | ); |
108 | 108 | |
109 | - $pdo->setAttribute( \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION ); |
|
110 | - $pdo->setAttribute( \PDO::ATTR_EMULATE_PREPARES, false ); |
|
111 | - } catch ( \PDOException $e ) { |
|
112 | - if ( DbConfig::getInstance()->isEnableLogErrors() ) { |
|
113 | - DbLog::getInstance()->writeQueryErros( 'Connection fail!', $e->getCode(), $e->getMessage() ); |
|
109 | + $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
|
110 | + $pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); |
|
111 | + } catch (\PDOException $e) { |
|
112 | + if (DbConfig::getInstance()->isEnableLogErrors()) { |
|
113 | + DbLog::getInstance()->writeQueryErros('Connection fail!', $e->getCode(), $e->getMessage()); |
|
114 | 114 | } |
115 | - throw new \PDOException( $e->getMessage(), $e->getCode() ); |
|
115 | + throw new \PDOException($e->getMessage(), $e->getCode()); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | return $pdo; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public static function getInstance() |
126 | 126 | { |
127 | - if ( null === self::$instance ) { |
|
127 | + if (null === self::$instance) { |
|
128 | 128 | self::$instance = new self(); |
129 | 129 | } |
130 | 130 |
@@ -60,10 +60,11 @@ discard block |
||
60 | 60 | private function __construct() |
61 | 61 | { |
62 | 62 | $vendorCfg = __DIR__ . '/../../../../../vendor-cfg/qpdb_db_config.php'; |
63 | - if(file_exists($vendorCfg)) |
|
64 | - $this->dbConfig = require $vendorCfg; |
|
65 | - else |
|
66 | - $this->dbConfig = require __DIR__ . '/../../config/qpdb_db_config.php'; |
|
63 | + if(file_exists($vendorCfg)) { |
|
64 | + $this->dbConfig = require $vendorCfg; |
|
65 | + } else { |
|
66 | + $this->dbConfig = require __DIR__ . '/../../config/qpdb_db_config.php'; |
|
67 | + } |
|
67 | 68 | |
68 | 69 | $this->buildConfig(); |
69 | 70 | } |
@@ -146,8 +147,9 @@ discard block |
||
146 | 147 | |
147 | 148 | public function useTablePrefix() |
148 | 149 | { |
149 | - if ( !empty( $this->dbConfig['use_table_prefix'] ) ) |
|
150 | - return $this->dbConfig['use_table_prefix']; |
|
150 | + if ( !empty( $this->dbConfig['use_table_prefix'] ) ) { |
|
151 | + return $this->dbConfig['use_table_prefix']; |
|
152 | + } |
|
151 | 153 | |
152 | 154 | return false; |
153 | 155 | } |
@@ -182,8 +184,9 @@ discard block |
||
182 | 184 | private function readMasterDataConnect() |
183 | 185 | { |
184 | 186 | |
185 | - if ( !isset( $this->dbConfig['master_data_connect'][0] ) ) |
|
186 | - throw new DbException( 'Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING ); |
|
187 | + if ( !isset( $this->dbConfig['master_data_connect'][0] ) ) { |
|
188 | + throw new DbException( 'Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING ); |
|
189 | + } |
|
187 | 190 | |
188 | 191 | $dataConnection = $this->dbConfig['master_data_connect']; |
189 | 192 |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | private function __construct() |
61 | 61 | { |
62 | 62 | $vendorCfg = __DIR__ . '/../../../../../vendor-cfg/qpdb_db_config.php'; |
63 | - if(file_exists($vendorCfg)) |
|
63 | + if (file_exists($vendorCfg)) |
|
64 | 64 | $this->dbConfig = require $vendorCfg; |
65 | 65 | else |
66 | 66 | $this->dbConfig = require __DIR__ . '/../../config/qpdb_db_config.php'; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @param string $fileConfig |
73 | 73 | * @return $this |
74 | 74 | */ |
75 | - public function withFileConfig( $fileConfig ) |
|
75 | + public function withFileConfig($fileConfig) |
|
76 | 76 | { |
77 | 77 | $this->dbConfig = require $fileConfig; |
78 | 78 | $this->buildConfig(); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | public function useTablePrefix() |
148 | 148 | { |
149 | - if ( !empty( $this->dbConfig['use_table_prefix'] ) ) |
|
149 | + if (!empty($this->dbConfig['use_table_prefix'])) |
|
150 | 150 | return $this->dbConfig['use_table_prefix']; |
151 | 151 | |
152 | 152 | return false; |
@@ -182,18 +182,18 @@ discard block |
||
182 | 182 | private function readMasterDataConnect() |
183 | 183 | { |
184 | 184 | |
185 | - if ( !isset( $this->dbConfig['master_data_connect'][0] ) ) |
|
186 | - throw new DbException( 'Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING ); |
|
185 | + if (!isset($this->dbConfig['master_data_connect'][0])) |
|
186 | + throw new DbException('Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING); |
|
187 | 187 | |
188 | 188 | $dataConnection = $this->dbConfig['master_data_connect']; |
189 | 189 | |
190 | - if ( !$this->replicationEnable || count( $dataConnection ) == 1 ) { |
|
190 | + if (!$this->replicationEnable || count($dataConnection) == 1) { |
|
191 | 191 | $this->masterDataConnect = $dataConnection[0]; |
192 | 192 | |
193 | 193 | return true; |
194 | 194 | } |
195 | 195 | |
196 | - shuffle( $dataConnection ); |
|
196 | + shuffle($dataConnection); |
|
197 | 197 | $this->masterDataConnect = $dataConnection[0]; |
198 | 198 | |
199 | 199 | return true; |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | private function readSlaveDataConnect() |
207 | 207 | { |
208 | 208 | |
209 | - if ( !isset( $this->dbConfig['slave_data_connect'][0] ) ) { |
|
209 | + if (!isset($this->dbConfig['slave_data_connect'][0])) { |
|
210 | 210 | $this->slaveDataConnect = $this->masterDataConnect; |
211 | 211 | |
212 | 212 | return true; |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | |
215 | 215 | $dataConnection = $this->dbConfig['slave_data_connect']; |
216 | 216 | |
217 | - shuffle( $dataConnection ); |
|
217 | + shuffle($dataConnection); |
|
218 | 218 | $this->slaveDataConnect = $dataConnection[0]; |
219 | 219 | |
220 | 220 | return true; |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public static function getInstance() |
227 | 227 | { |
228 | - if ( null === self::$instance ) { |
|
228 | + if (null === self::$instance) { |
|
229 | 229 | self::$instance = new self(); |
230 | 230 | } |
231 | 231 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * QueryBuild constructor. |
27 | 27 | * @param $queryType |
28 | 28 | */ |
29 | - protected function __construct( $queryType ) |
|
29 | + protected function __construct($queryType) |
|
30 | 30 | { |
31 | 31 | $this->queryType = $queryType; |
32 | 32 | } |
@@ -35,45 +35,45 @@ discard block |
||
35 | 35 | * @param $table |
36 | 36 | * @return QuerySelect |
37 | 37 | */ |
38 | - public static function select( $table ) |
|
38 | + public static function select($table) |
|
39 | 39 | { |
40 | - return new QuerySelect( new QueryBuild( 0 ), $table ); |
|
40 | + return new QuerySelect(new QueryBuild(0), $table); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @param $table |
45 | 45 | * @return QueryUpdate |
46 | 46 | */ |
47 | - public static function update( $table ) |
|
47 | + public static function update($table) |
|
48 | 48 | { |
49 | - return new QueryUpdate( new QueryBuild( 0 ), $table ); |
|
49 | + return new QueryUpdate(new QueryBuild(0), $table); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @param $table |
54 | 54 | * @return QueryInsert |
55 | 55 | */ |
56 | - public static function insert( $table ) |
|
56 | + public static function insert($table) |
|
57 | 57 | { |
58 | - return new QueryInsert( new QueryBuild( 0 ), $table ); |
|
58 | + return new QueryInsert(new QueryBuild(0), $table); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | 62 | * @param $table |
63 | 63 | * @return QueryDelete |
64 | 64 | */ |
65 | - public static function delete( $table ) |
|
65 | + public static function delete($table) |
|
66 | 66 | { |
67 | - return new QueryDelete( new QueryBuild( 0 ), $table ); |
|
67 | + return new QueryDelete(new QueryBuild(0), $table); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | 71 | * @param $query |
72 | 72 | * @return QueryCustom |
73 | 73 | */ |
74 | - public static function query( $query ) |
|
74 | + public static function query($query) |
|
75 | 75 | { |
76 | - return new QueryCustom( new QueryBuild( 1 ), $query ); |
|
76 | + return new QueryCustom(new QueryBuild(1), $query); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -110,8 +110,9 @@ |
||
110 | 110 | if ( |
111 | 111 | $this->queryStructure->getElement( ( QueryStructure::WHERE_TRIGGER ) ) && |
112 | 112 | !count( $this->queryStructure->getElement( QueryStructure::WHERE ) ) |
113 | - ) |
|
114 | - throw new QueryException( 'Where clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER ); |
|
113 | + ) { |
|
114 | + throw new QueryException( 'Where clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER ); |
|
115 | + } |
|
115 | 116 | |
116 | 117 | return DbService::getInstance()->query( |
117 | 118 | $this->getSyntax(), |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | * @param QueryBuild $queryBuild |
40 | 40 | * @param string $table |
41 | 41 | */ |
42 | - public function __construct( QueryBuild $queryBuild, $table = null ) |
|
42 | + public function __construct(QueryBuild $queryBuild, $table = null) |
|
43 | 43 | { |
44 | - parent::__construct( $queryBuild, $table ); |
|
44 | + parent::__construct($queryBuild, $table); |
|
45 | 45 | } |
46 | 46 | |
47 | - public function getSyntax( $replacement = self::REPLACEMENT_NONE ) |
|
47 | + public function getSyntax($replacement = self::REPLACEMENT_NONE) |
|
48 | 48 | { |
49 | 49 | |
50 | 50 | $syntax = array(); |
@@ -62,17 +62,17 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * PRIORITY |
64 | 64 | */ |
65 | - $syntax[] = $this->queryStructure->getElement( QueryStructure::PRIORITY ); |
|
65 | + $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY); |
|
66 | 66 | |
67 | 67 | /** |
68 | 68 | * IGNORE clause |
69 | 69 | */ |
70 | - $syntax[] = $this->queryStructure->getElement( QueryStructure::IGNORE ) ? 'IGNORE' : ''; |
|
70 | + $syntax[] = $this->queryStructure->getElement(QueryStructure::IGNORE) ? 'IGNORE' : ''; |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * TABLE update |
74 | 74 | */ |
75 | - $syntax[] = $this->queryStructure->getElement( QueryStructure::TABLE ); |
|
75 | + $syntax[] = $this->queryStructure->getElement(QueryStructure::TABLE); |
|
76 | 76 | |
77 | 77 | /** |
78 | 78 | * FIELDS update |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | */ |
95 | 95 | $syntax[] = $this->getLimitSyntax(); |
96 | 96 | |
97 | - $syntax = implode( ' ', $syntax ); |
|
97 | + $syntax = implode(' ', $syntax); |
|
98 | 98 | |
99 | - return $this->getSyntaxReplace( $syntax, $replacement ); |
|
99 | + return $this->getSyntaxReplace($syntax, $replacement); |
|
100 | 100 | |
101 | 101 | } |
102 | 102 | |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | { |
109 | 109 | |
110 | 110 | if ( |
111 | - $this->queryStructure->getElement( ( QueryStructure::WHERE_TRIGGER ) ) && |
|
112 | - !count( $this->queryStructure->getElement( QueryStructure::WHERE ) ) |
|
111 | + $this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && |
|
112 | + !count($this->queryStructure->getElement(QueryStructure::WHERE)) |
|
113 | 113 | ) |
114 | - throw new QueryException( 'Where clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER ); |
|
114 | + throw new QueryException('Where clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER); |
|
115 | 115 | |
116 | 116 | return DbService::getInstance()->query( |
117 | 117 | $this->getSyntax(), |
118 | - $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) |
|
118 | + $this->queryStructure->getElement(QueryStructure::BIND_PARAMS) |
|
119 | 119 | ); |
120 | 120 | } |
121 | 121 | } |
122 | 122 | \ No newline at end of file |
@@ -18,7 +18,7 @@ |
||
18 | 18 | * @param bool $replacement |
19 | 19 | * @return string |
20 | 20 | */ |
21 | - public function getSyntax( $replacement = self::REPLACEMENT_NONE ); |
|
21 | + public function getSyntax($replacement = self::REPLACEMENT_NONE); |
|
22 | 22 | |
23 | 23 | public function execute(); |
24 | 24 |
@@ -42,21 +42,21 @@ discard block |
||
42 | 42 | * @param QueryBuild $queryBuild |
43 | 43 | * @param string|QueryStatement $table |
44 | 44 | */ |
45 | - public function __construct( QueryBuild $queryBuild, $table ) |
|
45 | + public function __construct(QueryBuild $queryBuild, $table) |
|
46 | 46 | { |
47 | - parent::__construct( $queryBuild, $table ); |
|
47 | + parent::__construct($queryBuild, $table); |
|
48 | 48 | |
49 | - if ( is_a( $table, QuerySelect::class ) ) { |
|
49 | + if (is_a($table, QuerySelect::class)) { |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @var QuerySelect $table |
53 | 53 | */ |
54 | 54 | $tableName = '( ' . $table->getSyntax() . ' )'; |
55 | - $this->queryStructure->setElement( QueryStructure::TABLE, $tableName ); |
|
55 | + $this->queryStructure->setElement(QueryStructure::TABLE, $tableName); |
|
56 | 56 | |
57 | 57 | $tableSelectParams = $table->getBindParams(); |
58 | - foreach ( $tableSelectParams as $key => $value ) |
|
59 | - $this->queryStructure->setParams( $key, $value ); |
|
58 | + foreach ($tableSelectParams as $key => $value) |
|
59 | + $this->queryStructure->setParams($key, $value); |
|
60 | 60 | |
61 | 61 | } |
62 | 62 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function first() |
68 | 68 | { |
69 | - $this->queryStructure->setElement( QueryStructure::FIRST, 1 ); |
|
69 | + $this->queryStructure->setElement(QueryStructure::FIRST, 1); |
|
70 | 70 | |
71 | 71 | return $this; |
72 | 72 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function count() |
78 | 78 | { |
79 | - $this->queryStructure->setElement( QueryStructure::COUNT, 1 ); |
|
79 | + $this->queryStructure->setElement(QueryStructure::COUNT, 1); |
|
80 | 80 | |
81 | 81 | return $this; |
82 | 82 | } |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | * @param $column |
86 | 86 | * @return $this |
87 | 87 | */ |
88 | - public function column( $column ) |
|
88 | + public function column($column) |
|
89 | 89 | { |
90 | - $column = QueryHelper::clearMultipleSpaces( $column ); |
|
91 | - $this->queryStructure->setElement( QueryStructure::COLUMN, $column ); |
|
90 | + $column = QueryHelper::clearMultipleSpaces($column); |
|
91 | + $this->queryStructure->setElement(QueryStructure::COLUMN, $column); |
|
92 | 92 | |
93 | 93 | return $this; |
94 | 94 | } |
@@ -98,17 +98,17 @@ discard block |
||
98 | 98 | * @param bool|int $replacement |
99 | 99 | * @return mixed|string |
100 | 100 | */ |
101 | - public function getSyntax( $replacement = self::REPLACEMENT_NONE ) |
|
101 | + public function getSyntax($replacement = self::REPLACEMENT_NONE) |
|
102 | 102 | { |
103 | 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 ); //??? |
|
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 | 108 | } |
109 | 109 | |
110 | - if ( $this->queryStructure->getElement( QueryStructure::FIRST ) ) |
|
111 | - $this->queryStructure->setElement( QueryStructure::LIMIT, 1 ); |
|
110 | + if ($this->queryStructure->getElement(QueryStructure::FIRST)) |
|
111 | + $this->queryStructure->setElement(QueryStructure::LIMIT, 1); |
|
112 | 112 | |
113 | 113 | $syntax = array(); |
114 | 114 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | /** |
126 | 126 | * PRIORITY |
127 | 127 | */ |
128 | - $syntax[] = $this->queryStructure->getElement( QueryStructure::PRIORITY ); |
|
128 | + $syntax[] = $this->queryStructure->getElement(QueryStructure::PRIORITY); |
|
129 | 129 | |
130 | 130 | /** |
131 | 131 | * DISTINCT clause |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * FIELDS |
137 | 137 | */ |
138 | - $syntax[] = $this->queryStructure->getElement( QueryStructure::FIELDS ); |
|
138 | + $syntax[] = $this->queryStructure->getElement(QueryStructure::FIELDS); |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * FROM table or queryStructure |
142 | 142 | */ |
143 | - $syntax[] = 'FROM ' . $this->queryStructure->getElement( QueryStructure::TABLE ); |
|
143 | + $syntax[] = 'FROM ' . $this->queryStructure->getElement(QueryStructure::TABLE); |
|
144 | 144 | |
145 | 145 | /** |
146 | 146 | * JOIN CLAUSES |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | */ |
173 | 173 | $syntax[] = $this->getLimitSyntax(); |
174 | 174 | |
175 | - $syntax = implode( ' ', $syntax ); |
|
175 | + $syntax = implode(' ', $syntax); |
|
176 | 176 | |
177 | - return $this->getSyntaxReplace( $syntax, $replacement ); |
|
177 | + return $this->getSyntaxReplace($syntax, $replacement); |
|
178 | 178 | |
179 | 179 | } |
180 | 180 | |
@@ -185,21 +185,21 @@ discard block |
||
185 | 185 | public function execute() |
186 | 186 | { |
187 | 187 | |
188 | - switch ( true ) { |
|
189 | - case $this->queryStructure->getElement( QueryStructure::COUNT ): |
|
190 | - return DbService::getInstance()->single( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) ); |
|
188 | + switch (true) { |
|
189 | + case $this->queryStructure->getElement(QueryStructure::COUNT): |
|
190 | + return DbService::getInstance()->single($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS)); |
|
191 | 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 ) ); |
|
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 | 195 | |
196 | - return DbService::getInstance()->row( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) ); |
|
196 | + return DbService::getInstance()->row($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS)); |
|
197 | 197 | break; |
198 | - case $this->queryStructure->getElement( QueryStructure::COLUMN ): |
|
199 | - return DbService::getInstance()->column( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) ); |
|
198 | + case $this->queryStructure->getElement(QueryStructure::COLUMN): |
|
199 | + return DbService::getInstance()->column($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS)); |
|
200 | 200 | break; |
201 | 201 | default: |
202 | - return DbService::getInstance()->query( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) ); |
|
202 | + return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS)); |
|
203 | 203 | break; |
204 | 204 | } |
205 | 205 | } |
@@ -55,8 +55,9 @@ discard block |
||
55 | 55 | $this->queryStructure->setElement( QueryStructure::TABLE, $tableName ); |
56 | 56 | |
57 | 57 | $tableSelectParams = $table->getBindParams(); |
58 | - foreach ( $tableSelectParams as $key => $value ) |
|
59 | - $this->queryStructure->setParams( $key, $value ); |
|
58 | + foreach ( $tableSelectParams as $key => $value ) { |
|
59 | + $this->queryStructure->setParams( $key, $value ); |
|
60 | + } |
|
60 | 61 | |
61 | 62 | } |
62 | 63 | } |
@@ -107,8 +108,9 @@ discard block |
||
107 | 108 | $this->queryStructure->setElement( QueryStructure::DISTINCT, 0 ); //??? |
108 | 109 | } |
109 | 110 | |
110 | - if ( $this->queryStructure->getElement( QueryStructure::FIRST ) ) |
|
111 | - $this->queryStructure->setElement( QueryStructure::LIMIT, 1 ); |
|
111 | + if ( $this->queryStructure->getElement( QueryStructure::FIRST ) ) { |
|
112 | + $this->queryStructure->setElement( QueryStructure::LIMIT, 1 ); |
|
113 | + } |
|
112 | 114 | |
113 | 115 | $syntax = array(); |
114 | 116 | |
@@ -190,8 +192,9 @@ discard block |
||
190 | 192 | return DbService::getInstance()->single( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) ); |
191 | 193 | break; |
192 | 194 | 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 | + if ( $this->queryStructure->getElement( QueryStructure::COLUMN ) ) { |
|
196 | + return DbService::getInstance()->single( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) ); |
|
197 | + } |
|
195 | 198 | |
196 | 199 | return DbService::getInstance()->row( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ) ); |
197 | 200 | break; |