summaryrefslogtreecommitdiff
path: root/src/web/lib/hooks.php
blob: a688069216b795cda047da04efb61e44d0a0713e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php /* Copyright (c) 2024 Freya Murphy */

function load_htc(string $file) {
	$file_path = PUBLIC_ROOT . '/polyfills/' . $file;
	if (!file_exists($file_path))
		return;

	header('Content-type: text/x-component');
	include($file_path);
	CRIMSON_DIE();
}

function CRIMSON_pre_route_hook(Router $router): void {
	$uri_str = ROUTER->req['uri_str'] ?? '';
	$file = basename($uri_str);
	if (str_ends_with($file, '.htc'))
		load_htc($file);
}

function CRIMSON_error_hook(?array $req, int $code): never {
	$error_controller = ROUTER->load_controller('error');
	$error_controller->code($code);
	CRIMSON_DIE();
}