Skip to content

Commit 98a5c0a

Browse files
author
Fredrick Peter
committed
Added Whoopsand Var-dumper Error Handler
1 parent c43bf35 commit 98a5c0a

File tree

16 files changed

+149
-230
lines changed

16 files changed

+149
-230
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Prior to installing `php-orm-database` get the [Composer](https://getcomposer.or
116116
**Step 1** — update your `composer.json`:
117117
```composer.json
118118
"require": {
119-
"peterson/php-orm-database": "^4.1.9"
119+
"peterson/php-orm-database": "^4.2.0"
120120
}
121121
```
122122

@@ -210,7 +210,6 @@ $db->table('users')
210210
|-------------------|-----------|-----------------------|
211211
| DRIVER_NAME | string | mysql |
212212
| APP_DEBUG | boolean | true |
213-
| APP_DEBUG_BG | string | Default value is `dark` and other color \| `light` |
214213
| DB_HOST | string | `localhost` |
215214
| DB_USERNAME | string | |
216215
| DB_PASSWORD | string | |
@@ -1462,9 +1461,10 @@ class PostClass extends DB{
14621461

14631462
## Error Dump
14641463

1465-
| function | Description |
1466-
|-----------|-----------------|
1467-
| dd | Dump or Die - Error handling |
1464+
| function | Description |
1465+
|-----------|-------------------|
1466+
| dump | Dump Data |
1467+
| dd | Dump and Die |
14681468

14691469

14701470
## Error Status

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"php": ">=7.2",
2020
"vlucas/phpdotenv": "^5.3",
2121
"ezyang/htmlpurifier": "^4.16.0",
22-
"tracy/tracy": "^2.9.1"
22+
"filp/whoops": "^2.15",
23+
"symfony/var-dumper": "^4.4"
2324
},
2425
"config": {
2526
"platform": {
@@ -42,7 +43,7 @@
4243
},
4344
"extra": {
4445
"branch-alias": {
45-
"dev-main": "4.1.9-dev"
46+
"dev-main": "4.2.0-dev"
4647
}
4748
},
4849
"minimum-stability": "stable",

src/Capsule/AppManager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ static public function envDummy()
3030
APP_ENV=local
3131
APP_KEY='. self::generateAppKey() .'
3232
APP_DEBUG=true
33-
APP_DEBUG_BG='. Manager::$default_bg .'
3433
SITE_EMAIL=
3534
3635
DRIVER_NAME=mysql

src/Capsule/Manager.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace builder\Database\Capsule;
66

7-
use Exception;
87
use builder\Database\Constants;
98

109

@@ -46,19 +45,6 @@ class Manager extends Constants{
4645
'bootstrap' => 'bootstrap',
4746
'simple' => 'simple',
4847
];
49-
50-
/**
51-
* @var array
52-
*/
53-
static private $disallow_method = [
54-
'errorTemp',
55-
'executeAction',
56-
'execute',
57-
'insert',
58-
'delete',
59-
'update',
60-
'select',
61-
];
6248

6349
/**
6450
* @var array
@@ -81,11 +67,6 @@ class Manager extends Constants{
8167
'utf8',
8268
'latin1',
8369
];
84-
85-
/**
86-
* @var string
87-
*/
88-
static public $default_bg = 'dark';
8970

9071
/**
9172
* Initilize and Set the Database Configuration on constructor
@@ -106,7 +87,6 @@ static public function initConfiguration(?array $options = [])
10687
{
10788
$defaultOption = array_merge([
10889
'APP_DEBUG' => true,
109-
'APP_DEBUG_BG' => self::$default_bg,
11090
'DRIVER_NAME' => 'mysql',
11191
'DB_HOST' => 'localhost',
11292
'DB_DATABASE' => '',
@@ -127,11 +107,6 @@ static public function initConfiguration(?array $options = [])
127107
define('APP_DEBUG', self::setEnvBool($_ENV['APP_DEBUG'] ?? $defaultOption['APP_DEBUG']));
128108
}
129109

130-
// APP_DEBUG_BG
131-
if ( ! defined('APP_DEBUG_BG') ) {
132-
define('APP_DEBUG_BG', $_ENV['APP_DEBUG_BG'] ?? $defaultOption['APP_DEBUG_BG']);
133-
}
134-
135110
// DRIVER_NAME
136111
if ( ! defined('DRIVER_NAME') ) {
137112
define('DRIVER_NAME', $_ENV['DRIVER_NAME'] ?? $defaultOption['DRIVER_NAME']);
@@ -184,7 +159,6 @@ static public function getConfig($key = 'DB_HOST')
184159
{
185160
$data = [
186161
'APP_DEBUG' => defined('APP_DEBUG') ? APP_DEBUG : true,
187-
'APP_DEBUG_BG' => defined('APP_DEBUG_BG') ? APP_DEBUG_BG : self::$default_bg,
188162
'DRIVER_NAME' => defined('DRIVER_NAME') ? DRIVER_NAME : 'mysql',
189163
'DB_HOST' => defined('DB_HOST') ? DB_HOST : 'localhost',
190164
'DB_DATABASE' => defined('DB_DATABASE') ? DB_DATABASE : null,

src/Collections/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Collection extends CollectionProperty implements IteratorAggregate, ArrayA
4242
public function __construct($items = [])
4343
{
4444
$this->unescapeIsObjectWithoutArray = self::checkProxiesType();
45-
$this->items = $this->getArrayItems($items);
45+
$this->items = $this->convertOnInit($items);
4646

4747
// if pagination request is `true`
4848
if(self::$is_paginate){

src/Collections/Traits/CollectionTrait.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ static protected function checkProxiesType()
4949
static protected function getTrace()
5050
{
5151
// get Trace
52-
$getTrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
52+
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
5353

5454
// instance functions
55-
$functions = array_map('strtolower', array_column($getTrace, 'function'));
55+
$functions = array_map('strtolower', array_column($backtrace, 'function'));
5656

5757
// get array interests
5858
$interest = array_intersect(self::$proxies_compact, $functions);
@@ -88,21 +88,4 @@ protected function wrapArrayIntoCollectionMappers(mixed $items)
8888
return $items;
8989
}
9090

91-
/**
92-
* Results array of items from Collection or Arrayable.
93-
*
94-
* @param mixed $items
95-
*
96-
* @return array
97-
*/
98-
protected function getArrayItems($items)
99-
{
100-
// first or insert request
101-
if ($this->unescapeIsObjectWithoutArray || !is_array($items)) {
102-
return $this->convertOnInit($items);
103-
}
104-
105-
return $items;
106-
}
107-
10891
}

src/Collections/Traits/RelatedTrait.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function has($key)
9090
return array_key_exists($key, $this->items);
9191
}
9292

