@@ -65,6 +65,10 @@ discard block |
||
| 65 | 65 | return FALSE; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | + /** |
|
| 69 | + * @param integer $limit |
|
| 70 | + * @param integer $offset |
|
| 71 | + */ |
|
| 68 | 72 | public function fetchAll($table, Array $fields, $index, Array $condition, $operator, $limit, $offset) |
| 69 | 73 | { |
| 70 | 74 | $hs = $this->getReadSocket(); |
@@ -140,6 +144,9 @@ discard block |
||
| 140 | 144 | return (bool)$result; |
| 141 | 145 | } |
| 142 | 146 | |
| 147 | + /** |
|
| 148 | + * @param integer $increment |
|
| 149 | + */ |
|
| 143 | 150 | public function increment($table, $field, $index, Array $condition, $operator, $increment) |
| 144 | 151 | { |
| 145 | 152 | $hs = $this->getWriteSocket(); |
@@ -155,6 +162,9 @@ discard block |
||
| 155 | 162 | return (bool)$result; |
| 156 | 163 | } |
| 157 | 164 | |
| 165 | + /** |
|
| 166 | + * @param integer $decrement |
|
| 167 | + */ |
|
| 158 | 168 | public function decrement($table, $field, $index, Array $condition, $operator, $decrement) |
| 159 | 169 | { |
| 160 | 170 | |
@@ -48,7 +48,9 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | list($database, $table) = $this->getTableDatabase($table); |
| 50 | 50 | |
| 51 | - if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY'; |
|
| 51 | + if ($index == HSAL::INDEX_PRIMARY) { |
|
| 52 | + $index = 'PRIMARY'; |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | $index = $hs->openIndex($database, $table, $fields, ['index' => $index]); |
| 54 | 56 | |
@@ -59,10 +61,11 @@ discard block |
||
| 59 | 61 | |
| 60 | 62 | $result = $index->find([$operator => $condition]); |
| 61 | 63 | |
| 62 | - if (!empty($result) && is_array($result)) |
|
| 63 | - return $result[0]; |
|
| 64 | - else |
|
| 65 | - return FALSE; |
|
| 64 | + if (!empty($result) && is_array($result)) { |
|
| 65 | + return $result[0]; |
|
| 66 | + } else { |
|
| 67 | + return FALSE; |
|
| 68 | + } |
|
| 66 | 69 | } |
| 67 | 70 | |
| 68 | 71 | public function fetchAll($table, Array $fields, $index, Array $condition, $operator, $limit, $offset) |
@@ -71,7 +74,9 @@ discard block |
||
| 71 | 74 | |
| 72 | 75 | list($database, $table) = $this->getTableDatabase($table); |
| 73 | 76 | |
| 74 | - if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY'; |
|
| 77 | + if ($index == HSAL::INDEX_PRIMARY) { |
|
| 78 | + $index = 'PRIMARY'; |
|
| 79 | + } |
|
| 75 | 80 | |
| 76 | 81 | $index = $hs->openIndex($database, $table, $fields, ['index' => $index]); |
| 77 | 82 | |
@@ -90,9 +95,9 @@ discard block |
||
| 90 | 95 | } |
| 91 | 96 | |
| 92 | 97 | return $result; |
| 98 | + } else { |
|
| 99 | + return FALSE; |
|
| 93 | 100 | } |
| 94 | - else |
|
| 95 | - return FALSE; |
|
| 96 | 101 | } |
| 97 | 102 | |
| 98 | 103 | public function delete($table, $index, Array $condition, $operator) |
@@ -101,7 +106,9 @@ discard block |
||
| 101 | 106 | |
| 102 | 107 | list($database, $table) = $this->getTableDatabase($table); |
| 103 | 108 | |
| 104 | - if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY'; |
|
| 109 | + if ($index == HSAL::INDEX_PRIMARY) { |
|
| 110 | + $index = 'PRIMARY'; |
|
| 111 | + } |
|
| 105 | 112 | |
| 106 | 113 | $index = $hs->openIndex($database, $table, [], ['index' => $index]); |
| 107 | 114 | |
@@ -129,7 +136,9 @@ discard block |
||
| 129 | 136 | |
| 130 | 137 | list($database, $table) = $this->getTableDatabase($table); |
| 131 | 138 | |
| 132 | - if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY'; |
|
| 139 | + if ($index == HSAL::INDEX_PRIMARY) { |
|
| 140 | + $index = 'PRIMARY'; |
|
| 141 | + } |
|
| 133 | 142 | |
| 134 | 143 | $fields = array_keys($values); |
| 135 | 144 | |
@@ -146,7 +155,9 @@ discard block |
||
| 146 | 155 | |
| 147 | 156 | list($database, $table) = $this->getTableDatabase($table); |
| 148 | 157 | |
| 149 | - if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY'; |
|
| 158 | + if ($index == HSAL::INDEX_PRIMARY) { |
|
| 159 | + $index = 'PRIMARY'; |
|
| 160 | + } |
|
| 150 | 161 | |
| 151 | 162 | $index = $hs->openIndex($database, $table, [$field]); |
| 152 | 163 | |
@@ -162,7 +173,9 @@ discard block |
||
| 162 | 173 | |
| 163 | 174 | list($database, $table) = $this->getTableDatabase($table); |
| 164 | 175 | |
| 165 | - if ($index == HSAL::INDEX_PRIMARY) $index = 'PRIMARY'; |
|
| 176 | + if ($index == HSAL::INDEX_PRIMARY) { |
|
| 177 | + $index = 'PRIMARY'; |
|
| 178 | + } |
|
| 166 | 179 | |
| 167 | 180 | $index = $hs->openIndex($database, $table, [$field]); |
| 168 | 181 | |
@@ -27,10 +27,11 @@ |
||
| 27 | 27 | { |
| 28 | 28 | $result = $this->fetchArray($table, $fields, $index, $condition, $operator); |
| 29 | 29 | |
| 30 | - if (!empty($result)) |
|
| 31 | - return array_combine($fields, $result); |
|
| 32 | - else |
|
| 33 | - return FALSE; |
|
| 30 | + if (!empty($result)) { |
|
| 31 | + return array_combine($fields, $result); |
|
| 32 | + } else { |
|
| 33 | + return FALSE; |
|
| 34 | + } |
|
| 34 | 35 | } |
| 35 | 36 | |
| 36 | 37 | public function getTableDatabase($table) |
@@ -35,8 +35,7 @@ discard block |
||
| 35 | 35 | if (extension_loaded('handlersocketi')) |
| 36 | 36 | { |
| 37 | 37 | $driver = self::DRIVER_HANDLERSOCKETI; |
| 38 | - } |
|
| 39 | - else if (class_exists('\\HSPHP\\ReadSocket')) |
|
| 38 | + } else if (class_exists('\\HSPHP\\ReadSocket')) |
|
| 40 | 39 | { |
| 41 | 40 | $driver = self::DRIVER_HSPHP; |
| 42 | 41 | } |
@@ -45,8 +44,7 @@ discard block |
||
| 45 | 44 | if ($driver == self::DRIVER_HANDLERSOCKETI) |
| 46 | 45 | { |
| 47 | 46 | $this->hs = new \HSAL\Driver\Handlersocketi($host, $database); |
| 48 | - } |
|
| 49 | - else if ($driver == self::DRIVER_HSPHP) |
|
| 47 | + } else if ($driver == self::DRIVER_HSPHP) |
|
| 50 | 48 | { |
| 51 | 49 | $this->hs = new \HSAL\Driver\HSPHP($host, $database); |
| 52 | 50 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | list($database, $table) = $this->getTableDatabase($table); |
| 49 | 49 | |
| 50 | - $idx = $hs->getIndexId($database, $table, $index, implode(',',$fields)); |
|
| 50 | + $idx = $hs->getIndexId($database, $table, $index, implode(',', $fields)); |
|
| 51 | 51 | $hs->select($idx, $operator, $condition); |
| 52 | 52 | $result = $hs->readResponse(); |
| 53 | 53 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | $fields = array_keys($values); |
| 107 | 107 | |
| 108 | - $idx = $hs->getIndexId($database, $table, '', implode(',',$fields)); |
|
| 108 | + $idx = $hs->getIndexId($database, $table, '', implode(',', $fields)); |
|
| 109 | 109 | $hs->insert($idx, array_values($values)); |
| 110 | 110 | |
| 111 | 111 | $result = $hs->readResponse(); |
@@ -51,10 +51,11 @@ discard block |
||
| 51 | 51 | $hs->select($idx, $operator, $condition); |
| 52 | 52 | $result = $hs->readResponse(); |
| 53 | 53 | |
| 54 | - if (!empty($result)) |
|
| 55 | - return $result[0]; |
|
| 56 | - else |
|
| 57 | - return FALSE; |
|
| 54 | + if (!empty($result)) { |
|
| 55 | + return $result[0]; |
|
| 56 | + } else { |
|
| 57 | + return FALSE; |
|
| 58 | + } |
|
| 58 | 59 | } |
| 59 | 60 | |
| 60 | 61 | public function fetchAll($table, Array $fields, $index, Array $condition, $operator, $limit, $offset) |
@@ -76,9 +77,9 @@ discard block |
||
| 76 | 77 | } |
| 77 | 78 | |
| 78 | 79 | return $result; |
| 80 | + } else { |
|
| 81 | + return FALSE; |
|
| 79 | 82 | } |
| 80 | - else |
|
| 81 | - return FALSE; |
|
| 82 | 83 | } |
| 83 | 84 | |
| 84 | 85 | public function delete($table, $index, Array $condition, $operator) |
@@ -91,10 +92,11 @@ discard block |
||
| 91 | 92 | $hs->delete($idx, $operator, $condition); |
| 92 | 93 | $result = $hs->readResponse(); |
| 93 | 94 | |
| 94 | - if (!empty($result)) |
|
| 95 | - return (bool)$result[0][0]; |
|
| 96 | - else |
|
| 97 | - return FALSE; |
|
| 95 | + if (!empty($result)) { |
|
| 96 | + return (bool)$result[0][0]; |
|
| 97 | + } else { |
|
| 98 | + return FALSE; |
|
| 99 | + } |
|
| 98 | 100 | } |
| 99 | 101 | |
| 100 | 102 | public function insert($table, Array $values) |
@@ -110,10 +112,11 @@ discard block |
||
| 110 | 112 | |
| 111 | 113 | $result = $hs->readResponse(); |
| 112 | 114 | |
| 113 | - if (!empty($result)) |
|
| 114 | - return (bool)$result[0][0]; |
|
| 115 | - else |
|
| 116 | - return FALSE; |
|
| 115 | + if (!empty($result)) { |
|
| 116 | + return (bool)$result[0][0]; |
|
| 117 | + } else { |
|
| 118 | + return FALSE; |
|
| 119 | + } |
|
| 117 | 120 | } |
| 118 | 121 | |
| 119 | 122 | public function update($table, Array $values, $index, Array $condition, $operator) |
@@ -129,10 +132,11 @@ discard block |
||
| 129 | 132 | |
| 130 | 133 | $result = $hs->readResponse(); |
| 131 | 134 | |
| 132 | - if (!empty($result)) |
|
| 133 | - return (bool)$result[0][0]; |
|
| 134 | - else |
|
| 135 | - return FALSE; |
|
| 135 | + if (!empty($result)) { |
|
| 136 | + return (bool)$result[0][0]; |
|
| 137 | + } else { |
|
| 138 | + return FALSE; |
|
| 139 | + } |
|
| 136 | 140 | } |
| 137 | 141 | |
| 138 | 142 | public function increment($table, $field, $index, Array $condition, $operator, $increment) |
@@ -145,10 +149,11 @@ discard block |
||
| 145 | 149 | $hs->increment($idx, $operator, $condition, [$increment]); |
| 146 | 150 | $result = $hs->readResponse(); |
| 147 | 151 | |
| 148 | - if (!empty($result)) |
|
| 149 | - return (bool)$result[0][0]; |
|
| 150 | - else |
|
| 151 | - return FALSE; |
|
| 152 | + if (!empty($result)) { |
|
| 153 | + return (bool)$result[0][0]; |
|
| 154 | + } else { |
|
| 155 | + return FALSE; |
|
| 156 | + } |
|
| 152 | 157 | } |
| 153 | 158 | |
| 154 | 159 | public function decrement($table, $field, $index, Array $condition, $operator, $decrement) |
@@ -161,9 +166,10 @@ discard block |
||
| 161 | 166 | $hs->decrement($idx, $operator, $condition, [$decrement]); |
| 162 | 167 | $result = $hs->readResponse(); |
| 163 | 168 | |
| 164 | - if (!empty($result)) |
|
| 165 | - return (bool)$result[0][0]; |
|
| 166 | - else |
|
| 167 | - return FALSE; |
|
| 169 | + if (!empty($result)) { |
|
| 170 | + return (bool)$result[0][0]; |
|
| 171 | + } else { |
|
| 172 | + return FALSE; |
|
| 173 | + } |
|
| 168 | 174 | } |
| 169 | 175 | } |
| 170 | 176 | \ No newline at end of file |
@@ -1,3 +1,3 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -$autoload = require __DIR__.'/../vendor/autoload.php'; |
|
| 4 | 3 | \ No newline at end of file |
| 4 | +$autoload = require __DIR__ . '/../vendor/autoload.php'; |
|
| 5 | 5 | \ No newline at end of file |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | { |
| 9 | 9 | $hs = new HSAL('localhost', 'hstest', HSAL::DRIVER_HSPHP); |
| 10 | 10 | |
| 11 | - $result = $hs->fetchArray('test', ['id','name','cnt'], [HSAL::INDEX_PRIMARY => 3]); |
|
| 11 | + $result = $hs->fetchArray('test', ['id', 'name', 'cnt'], [HSAL::INDEX_PRIMARY => 3]); |
|
| 12 | 12 | |
| 13 | 13 | $this->assertTrue(is_array($result)); |
| 14 | 14 | $this->assertEquals(3, count($result)); |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | { |
| 22 | 22 | $hs = new HSAL('localhost', 'hstest', HSAL::DRIVER_HSPHP); |
| 23 | 23 | |
| 24 | - $result = $hs->fetchArray('test', ['id','name','cnt'], [HSAL::INDEX_PRIMARY => 3]); |
|
| 24 | + $result = $hs->fetchArray('test', ['id', 'name', 'cnt'], [HSAL::INDEX_PRIMARY => 3]); |
|
| 25 | 25 | |
| 26 | 26 | $this->assertTrue(is_array($result)); |
| 27 | 27 | $this->assertEquals(3, count($result)); |