myPrayerJournal/src/start.php

38 lines
910 B
PHP
Raw Normal View History

2024-06-21 03:06:31 +00:00
<?php declare(strict_types=1);
2024-06-22 03:22:56 +00:00
use BitBadger\PDODocument\{Configuration, Definition, Mode};
2024-06-21 23:01:12 +00:00
use Dotenv\Dotenv;
2024-06-22 03:22:56 +00:00
use MyPrayerJournal\{Auth, Layout, Table};
2024-06-21 23:01:12 +00:00
require __DIR__ . '/vendor/autoload.php';
/** The version of this application */
const MPJ_VERSION = '4.0.0-alpha1';
(Dotenv::createImmutable(__DIR__))->load();
2024-06-22 16:30:26 +00:00
if (php_sapi_name() != 'cli') {
session_start();
$auth0_user = Auth::user();
if (!is_null($auth0_user)) {
$_SESSION['user_id'] = $auth0_user['sub'];
2024-06-22 16:30:26 +00:00
}
2024-06-21 23:01:12 +00:00
}
2024-06-22 03:22:56 +00:00
Configuration::$pdoDSN = 'sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'data', 'mpj.db']);
Configuration::$mode = Mode::SQLite;
Definition::ensureTable(Table::REQUEST);
$_PATCH = [];
if ($_SERVER['REQUEST_METHOD'] ?? '' == 'PATCH') parse_str(file_get_contents('php://input'), $_PATCH);
2024-06-21 23:01:12 +00:00
/**
* Return a 404 and exit
2024-06-21 23:01:12 +00:00
*/
function not_found(): never
2024-06-21 23:01:12 +00:00
{
http_response_code(404);
die('Not found');
2024-06-21 23:01:12 +00:00
}