93-
/**
93+
/**
9494
* Check if an item exists in the collection.
9595
*
9696
* @param string $key
@@ -229,9 +229,9 @@ private function convertMapperOnInit(mixed $items = null)
229229
{
230230
if (self::$is_paginate) {
231231
return json_decode(json_encode($items), true);
232-
} elseif ($this->isValidJson()) {
232+
} elseif ($this->isValidJson($items)) {
233233
return json_decode($items, true);
234-
} elseif (is_array($items) || is_string($items)) {
234+
} elseif (is_array($items)) {
235235
return $items;
236236
}
237237

@@ -246,16 +246,16 @@ private function convertMapperOnInit(mixed $items = null)
246246
*/
247247
private function convertOnInit(mixed $items = null)
248248
{
249+
// first or insert request
249250
if ($this->unescapeIsObjectWithoutArray) {
250-
if(!is_bool($items))
251-
return json_decode(json_encode($items), true);
252-
} elseif ($this->isValidJson()) {
251+
return json_decode(json_encode($items), true);
252+
} elseif($this->isValidJson($items)) {
253253
return json_decode($items, true);
254-
} elseif (is_array($items) || is_string($items)) {
254+
} elseif(is_array($items)){
255255
return $items;
256256
}
257257

258-
return (array) $items;
258+
return $items;
259259
}
260260

