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