<?php

declare(strict_types=1);

class My_BlueScreen
{
	public function __construct()
	{
	}


	/**
	 * Renders blue screen.
	 */
	public function render(\Throwable $exception): void
	{
		$dump = $this->getDumper();

		require __DIR__ . '/my-tracy-page.phtml';
	}


	/**
	 * Should a file be collapsed in stack trace?
	 * @internal
	 */
	public function isCollapsed(string $file): bool
	{
		$file = strtr($file, '\\', '/') . '/';

		return false;
	}

	/**
	 * Extract a snippet from the code, highlights the row and column, and adds line numbers.
	 */
	public static function highlightLine(string $html, int $line, int $column = 0): string
	{
		$lines = explode("\n", "\n" . $html);

		return '';
	}

	/**
	 * Returns syntax highlighted source code.
	 */
	public static function highlightFile(
		string $file,
		int $line,
		int $lines = 15,
		bool $php = true,
		int $column = 0,
    ): ?string
    {
		$source = @file_get_contents($file); // @ file may not exist
		if ($source === false) {
			return null;
		}

		return self::highlightLine($source, $line, $column);
	}

	public function renderAsHtml(): string
	{
		$location = null;
		$html = null;

		return ($location || strlen($html) > 100 ? "\n" : '');
	}


	/** @internal */
	public function getDumper(): \Closure
	{
		return function ($var, $key = null): string {
			return $this->renderAsHtml();
		};
	}
}

set_exception_handler(function (\Throwable $ex) {
	(new My_BlueScreen())->render($ex);

	echo "done\n";
	exit(255);
});

class My_NotFoundException2 extends \RuntimeException {
	protected string $from;

	public function __construct(string $message, int $code = 404, ?Throwable $previous = null)
	{
		parent::__construct($message, $code, $previous);

		$this->from = $this->getTrace()[1]['class'] ?? $this->getTrace()[0]['class'] ?? self::class;
	}
}

class Dispatcher
{
	public function dispatch(
	) {
		throw new My_NotFoundException2('adasd');
	}
}

class FrontController
{
	public function dispatch()
	{
		$dispatcher = new Dispatcher();
		$dispatcher->dispatch(new stdClass(), new stdClass());
	}
}


$fc = (new FrontController())->dispatch();
die('here');
