Skip to content

Commit 44f3bcf

Browse files
committed
made ArrayBuilder(), ObjectBuilder(), JsonBuilder private to be able to use it on a created object
1 parent 62ad414 commit 44f3bcf

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

dbObject.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* @version 2.2
1212
*
1313
* @method int count ()
14+
* @method dbObject ArrayBuilder()
15+
* @method dbObject JsonBuilder()
16+
* @method dbObject ObjectBuilder()
1417
* @method mixed byId (string $id, mixed $fields)
1518
* @method mixed get (mixed $limit, mixed $fields)
1619
* @method mixed getOne (mixed $fields)
@@ -181,21 +184,19 @@ public function __unset ($name) {
181184
*
182185
* @return dbObject
183186
*/
184-
public static function JsonBuilder () {
185-
$obj = new static;
186-
$obj->returnType = 'Json';
187-
return $obj;
187+
private function JsonBuilder () {
188+
$this->returnType = 'Json';
189+
return $return;
188190
}
189191

190192
/**
191193
* Helper function to create dbObject with Array return type
192194
*
193195
* @return dbObject
194196
*/
195-
public static function ArrayBuilder () {
196-
$obj = new static;
197-
$obj->returnType = 'Array';
198-
return $obj;
197+
private function ArrayBuilder () {
198+
$this->returnType = 'Array';
199+
return $this;
199200
}
200201

201202
/**
@@ -204,8 +205,9 @@ public static function ArrayBuilder () {
204205
*
205206
* @return dbObject
206207
*/
207-
public static function ObjectBuilder () {
208-
return new static;
208+
private function ObjectBuilder () {
209+
$this->returnType = 'Object';
210+
return $this;
209211
}
210212

211213
/**

tests/dbObjectTests.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ function createTable ($name, $data) {
141141
exit;
142142
}
143143

144+
$products = product::with('userId')->ArrayBuilder()->get(2);
145+
if (!is_array ($products[0]['userId']) || !is_array ($products[1]['userId'])) {
146+
echo "Error in with processing in get";
147+
exit;
148+
}
149+
144150
$depts = product::join('user')->orderBy('`products`.id', 'desc')->get(5);
145151
foreach ($depts as $d) {
146152
if (!is_object($d)) {

0 commit comments

Comments
 (0)