261261
/**

src/DB.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,27 @@
1212
*/
1313
namespace builder\Database;
1414

15-
use builder\Database\Query\MySqlExec;
1615
use builder\Database\Schema\Insertion;
16+
use builder\Database\Traits\DBSetupTrait;
1717

1818
class DB extends Insertion{
1919

20+
use DBSetupTrait;
21+
2022
/**
21-
* Extending Settings
23+
* Extending Constructor opitons if Available
24+
* - If User Extends the DB::Class and has their own __construct()
25+
* - They must call the parent::__construct();
26+
* - For Loaded Data to be returned
2227
*
23-
* @param array $options
28+
* @param array $options
2429
*/
25-
public function __construct(?array $options = []) {
26-
parent::__construct($options);
27-
28-
// configuring pagination settings
29-
if ( ! defined('PAGINATION_CONFIG') ) {
30-
$this->configPagination($options);
31-
} else{
32-
// if set to allow global use of ENV Autoloader Settings
33-
if(is_bool(PAGINATION_CONFIG['allow']) && PAGINATION_CONFIG['allow'] === true){
34-
$this->configPagination(PAGINATION_CONFIG);
35-
}else{
36-
$this->configPagination($options);
37-
}
30+
public function __construct(?array $options = [])
31+
{
32+
if (!$this->initialized) {
33+
$this->initializeSetup($options);
34+
$this->initialized = true;
3835
}
39-
40-
// open default logger
41-
(new MySqlExec)->autoStartDebugger();
4236
}
37+
4338
}

src/EnvAutoLoad.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class EnvAutoLoad{
1717
*
1818
* @param array $options
1919
* path \Path to .env file
20-
* bg \dump background color (light | dark)
2120
*
2221
* @return void
2322
*/
@@ -30,7 +29,6 @@ static public function start(?array $options = [])
3029
*/
3130
$default = array_merge([
3231
'path' => null,
33-
'bg' => Manager::$default_bg,
3432
], $options);
3533

3634
/*
@@ -56,30 +54,6 @@ static public function start(?array $options = [])
5654
*/
5755
$loader = $EnvOrm::loadOrFail();
5856

59-
/*
60-
|--------------------------------------------------------------------------
61-
| Defining background color for var dump
62-
|--------------------------------------------------------------------------
63-
| default | main | dark | red | blue
64-
*/
65-
$EnvOrm->{'bg'} = $default['bg'];
66-
67-
/*
68-
|--------------------------------------------------------------------------
69-
| Update ENV variable
70-
|--------------------------------------------------------------------------
71-
| Here we do not want to temper with the environment file always
72-
| - Since this path will always run at every application call
73-
| - We only will update APP_DEBUG_BG if env path is set and
74-
| - If the APP_DEBUG_BG is empty
75-
|
76-
*/
77-
if(isset($_ENV['APP_DEBUG_BG'])){
78-
if(empty($_ENV['APP_DEBUG_BG'])){
79-
$EnvOrm::updateENV('APP_DEBUG_BG', $EnvOrm->{'bg'}, false);
80-
}
81-
}
82-
8357
/*
8458
|--------------------------------------------------------------------------
8559
| Check If There was an error getting the environment file
@@ -90,11 +64,6 @@ static public function start(?array $options = [])
9064
|
9165
*/
9266
if($loader['status'] != 200){
93-
/**
94-
* Setting application to use the dump error handling
95-
*/
96-
$EnvOrm->dump_final = false;
97-
9867
/**
9968
* Dump error message
10069
*/

0 commit comments

Comments
 (0)