@@ -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) |
@@ -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(); |
@@ -53,10 +53,11 @@ discard block |
||
53 | 53 | $hs->select($idx, $operator, $condition); |
54 | 54 | $result = $hs->readResponse(); |
55 | 55 | |
56 | - if (!empty($result)) |
|
57 | - return $result[0]; |
|
58 | - else |
|
59 | - return FALSE; |
|
56 | + if (!empty($result)) { |
|
57 | + return $result[0]; |
|
58 | + } else { |
|
59 | + return FALSE; |
|
60 | + } |
|
60 | 61 | } |
61 | 62 | |
62 | 63 | public function fetchAll($table, Array $fields, $index, Array $condition, $operator, $limit, $offset) |
@@ -78,9 +79,9 @@ discard block |
||
78 | 79 | } |
79 | 80 | |
80 | 81 | return $result; |
82 | + } else { |
|
83 | + return FALSE; |
|
81 | 84 | } |
82 | - else |
|
83 | - return FALSE; |
|
84 | 85 | } |
85 | 86 | |
86 | 87 | public function delete($table, $index, Array $condition, $operator) |
@@ -93,10 +94,11 @@ discard block |
||
93 | 94 | $hs->delete($idx, $operator, $condition); |
94 | 95 | $result = $hs->readResponse(); |
95 | 96 | |
96 | - if (!empty($result)) |
|
97 | - return (bool)$result[0][0]; |
|
98 | - else |
|
99 | - return FALSE; |
|
97 | + if (!empty($result)) { |
|
98 | + return (bool)$result[0][0]; |
|
99 | + } else { |
|
100 | + return FALSE; |
|
101 | + } |
|
100 | 102 | } |
101 | 103 | |
102 | 104 | public function insert($table, Array $values) |
@@ -128,10 +130,11 @@ discard block |
||
128 | 130 | |
129 | 131 | $result = $hs->readResponse(); |
130 | 132 | |
131 | - if (!empty($result)) |
|
132 | - return (bool)$result[0][0]; |
|
133 | - else |
|
134 | - return FALSE; |
|
133 | + if (!empty($result)) { |
|
134 | + return (bool)$result[0][0]; |
|
135 | + } else { |
|
136 | + return FALSE; |
|
137 | + } |
|
135 | 138 | } |
136 | 139 | |
137 | 140 | public function increment($table, $field, $index, Array $condition, $operator, $increment) |
@@ -144,10 +147,11 @@ discard block |
||
144 | 147 | $hs->increment($idx, $operator, $condition, [$increment]); |
145 | 148 | $result = $hs->readResponse(); |
146 | 149 | |
147 | - if (!empty($result)) |
|
148 | - return (bool)$result[0][0]; |
|
149 | - else |
|
150 | - return FALSE; |
|
150 | + if (!empty($result)) { |
|
151 | + return (bool)$result[0][0]; |
|
152 | + } else { |
|
153 | + return FALSE; |
|
154 | + } |
|
151 | 155 | } |
152 | 156 | |
153 | 157 | public function decrement($table, $field, $index, Array $condition, $operator, $decrement) |
@@ -160,9 +164,10 @@ discard block |
||
160 | 164 | $hs->decrement($idx, $operator, $condition, [$decrement]); |
161 | 165 | $result = $hs->readResponse(); |
162 | 166 | |
163 | - if (!empty($result)) |
|
164 | - return (bool)$result[0][0]; |
|
165 | - else |
|
166 | - return FALSE; |
|
167 | + if (!empty($result)) { |
|
168 | + return (bool)$result[0][0]; |
|
169 | + } else { |
|
170 | + return FALSE; |
|
171 | + } |
|
167 | 172 | } |
168 | 173 | } |
169 | 174 | \ 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->fetchAssoc('test', ['id','name','cnt'], [HSAL::INDEX_PRIMARY => 3]); |
|
24 | + $result = $hs->fetchAssoc('test', ['id', 'name', 'cnt'], [HSAL::INDEX_PRIMARY => 3]); |
|
25 | 25 | |
26 | 26 | $this->assertTrue(is_array($result)); |
27 | 27 | $this->assertEquals(3, count($result)); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | { |
9 | 9 | $hs = new HSAL('localhost', 'hstest', HSAL::DRIVER_HANDLERSOCKETI); |
10 | 10 | |
11 | - $result = $hs->fetchArray('test2', ['id','name','cnt'], [HSAL::INDEX_PRIMARY => 3]); |
|
11 | + $result = $hs->fetchArray('test2', ['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_HANDLERSOCKETI); |
23 | 23 | |
24 | - $result = $hs->fetchAssoc('test2', ['id','name','cnt'], [HSAL::INDEX_PRIMARY => 3]); |
|
24 | + $result = $hs->fetchAssoc('test2', ['id', 'name', 'cnt'], [HSAL::INDEX_PRIMARY => 3]); |
|
25 | 25 | |
26 | 26 | $this->assertTrue(is_array($result)); |
27 | 27 | $this->assertEquals(3, count($result)); |
@@ -23,6 +23,10 @@ discard block |
||
23 | 23 | const INDEX_PRIMARY = ''; |
24 | 24 | |
25 | 25 | |
26 | + /** |
|
27 | + * @param string $host |
|
28 | + * @param string $database |
|
29 | + */ |
|
26 | 30 | public function __construct($host, $database, Array $options = NULL) |
27 | 31 | { |
28 | 32 | if (!extension_loaded('handlersocketi') && (!class_exists('\\HSPHP\\ReadSocket'))) |
@@ -64,6 +68,9 @@ discard block |
||
64 | 68 | } |
65 | 69 | |
66 | 70 | |
71 | + /** |
|
72 | + * @param string $table |
|
73 | + */ |
|
67 | 74 | public function fetchArray($table, Array $fields, Array $index_condition, $operator = HSAL::OPERATOR_EQUAL) |
68 | 75 | { |
69 | 76 | list($index, $condition) = self::parse_index_condition($index_condition); |
@@ -71,6 +78,9 @@ discard block |
||
71 | 78 | return $this->hs->fetchArray($table, $fields, $index, $condition, $operator); |
72 | 79 | } |
73 | 80 | |
81 | + /** |
|
82 | + * @param string $table |
|
83 | + */ |
|
74 | 84 | public function fetchAssoc($table, Array $fields, Array $index_condition, $operator = HSAL::OPERATOR_EQUAL) |
75 | 85 | { |
76 | 86 | list($index, $condition) = self::parse_index_condition($index_condition); |
@@ -78,6 +88,10 @@ discard block |
||
78 | 88 | return $this->hs->fetchAssoc($table, $fields, $index, $condition, $operator); |
79 | 89 | } |
80 | 90 | |
91 | + /** |
|
92 | + * @param string $table |
|
93 | + * @param string $field |
|
94 | + */ |
|
81 | 95 | public function fetchColumn($table, $field, Array $index_condition, $operator = HSAL::OPERATOR_EQUAL) |
82 | 96 | { |
83 | 97 | list($index, $condition) = self::parse_index_condition($index_condition); |
@@ -85,6 +99,9 @@ discard block |
||
85 | 99 | return $this->hs->fetchColumn($table, $field, $index, $condition, $operator); |
86 | 100 | } |
87 | 101 | |
102 | + /** |
|
103 | + * @param string $table |
|
104 | + */ |
|
88 | 105 | public function fetchAll($table, Array $fields, Array $index_condition, $operator = HSAL::OPERATOR_EQUAL, $limit = 1000, $offset = 0) |
89 | 106 | { |
90 | 107 | list($index, $condition) = self::parse_index_condition($index_condition); |
@@ -92,6 +109,9 @@ discard block |
||
92 | 109 | return $this->hs->fetchAll($table, $fields, $index, $condition, $operator, $limit, $offset); |
93 | 110 | } |
94 | 111 | |
112 | + /** |
|
113 | + * @param string $table |
|
114 | + */ |
|
95 | 115 | public function delete($table, Array $index_condition, $operator = HSAL::OPERATOR_EQUAL) |
96 | 116 | { |
97 | 117 | list($index, $condition) = self::parse_index_condition($index_condition); |
@@ -99,11 +119,17 @@ discard block |
||
99 | 119 | return $this->hs->delete($table, $index, $condition, $operator); |
100 | 120 | } |
101 | 121 | |
122 | + /** |
|
123 | + * @param string $table |
|
124 | + */ |
|
102 | 125 | public function insert($table, Array $values) |
103 | 126 | { |
104 | 127 | return $this->hs->insert($table, $values); |
105 | 128 | } |
106 | 129 | |
130 | + /** |
|
131 | + * @param string $table |
|
132 | + */ |
|
107 | 133 | public function update($table, Array $values, Array $index_condition, $operator = HSAL::OPERATOR_EQUAL) |
108 | 134 | { |
109 | 135 | list($index, $condition) = self::parse_index_condition($index_condition); |
@@ -111,6 +137,10 @@ discard block |
||
111 | 137 | return $this->hs->update($table, $values, $index, $condition, $operator); |
112 | 138 | } |
113 | 139 | |
140 | + /** |
|
141 | + * @param string $table |
|
142 | + * @param string $field |
|
143 | + */ |
|
114 | 144 | public function increment($table, $field, Array $index_condition, $operator = HSAL::OPERATOR_EQUAL, $increment = 1) |
115 | 145 | { |
116 | 146 | list($index, $condition) = self::parse_index_condition($index_condition); |
@@ -118,6 +148,10 @@ discard block |
||
118 | 148 | return $this->hs->increment($table, $field, $index, $condition, $operator, $increment); |
119 | 149 | } |
120 | 150 | |
151 | + /** |
|
152 | + * @param string $table |
|
153 | + * @param string $field |
|
154 | + */ |
|
121 | 155 | public function decrement($table, $field, Array $index_condition, $operator = HSAL::OPERATOR_EQUAL, $decrement = 1) |
122 | 156 | { |
123 | 157 | list($index, $condition) = self::parse_index_condition($index_condition); |
@@ -34,8 +34,9 @@ discard block |
||
34 | 34 | |
35 | 35 | if (!empty($options)) |
36 | 36 | { |
37 | - if (isset($options['driver'])) |
|
38 | - $driver = $options['driver']; |
|
37 | + if (isset($options['driver'])) { |
|
38 | + $driver = $options['driver']; |
|
39 | + } |
|
39 | 40 | } |
40 | 41 | |
41 | 42 | if ($driver == self::DRIVER_AUTO) |
@@ -43,8 +44,7 @@ discard block |
||
43 | 44 | if (extension_loaded('handlersocketi')) |
44 | 45 | { |
45 | 46 | $driver = self::DRIVER_HANDLERSOCKETI; |
46 | - } |
|
47 | - else if (class_exists('\\HSPHP\\ReadSocket')) |
|
47 | + } else if (class_exists('\\HSPHP\\ReadSocket')) |
|
48 | 48 | { |
49 | 49 | $driver = self::DRIVER_HSPHP; |
50 | 50 | } |
@@ -53,8 +53,7 @@ discard block |
||
53 | 53 | if ($driver == self::DRIVER_HANDLERSOCKETI) |
54 | 54 | { |
55 | 55 | $this->hs = new \HSAL\Driver\Handlersocketi($host, $database, $options); |
56 | - } |
|
57 | - else if ($driver == self::DRIVER_HSPHP) |
|
56 | + } else if ($driver == self::DRIVER_HSPHP) |
|
58 | 57 | { |
59 | 58 | $this->hs = new \HSAL\Driver\HSPHP($host, $database, $options); |
60 | 59 | } |