@@ -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 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public function __construct() |
| 25 | 25 | { |
| 26 | - $this->queryStart = microtime( true ); |
|
| 26 | + $this->queryStart = microtime(true); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function getDuration() |
| 33 | 33 | { |
| 34 | - $this->queryEnd = microtime( true ); |
|
| 34 | + $this->queryEnd = microtime(true); |
|
| 35 | 35 | |
| 36 | 36 | return $this->queryEnd - $this->queryStart; |
| 37 | 37 | } |
@@ -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 === static::$instance ) { |
|
| 117 | + if (null === static::$instance) { |
|
| 118 | 118 | static::$instance = new static(); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -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 | } |
@@ -52,22 +52,22 @@ discard block |
||
| 52 | 52 | * @param int $fetchMode |
| 53 | 53 | * @return array|int|null |
| 54 | 54 | */ |
| 55 | - public function query( $query, $params = null, $fetchMode = \PDO::FETCH_ASSOC ) |
|
| 55 | + public function query($query, $params = null, $fetchMode = \PDO::FETCH_ASSOC) |
|
| 56 | 56 | { |
| 57 | 57 | |
| 58 | - $query = trim( str_replace( "\r", " ", $query ) ); |
|
| 59 | - $statement = self::getQueryStatement( $query ); |
|
| 58 | + $query = trim(str_replace("\r", " ", $query)); |
|
| 59 | + $statement = self::getQueryStatement($query); |
|
| 60 | 60 | |
| 61 | - $this->queryInit( $query, $params ); |
|
| 61 | + $this->queryInit($query, $params); |
|
| 62 | 62 | |
| 63 | - if ( $statement === self::QUERY_TYPE_SELECT || |
|
| 63 | + if ($statement === self::QUERY_TYPE_SELECT || |
|
| 64 | 64 | $statement === self::QUERY_TYPE_SHOW || |
| 65 | 65 | $statement === self::QUERY_TYPE_DESC || |
| 66 | 66 | $statement === self::QUERY_TYPE_EXPLAIN |
| 67 | 67 | ) { |
| 68 | - return $this->sQuery->fetchAll( $fetchMode ); |
|
| 68 | + return $this->sQuery->fetchAll($fetchMode); |
|
| 69 | 69 | } |
| 70 | - elseif ( $statement === self::QUERY_TYPE_INSERT || |
|
| 70 | + elseif ($statement === self::QUERY_TYPE_INSERT || |
|
| 71 | 71 | $statement === self::QUERY_TYPE_UPDATE || |
| 72 | 72 | $statement === self::QUERY_TYPE_DELETE |
| 73 | 73 | ) { |
@@ -84,46 +84,46 @@ discard block |
||
| 84 | 84 | * @param null $params |
| 85 | 85 | * @return array|null |
| 86 | 86 | */ |
| 87 | - public function column( $query, $params = null ) |
|
| 87 | + public function column($query, $params = null) |
|
| 88 | 88 | { |
| 89 | - $this->queryInit( $query, $params ); |
|
| 89 | + $this->queryInit($query, $params); |
|
| 90 | 90 | |
| 91 | - $query = trim( str_replace( "\r", " ", $query ) ); |
|
| 92 | - $statement = self::getQueryStatement( $query ); |
|
| 91 | + $query = trim(str_replace("\r", " ", $query)); |
|
| 92 | + $statement = self::getQueryStatement($query); |
|
| 93 | 93 | |
| 94 | - if ( $statement === self::QUERY_TYPE_EXPLAIN ) |
|
| 95 | - return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 94 | + if ($statement === self::QUERY_TYPE_EXPLAIN) |
|
| 95 | + return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC); |
|
| 96 | 96 | |
| 97 | - $Columns = $this->sQuery->fetchAll( \PDO::FETCH_NUM ); |
|
| 97 | + $Columns = $this->sQuery->fetchAll(\PDO::FETCH_NUM); |
|
| 98 | 98 | |
| 99 | 99 | $column = null; |
| 100 | 100 | |
| 101 | - foreach ( $Columns as $cells ) { |
|
| 101 | + foreach ($Columns as $cells) { |
|
| 102 | 102 | $column[] = $cells[0]; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | return $column; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - public function row( $query, $params = null, $fetchmode = \PDO::FETCH_ASSOC ) |
|
| 108 | + public function row($query, $params = null, $fetchmode = \PDO::FETCH_ASSOC) |
|
| 109 | 109 | { |
| 110 | - $this->queryInit( $query, $params ); |
|
| 110 | + $this->queryInit($query, $params); |
|
| 111 | 111 | |
| 112 | - $query = trim( str_replace( "\r", " ", $query ) ); |
|
| 113 | - $statement = self::getQueryStatement( $query ); |
|
| 112 | + $query = trim(str_replace("\r", " ", $query)); |
|
| 113 | + $statement = self::getQueryStatement($query); |
|
| 114 | 114 | |
| 115 | - if ( $statement === self::QUERY_TYPE_EXPLAIN ) |
|
| 116 | - return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 115 | + if ($statement === self::QUERY_TYPE_EXPLAIN) |
|
| 116 | + return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC); |
|
| 117 | 117 | |
| 118 | - $result = $this->sQuery->fetch( $fetchmode ); |
|
| 118 | + $result = $this->sQuery->fetch($fetchmode); |
|
| 119 | 119 | $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued, |
| 120 | 120 | |
| 121 | 121 | return $result; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - public function single( $query, $params = null ) |
|
| 124 | + public function single($query, $params = null) |
|
| 125 | 125 | { |
| 126 | - $this->queryInit( $query, $params ); |
|
| 126 | + $this->queryInit($query, $params); |
|
| 127 | 127 | $result = $this->sQuery->fetchColumn(); |
| 128 | 128 | $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued |
| 129 | 129 | |
@@ -135,57 +135,57 @@ discard block |
||
| 135 | 135 | * @param string $query |
| 136 | 136 | * @param array $parameters |
| 137 | 137 | */ |
| 138 | - private function queryInit( $query, $parameters = [] ) |
|
| 138 | + private function queryInit($query, $parameters = []) |
|
| 139 | 139 | { |
| 140 | - $this->pdo = DbConnect::getInstance()->getConnection( self::getQueryStatement( $query ) ); |
|
| 141 | - $startQueryTime = microtime( true ); |
|
| 140 | + $this->pdo = DbConnect::getInstance()->getConnection(self::getQueryStatement($query)); |
|
| 141 | + $startQueryTime = microtime(true); |
|
| 142 | 142 | |
| 143 | 143 | try { |
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * Prepare query |
| 147 | 147 | */ |
| 148 | - $this->sQuery = $this->pdo->prepare( $query ); |
|
| 148 | + $this->sQuery = $this->pdo->prepare($query); |
|
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * Add parameters to the parameter array |
| 152 | 152 | */ |
| 153 | - if ( self::isArrayAssoc( $parameters ) ) |
|
| 154 | - $this->bindMore( $parameters ); |
|
| 153 | + if (self::isArrayAssoc($parameters)) |
|
| 154 | + $this->bindMore($parameters); |
|
| 155 | 155 | else |
| 156 | - foreach ( $parameters as $key => $val ) |
|
| 157 | - $this->parameters[] = array( $key + 1, $val ); |
|
| 156 | + foreach ($parameters as $key => $val) |
|
| 157 | + $this->parameters[] = array($key + 1, $val); |
|
| 158 | 158 | |
| 159 | - if ( count( $this->parameters ) ) { |
|
| 160 | - foreach ( $this->parameters as $param => $value ) { |
|
| 161 | - if ( is_int( $value[1] ) ) { |
|
| 159 | + if (count($this->parameters)) { |
|
| 160 | + foreach ($this->parameters as $param => $value) { |
|
| 161 | + if (is_int($value[1])) { |
|
| 162 | 162 | $type = \PDO::PARAM_INT; |
| 163 | 163 | } |
| 164 | - elseif ( is_bool( $value[1] ) ) { |
|
| 164 | + elseif (is_bool($value[1])) { |
|
| 165 | 165 | $type = \PDO::PARAM_BOOL; |
| 166 | 166 | } |
| 167 | - elseif ( is_null( $value[1] ) ) { |
|
| 167 | + elseif (is_null($value[1])) { |
|
| 168 | 168 | $type = \PDO::PARAM_NULL; |
| 169 | 169 | } |
| 170 | 170 | else { |
| 171 | 171 | $type = \PDO::PARAM_STR; |
| 172 | 172 | } |
| 173 | - $this->sQuery->bindValue( $value[0], $value[1], $type ); |
|
| 173 | + $this->sQuery->bindValue($value[0], $value[1], $type); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | $this->sQuery->execute(); |
| 178 | 178 | |
| 179 | - if ( DbConfig::getInstance()->isEnableLogQueryDuration() ) { |
|
| 180 | - $duration = microtime( true ) - $startQueryTime; |
|
| 181 | - DbLog::getInstance()->writeQueryDuration( $query, $duration ); |
|
| 179 | + if (DbConfig::getInstance()->isEnableLogQueryDuration()) { |
|
| 180 | + $duration = microtime(true) - $startQueryTime; |
|
| 181 | + DbLog::getInstance()->writeQueryDuration($query, $duration); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - } catch ( \PDOException $e ) { |
|
| 185 | - if ( DbConfig::getInstance()->isEnableLogErrors() ) { |
|
| 186 | - DbLog::getInstance()->writeQueryErros( $query, $e->getCode(), $e->getMessage() ); |
|
| 184 | + } catch (\PDOException $e) { |
|
| 185 | + if (DbConfig::getInstance()->isEnableLogErrors()) { |
|
| 186 | + DbLog::getInstance()->writeQueryErros($query, $e->getCode(), $e->getMessage()); |
|
| 187 | 187 | } |
| 188 | - throw new \PDOException( $e->getMessage(), $e->getCode() ); |
|
| 188 | + throw new \PDOException($e->getMessage(), $e->getCode()); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -195,19 +195,19 @@ discard block |
||
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | |
| 198 | - public function bindMore( $parray ) |
|
| 198 | + public function bindMore($parray) |
|
| 199 | 199 | { |
| 200 | - if ( !count( $this->parameters ) && is_array( $parray ) ) { |
|
| 201 | - $columns = array_keys( $parray ); |
|
| 202 | - foreach ( $columns as $i => &$column ) { |
|
| 203 | - $this->bind( $column, $parray[ $column ] ); |
|
| 200 | + if (!count($this->parameters) && is_array($parray)) { |
|
| 201 | + $columns = array_keys($parray); |
|
| 202 | + foreach ($columns as $i => &$column) { |
|
| 203 | + $this->bind($column, $parray[$column]); |
|
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - public function bind( $para, $value ) |
|
| 208 | + public function bind($para, $value) |
|
| 209 | 209 | { |
| 210 | - $this->parameters[ sizeof( $this->parameters ) ] = [ ":" . $para, $value ]; |
|
| 210 | + $this->parameters[sizeof($this->parameters)] = [":" . $para, $value]; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
@@ -221,16 +221,16 @@ discard block |
||
| 221 | 221 | * @param $queryString |
| 222 | 222 | * @return string |
| 223 | 223 | */ |
| 224 | - public static function getQueryStatement( $queryString ) |
|
| 224 | + public static function getQueryStatement($queryString) |
|
| 225 | 225 | { |
| 226 | - $queryString = trim( $queryString ); |
|
| 226 | + $queryString = trim($queryString); |
|
| 227 | 227 | |
| 228 | - if ( $queryString === '' ) { |
|
| 228 | + if ($queryString === '') { |
|
| 229 | 229 | return self::QUERY_TYPE_EMPTY; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if ( preg_match( '/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches ) ) { |
|
| 233 | - switch ( strtolower( $matches[1] ) ) { |
|
| 232 | + if (preg_match('/^(select|insert|update|delete|replace|show|desc|explain)[\s]+/i', $queryString, $matches)) { |
|
| 233 | + switch (strtolower($matches[1])) { |
|
| 234 | 234 | case 'select': |
| 235 | 235 | return self::QUERY_TYPE_SELECT; |
| 236 | 236 | break; |
@@ -263,11 +263,11 @@ discard block |
||
| 263 | 263 | * @param array $arr |
| 264 | 264 | * @return bool |
| 265 | 265 | */ |
| 266 | - public static function isArrayAssoc( array $arr ) |
|
| 266 | + public static function isArrayAssoc(array $arr) |
|
| 267 | 267 | { |
| 268 | - if ( array() === $arr ) return false; |
|
| 268 | + if (array() === $arr) return false; |
|
| 269 | 269 | |
| 270 | - return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); |
|
| 270 | + return array_keys($arr) !== range(0, count($arr) - 1); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public static function getInstance() |
| 278 | 278 | { |
| 279 | - if ( null === static::$instance ) { |
|
| 279 | + if (null === static::$instance) { |
|
| 280 | 280 | static::$instance = new static(); |
| 281 | 281 | } |
| 282 | 282 | |
@@ -66,14 +66,12 @@ discard block |
||
| 66 | 66 | $statement === self::QUERY_TYPE_EXPLAIN |
| 67 | 67 | ) { |
| 68 | 68 | return $this->sQuery->fetchAll( $fetchMode ); |
| 69 | - } |
|
| 70 | - elseif ( $statement === self::QUERY_TYPE_INSERT || |
|
| 69 | + } elseif ( $statement === self::QUERY_TYPE_INSERT || |
|
| 71 | 70 | $statement === self::QUERY_TYPE_UPDATE || |
| 72 | 71 | $statement === self::QUERY_TYPE_DELETE |
| 73 | 72 | ) { |
| 74 | 73 | return $this->sQuery->rowCount(); |
| 75 | - } |
|
| 76 | - else { |
|
| 74 | + } else { |
|
| 77 | 75 | |
| 78 | 76 | return NULL; |
| 79 | 77 | } |
@@ -91,8 +89,9 @@ discard block |
||
| 91 | 89 | $query = trim( str_replace( "\r", " ", $query ) ); |
| 92 | 90 | $statement = self::getQueryStatement( $query ); |
| 93 | 91 | |
| 94 | - if ( $statement === self::QUERY_TYPE_EXPLAIN ) |
|
| 95 | - return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 92 | + if ( $statement === self::QUERY_TYPE_EXPLAIN ) { |
|
| 93 | + return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 94 | + } |
|
| 96 | 95 | |
| 97 | 96 | $Columns = $this->sQuery->fetchAll( \PDO::FETCH_NUM ); |
| 98 | 97 | |
@@ -112,8 +111,9 @@ discard block |
||
| 112 | 111 | $query = trim( str_replace( "\r", " ", $query ) ); |
| 113 | 112 | $statement = self::getQueryStatement( $query ); |
| 114 | 113 | |
| 115 | - if ( $statement === self::QUERY_TYPE_EXPLAIN ) |
|
| 116 | - return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 114 | + if ( $statement === self::QUERY_TYPE_EXPLAIN ) { |
|
| 115 | + return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | $result = $this->sQuery->fetch( $fetchmode ); |
| 119 | 119 | $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued, |
@@ -150,24 +150,22 @@ discard block |
||
| 150 | 150 | /** |
| 151 | 151 | * Add parameters to the parameter array |
| 152 | 152 | */ |
| 153 | - if ( self::isArrayAssoc( $parameters ) ) |
|
| 154 | - $this->bindMore( $parameters ); |
|
| 155 | - else |
|
| 156 | - foreach ( $parameters as $key => $val ) |
|
| 153 | + if ( self::isArrayAssoc( $parameters ) ) { |
|
| 154 | + $this->bindMore( $parameters ); |
|
| 155 | + } else { |
|
| 156 | + foreach ( $parameters as $key => $val ) |
|
| 157 | 157 | $this->parameters[] = array( $key + 1, $val ); |
| 158 | + } |
|
| 158 | 159 | |
| 159 | 160 | if ( count( $this->parameters ) ) { |
| 160 | 161 | foreach ( $this->parameters as $param => $value ) { |
| 161 | 162 | if ( is_int( $value[1] ) ) { |
| 162 | 163 | $type = \PDO::PARAM_INT; |
| 163 | - } |
|
| 164 | - elseif ( is_bool( $value[1] ) ) { |
|
| 164 | + } elseif ( is_bool( $value[1] ) ) { |
|
| 165 | 165 | $type = \PDO::PARAM_BOOL; |
| 166 | - } |
|
| 167 | - elseif ( is_null( $value[1] ) ) { |
|
| 166 | + } elseif ( is_null( $value[1] ) ) { |
|
| 168 | 167 | $type = \PDO::PARAM_NULL; |
| 169 | - } |
|
| 170 | - else { |
|
| 168 | + } else { |
|
| 171 | 169 | $type = \PDO::PARAM_STR; |
| 172 | 170 | } |
| 173 | 171 | $this->sQuery->bindValue( $value[0], $value[1], $type ); |
@@ -253,8 +251,7 @@ discard block |
||
| 253 | 251 | return self::QUERY_TYPE_OTHER; |
| 254 | 252 | break; |
| 255 | 253 | } |
| 256 | - } |
|
| 257 | - else { |
|
| 254 | + } else { |
|
| 258 | 255 | return self::QUERY_TYPE_OTHER; |
| 259 | 256 | } |
| 260 | 257 | } |
@@ -265,7 +262,9 @@ discard block |
||
| 265 | 262 | */ |
| 266 | 263 | public static function isArrayAssoc( array $arr ) |
| 267 | 264 | { |
| 268 | - if ( array() === $arr ) return false; |
|
| 265 | + if ( array() === $arr ) { |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 269 | 268 | |
| 270 | 269 | return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); |
| 271 | 270 | } |
@@ -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 === static::$instance ) { |
|
| 127 | + if (null === static::$instance) { |
|
| 128 | 128 | static::$instance = new static(); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -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 | } |
@@ -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 === static::$instance ) { |
|
| 228 | + if (null === static::$instance) { |
|
| 229 | 229 | static::$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 | /** |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | * @param QueryBuild $queryBuild |
| 40 | 40 | * @param null $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 |
@@ -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(), |