Skip to content

Commit 29406a0

Browse files
committed
Merge branch '1.x' of github.com:hardeepvicky/Php-Query-Builder into 1.x
2 parents 6f1b3d2 + ffa0982 commit 29406a0

19 files changed

+1976
-817
lines changed

README.md

Lines changed: 398 additions & 19 deletions
Large diffs are not rendered by default.

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@
1919
},
2020
"minimum-stability" : "stable",
2121
"prefer-stable": true,
22-
"require-dev": {
23-
"symfony/var-dumper": "^6.3"
24-
}
22+
"require-dev": {}
2523
}

composer.lock

Lines changed: 2 additions & 237 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Where.php renamed to src/Condition.php

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
namespace HardeepVicky\QueryBuilder;
33

4-
class Where
4+
class Condition
55
{
6-
private $op = null, $fields = array(), $where_list = array();
6+
private $op = null, $fields = array(), $Condition_list = array();
77

88
/**
99
* @param String $op
@@ -16,11 +16,11 @@ public function __construct(String $op)
1616
/**
1717
* @param String $op
1818
*
19-
* @return Where
19+
* @return Condition
2020
*/
2121
public static function init(String $op)
2222
{
23-
return new Where($op);
23+
return new Condition($op);
2424
}
2525

2626
/**
@@ -29,7 +29,7 @@ public static function init(String $op)
2929
* @param String $operator
3030
* @param String $value_type
3131
*
32-
* @return Where
32+
* @return Condition
3333
*/
3434
public function add(String $field, $value, String $operator = "=", String $value_type = "string")
3535
{
@@ -158,7 +158,7 @@ private function _parseStringValue($value, $value_type = "string")
158158
* @param Array $arr
159159
* @param String $operator
160160
*
161-
* @return Where
161+
* @return Condition
162162
*/
163163
public function addList(Array $arr, String $operator = "=")
164164
{
@@ -171,13 +171,13 @@ public function addList(Array $arr, String $operator = "=")
171171
}
172172

173173
/**
174-
* @param Where $wh
174+
* @param Condition $wh
175175
*
176-
* @return Where
176+
* @return Condition
177177
*/
178-
public function addWhere(Where $wh)
178+
public function addCondition(Condition $wh)
179179
{
180-
$this->where_list[] = $wh;
180+
$this->Condition_list[] = $wh;
181181
return $this;
182182
}
183183

@@ -186,50 +186,41 @@ public function addWhere(Where $wh)
186186
*
187187
* @return String
188188
*/
189-
public function get(String $table = "")
189+
public function get(String $table_name = "")
190190
{
191-
$list = array();
191+
$list = [];
192192

193193
foreach($this->fields as $field)
194194
{
195195
if (strlen($field["value"]) > 0)
196196
{
197197
$key = $field["field"];
198198

199-
if ($table)
199+
if ($table_name)
200200
{
201-
$key = $table . "." . $key;
201+
$key = $table_name . "." . $key;
202202
}
203203

204204
if ($field["op"])
205205
{
206206
$key = $key . " " . $field["op"];
207207
}
208208

209-
$list[$key] = $field["value"];
209+
$list[] = $key . " " . $field["value"];
210210
}
211211
}
212212

213-
$list = $this->_listToStr($list);
214-
215-
foreach($this->where_list as $wh)
213+
foreach($this->Condition_list as $wh)
216214
{
217-
$list[] = $wh->get($table);
215+
$list[] = $wh->get($table_name);
218216
}
219-
220-
return "(" . implode($this->op, $list) . ")";
221-
}
222-
223-
private function _listToStr($data)
224-
{
225-
$list = array();
226-
227-
foreach($data as $k => $v)
217+
218+
if (empty($list))
228219
{
229-
$list[] = $k . " " . $v ;
220+
return "";
230221
}
231222

232-
return $list;
223+
return "(" . implode($this->op, $list) . ")";
233224
}
234225
}
235226

0 commit comments

Comments
 (0)