-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.php
50 lines (43 loc) · 1000 Bytes
/
utils.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
<?php
function dump($value): void
{
echo '<pre>';
var_dump($value);
echo '</pre>';
}
function dd($value): void
{
dump($value);
die();
}
//function base_path(string $base_relative_path): string
//{
// return BASE_PATH . $base_relative_path;
//}
//function view(string $path, array $view_data = []): void
//{
// extract($view_data);
// require BASE_PATH . 'views/' . $path;
//}
function abort(int $response_code): void
{
http_response_code($response_code);
require "views/$response_code.php";
die();
}
function require_auth(string $message, string $redirect_path = '/login'): void
{
if (!isset($_SESSION['user_id'])) {
http_response_code(StatusCode::UNAUTHORIZED_401);
$_SESSION['auth_error'] = $message;
header("Location: $redirect_path");
die();
}
}
function redirect(string $path, string $message = null): void
{
if ($message) {
$_SESSION['flash'] = $message;
}
header("Location: $path");
}