1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of template |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Slick\Template\UserInterface; |
13
|
|
|
|
14
|
|
|
use Slick\ErrorHandler\Exception\ExceptionInspector; |
15
|
|
|
use Slick\ErrorHandler\Handler\HandlerInterface; |
16
|
|
|
use Slick\ErrorHandler\RunnerInterface; |
17
|
|
|
use Slick\Template\Engine\TwigTemplateEngine; |
18
|
|
|
use Slick\Template\TemplateEngineInterface; |
19
|
|
|
use Throwable; |
20
|
|
|
use Twig\Environment; |
21
|
|
|
use Twig\Extension\DebugExtension; |
22
|
|
|
use Twig\Extra\Markdown\MarkdownExtension; |
23
|
|
|
use Twig\Loader\FilesystemLoader; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* PrettyErrorHandler |
27
|
|
|
* |
28
|
|
|
* @package Slick\Template\UserInterface |
29
|
|
|
*/ |
30
|
|
|
final class PrettyErrorHandler implements HandlerInterface |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
public function __construct(private readonly TemplateEngineInterface $engine) |
34
|
|
|
{ |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function create(): static |
38
|
|
|
{ |
39
|
|
|
$path = dirname(dirname(__DIR__)) . '/templates'; |
40
|
|
|
$loader = new FilesystemLoader([$path]); |
41
|
|
|
$twig = new Environment($loader, ['cache' => false, 'debug' => true]); |
42
|
|
|
$twig->addExtension(new DebugExtension()); |
43
|
|
|
$twig->addExtension(new MarkdownExtension()); |
44
|
|
|
$templateEngine = new TwigTemplateEngine($twig); |
45
|
|
|
|
46
|
|
|
return new static($templateEngine); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function handle(Throwable $throwable, ExceptionInspector $inspector, RunnerInterface $runner): ?int |
50
|
|
|
{ |
51
|
|
|
$handler = $this; |
52
|
|
|
$runner->sendResponseCode($inspector->statusCode()); |
|
|
|
|
53
|
|
|
|
54
|
|
|
echo $this->engine |
55
|
|
|
->parse('errors/exception.twig') |
56
|
|
|
->process(compact('throwable', 'inspector', 'runner', 'handler')); |
57
|
|
|
return self::QUIT; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function functionCall(Throwable $throwable, int $key): string |
61
|
|
|
{ |
62
|
|
|
$lines = explode("#", $throwable->getTraceAsString()); |
63
|
|
|
$line = $lines[$key]; |
64
|
|
|
$parts = explode(":", $line); |
65
|
|
|
return trim(end($parts)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function version(): string |
69
|
|
|
{ |
70
|
|
|
$composerFile = dirname(__DIR__, 2) . '/webstack/composer.json'; |
71
|
|
|
$file = is_file($composerFile) |
72
|
|
|
? $composerFile |
73
|
|
|
: dirname(dirname(__DIR__)) . '/vendor/slick/webstack/composer.json'; |
74
|
|
|
|
75
|
|
|
$composer = json_decode(file_get_contents($file)); |
76
|
|
|
return $composer->version; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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.