Skip to content

Commit

Permalink
🔀 Merge pull request #115 from leafsphp/v3.x-dev
Browse files Browse the repository at this point in the history
V3.x dev
  • Loading branch information
mychidarko authored Jan 27, 2022
2 parents f70cb43 + 4ebdc03 commit 3cec010
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 368 deletions.
58 changes: 29 additions & 29 deletions README.md

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"leafs/http": "^1.1",
"leafs/router": "^0.1.4",
"leafs/anchor": "^1.1"
"leafs/http": "^1.2",
"leafs/router": "^0.1.5",
"leafs/anchor": "^1.2",
"leafs/exception": "^3.0"
},
"require-dev": {
"pestphp/pest": "^1.21",
Expand All @@ -42,5 +43,10 @@
"scripts": {
"format": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist.php --allow-risky=yes",
"test": "vendor/bin/pest"
}
}
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
52 changes: 17 additions & 35 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* The easiest way to build simple but powerful apps and APIs quickly.
*
* @author Michael Darko <[email protected]>
* @copyright 2019-2021 Michael Darko
* @copyright 2019-2022 Michael Darko
* @link https://leafphp.dev
* @license MIT
* @package Leaf
Expand Down Expand Up @@ -70,16 +70,17 @@ public function __construct(array $userSettings = [])

protected function setupErrorHandler()
{
if ($this->config('debug')) {
$debugConfig = [E_ALL, 1, ['\Leaf\Exception\General', 'handleErrors'], false];
if ($this->config('debug') === true) {
$debugConfig = [E_ALL, 1];
$this->errorHandler = (new \Leaf\Exception\Run());
$this->errorHandler->register();
} else {
$debugConfig = [0, 0, ['\Leaf\Exception\General', 'defaultError'], true];
$debugConfig = [0, 0];
$this->setErrorHandler(['\Leaf\Exception\General', 'defaultError'], true);
}

error_reporting($debugConfig[0]);
ini_set('display_errors', (string) $debugConfig[1]);

$this->setErrorHandler($debugConfig[2], $debugConfig[3]);
}

/**
Expand All @@ -91,6 +92,15 @@ public function setErrorHandler($handler, bool $wrapper = true)
{
$errorHandler = $handler;

if ($this->errorHandler instanceof \Leaf\Exception\Run) {
$this->errorHandler->unregister();
}

if ($handler instanceof \Leaf\Exception\Handler\Handler) {
$this->errorHandler = new \Leaf\Exception\Run();
$this->errorHandler->pushHandler($handler)->register();
}

if ($wrapper) {
$errorHandler = function ($errno, $errstr = '', $errfile = '', $errline = '') use ($handler) {
$exception = Exception\General::toException($errno, $errstr, $errfile, $errline);
Expand Down Expand Up @@ -241,6 +251,7 @@ public function config($name, $value = null)
}

Config::set($name, $value);
$this->setupErrorHandler();
}

/********************************************************************************
Expand Down Expand Up @@ -361,35 +372,6 @@ public static function halt($status, $message = '')
exit();
}

/**
* Stop
*
* The thrown exception will be caught in application's `call()` method
* and the response will be sent as is to the HTTP client.
*
* @throws \Leaf\Exception\Stop
*/
public function stop()
{
throw new \Leaf\Exception\Stop();
}

/**
* Pass
*
* The thrown exception is caught in the application's `call()` method causing
* the router's current iteration to stop and continue to the subsequent route if available.
* If no subsequent matching routes are found, a 404 response will be sent to the client.
*
* @throws \Leaf\Exception\Pass
*/
public function pass()
{
$this->cleanBuffer();

throw new \Leaf\Exception\Pass();
}

/**
* Evade CORS errors
*
Expand Down
232 changes: 0 additions & 232 deletions src/Exception/General.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/Exception/Pass.php

This file was deleted.

19 changes: 0 additions & 19 deletions src/Exception/Stop.php

This file was deleted.

Loading

0 comments on commit 3cec010

Please sign in to comment.