Skip to content

Commit 3652497

Browse files
author
Fredrick Peter
committed
Collection and Helpers
1 parent 7a47ff5 commit 3652497

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
],
1818
"require": {
1919
"php": ">=7.2.5",
20+
"psr/log": "^1.0 || ^1.1.4",
2021
"vlucas/phpdotenv": "^5.3",
2122
"ezyang/htmlpurifier": "^4.16.0",
22-
"symfony/var-dumper": "^4.4 || ^5 || ^6",
2323
"filp/whoops": "^2.15",
24-
"psr/log": "^1.0 || ^1.1.4"
24+
"kint-php/kint": "^5.0"
2525
},
2626
"autoload": {
2727
"files": [

src/Collections/CollectionMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct($items = [], mixed $key = 0, object $collection)
3737
$this->isPaginate = $collection->isPaginate;
3838
$this->pagination = $collection->pagination;
3939
$this->isProxyAllowed = $collection->isProxyAllowed;
40-
$this->items = $this->convertOnInit($items, true);
40+
$this->items = $this->convertOnInit($items);
4141
}
4242

4343
/**

src/Collections/Traits/CollectionTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait CollectionTrait{
2424
protected function wrapArrayIntoNewCollections()
2525
{
2626
// check if valid array data
27-
if (is_array($this->items) && count($this->items) > 0) {
27+
if (!$this->isProxyAllowed && is_array($this->items) && count($this->items) > 0) {
2828
return array_map(function ($item, $key){
2929
return new CollectionMapper($item, $key, $this);
3030
}, $this->items, array_keys($this->items));

src/Collections/Traits/RelatedTrait.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public function getPagination()
3535
}
3636

3737
/**
38-
* Get SQL Query
38+
* Dump SQL Query
3939
*
40-
* @return string|null
40+
* @return void
4141
*/
4242
public function toSql()
4343
{
@@ -47,9 +47,9 @@ public function toSql()
4747
}
4848

4949
/**
50-
* Dumb and Die
50+
* Dumb and Die\DbQuery
5151
*
52-
* @return mixed
52+
* @return void
5353
*/
5454
public function dd()
5555
{
@@ -246,19 +246,13 @@ private function isArray()
246246
/**
247247
* Convert data to an array on Initializaiton
248248
* @param mixed $items
249-
* @param bool $mapper
250249
*
251250
* @return array
252251
*/
253-
private function convertOnInit(mixed $items = null, ?bool $mapper = false)
252+
private function convertOnInit(mixed $items = null)
254253
{
255-
// on loop use
256-
// if $mapper === false then we return for proxy checks
257-
// else then it's for Mapper Collections
258-
$typePaginateOrProxy = !$mapper ? $this->isProxyAllowed : $this->isPaginate;
259-
260-
// first or insert request
261-
if ($typePaginateOrProxy || is_array($items)) {
254+
// For ORM Database Proxies Data
255+
if ($this->isProxyAllowed || $this->isPaginate || is_array($items)) {
262256
return json_decode(json_encode($items), true);
263257
} elseif($this->isValidJson($items)) {
264258
return json_decode($items, true);

src/Traits/ReusableTrait.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
namespace builder\Database\Traits;
66

7+
use Kint\Kint;
78
use Whoops\Run;
9+
use Kint\Renderer\RichRenderer;
810
use builder\Database\Capsule\Manager;
911
use Whoops\Handler\PrettyPageHandler;
10-
use Symfony\Component\VarDumper\VarDumper;
1112

1213
trait ReusableTrait{
1314

@@ -22,12 +23,15 @@ public function dump(...$data)
2223
// if DEBUG MODE IS ON
2324
if(Manager::setEnvBool(APP_DEBUG)){
2425
$dataArray = $data[0] ?? $data;
26+
RichRenderer::$folder = false;
27+
RichRenderer::$theme = 'solarized.css';
28+
2529
if(is_array($dataArray)){
2630
foreach ($dataArray as $var) {
27-
VarDumper::dump($var);
31+
Kint::dump($var);
2832
}
2933
} else{
30-
VarDumper::dump($dataArray);
34+
Kint::dump($dataArray);
3135
}
3236
}
3337
}

src/helpers.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,30 @@ function to_json(mixed $items)
400400
return json_encode( $items );
401401
}
402402
}
403+
404+
if (! function_exists('dump')) {
405+
/**
406+
* Dump Data
407+
* @param mixed $data
408+
*
409+
* @return void
410+
*/
411+
function dump(...$data)
412+
{
413+
env_orm()->dump($data);
414+
}
415+
}
416+
417+
if (! function_exists('dd')) {
418+
/**
419+
* Dump and Data
420+
* @param mixed $data
421+
*
422+
* @return void
423+
*/
424+
function dd(...$data)
425+
{
426+
env_orm()->dump($data);
427+
exit(1);
428+
}
429+
}

0 commit comments

Comments
 (0)