marcolamr /
whoops
| 1 | <?php |
||||||||
| 2 | |||||||||
| 3 | namespace MarcolaMr\Whoops; |
||||||||
| 4 | |||||||||
| 5 | use Whoops\Handler\JsonResponseHandler; |
||||||||
| 6 | use Whoops\Handler\PlainTextHandler; |
||||||||
| 7 | use Whoops\Handler\PrettyPageHandler; |
||||||||
| 8 | use Whoops\Handler\XmlResponseHandler; |
||||||||
| 9 | use Whoops\Run; |
||||||||
| 10 | |||||||||
| 11 | class ErrorHandler |
||||||||
| 12 | {
|
||||||||
| 13 | /** @var string */ |
||||||||
| 14 | private $handler; |
||||||||
| 15 | |||||||||
| 16 | /** @var Run */ |
||||||||
| 17 | private $whoops; |
||||||||
| 18 | |||||||||
| 19 | /** @var PrettyPageHandler | JsonResponseHandler | XmlResponseHandler | PlainTextHandler */ |
||||||||
| 20 | private $errorHandler; |
||||||||
| 21 | |||||||||
| 22 | public function __construct($handler = "html", string $pageTitle = "Whoops! There was an error.", array $data = []) |
||||||||
| 23 | {
|
||||||||
| 24 | $this->handler = $handler; |
||||||||
| 25 | $this->whoops = new Run(); |
||||||||
| 26 | $this->setHandler(); |
||||||||
| 27 | $this->setPageTitle($pageTitle); |
||||||||
| 28 | $this->setData("Extra Information", $data);
|
||||||||
| 29 | $this->register(); |
||||||||
| 30 | } |
||||||||
| 31 | |||||||||
| 32 | private function register() |
||||||||
| 33 | {
|
||||||||
| 34 | $this->whoops->pushHandler($this->errorHandler); |
||||||||
| 35 | $this->whoops->register(); |
||||||||
| 36 | } |
||||||||
| 37 | |||||||||
| 38 | private function setPageTitle(string $pageTitle): void |
||||||||
| 39 | {
|
||||||||
| 40 | if ($this->handler === "html" && !empty($pageTitle)) {
|
||||||||
| 41 | $this->errorHandler->setPageTitle($pageTitle); |
||||||||
|
0 ignored issues
–
show
The method
setPageTitle() does not exist on Whoops\Handler\PlainTextHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
The method
setPageTitle() does not exist on Whoops\Handler\XmlResponseHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||||
| 42 | } |
||||||||
| 43 | } |
||||||||
| 44 | |||||||||
| 45 | private function setData(string $label, array $data): void |
||||||||
| 46 | {
|
||||||||
| 47 | if ($this->handler === "html" && !empty($label) && !empty($data)) {
|
||||||||
| 48 | $this->errorHandler->addDataTable($label, $data); |
||||||||
|
0 ignored issues
–
show
The method
addDataTable() does not exist on Whoops\Handler\XmlResponseHandler. Did you maybe mean addDataToNode()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
The method
addDataTable() does not exist on Whoops\Handler\JsonResponseHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
The method
addDataTable() does not exist on Whoops\Handler\PlainTextHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||||
| 49 | } |
||||||||
| 50 | } |
||||||||
| 51 | |||||||||
| 52 | private function setHandler(): void |
||||||||
| 53 | {
|
||||||||
| 54 | switch ($this->handler) {
|
||||||||
| 55 | case 'json': |
||||||||
| 56 | $this->errorHandler = new JsonResponseHandler(); |
||||||||
| 57 | break; |
||||||||
| 58 | |||||||||
| 59 | case 'xml': |
||||||||
| 60 | $this->errorHandler = new XmlResponseHandler(); |
||||||||
| 61 | break; |
||||||||
| 62 | |||||||||
| 63 | case 'txt': |
||||||||
| 64 | $this->errorHandler = new PlainTextHandler(); |
||||||||
| 65 | break; |
||||||||
| 66 | |||||||||
| 67 | default: |
||||||||
| 68 | $this->errorHandler = new PrettyPageHandler(); |
||||||||
| 69 | break; |
||||||||
| 70 | } |
||||||||
| 71 | } |
||||||||
| 72 | } |
||||||||
| 73 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.