-
Notifications
You must be signed in to change notification settings - Fork 0
/
Run.php
executable file
·69 lines (58 loc) · 1.81 KB
/
Run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* @Package: MaplePHP - Error handler framework
* @Author: Daniel Ronkainen
* @Licence: Apache-2.0 license, Copyright © Daniel Ronkainen
Don't delete this comment, its part of the license.
*/
namespace MaplePHP\Blunder;
use MaplePHP\Blunder\Interfaces\HandlerInterface;
use MaplePHP\Blunder\Interfaces\HttpMessagingInterface;
use Closure;
class Run
{
private HandlerInterface $handler;
private ?SeverityLevelPool $severity = null;
public function __construct(HandlerInterface $handler, ?HttpMessagingInterface $http = null)
{
$this->handler = $handler;
if(!is_null($http)) {
$this->handler->setHttp($http);
}
}
/**
* Access severity instance to set or exclude severity levels from error handler
* @return SeverityLevelPool
*/
public function severity(): SeverityLevelPool
{
if(is_null($this->severity)) {
$this->severity = new SeverityLevelPool();
}
return $this->severity;
}
/**
* The event callable will be triggered when an error occur.
* Note: Will add PSR-14 support for dispatch in the future.
* @param Closure $event
* @return void
*/
public function event(Closure $event): void
{
$this->handler->event($event);
}
/**
* Init the handlers
* @return void
*/
public function load(): void
{
if (!headers_sent()) {
header_remove('location');
}
$this->handler->setSeverity($this->severity()->getSeverityLevelMask());
set_error_handler([$this->handler, "errorHandler"], $this->severity()->getSeverityLevelMask());
set_exception_handler([$this->handler, "exceptionHandler"]);
register_shutdown_function([$this->handler, "shutdownHandler"]);
}
}