|
Server : LiteSpeed System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : outerorb ( 1091) PHP Version : 8.1.34 Disable Function : mail Directory : /home2/outerorb/crm.debtclearplans.co.uk/ | |
|
Path: /home2/outerorb/crm.debtclearplans.co.uk/bootstrap.php
Size: 3.53 KB
Permissions: 0666
<?php
declare(strict_types=1);
define('BASE_PATH', __DIR__);
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
spl_autoload_register(static function (string $className): void {
$prefix = 'App\\';
if (! str_starts_with($className, $prefix)) {
return;
}
$relativeClass = substr($className, strlen($prefix));
$path = BASE_PATH . '/app/' . str_replace('\\', '/', $relativeClass) . '.php';
if (is_file($path)) {
require $path;
}
});
function config(string $key, mixed $default = null): mixed
{
static $config = null;
if ($config === null) {
$config = array_merge(
require BASE_PATH . '/config/app.php',
['crm' => require BASE_PATH . '/config/crm.php']
);
}
$segments = explode('.', $key);
$value = $config;
foreach ($segments as $segment) {
if (! is_array($value) || ! array_key_exists($segment, $value)) {
return $default;
}
$value = $value[$segment];
}
return $value;
}
function asset(string $path): string
{
return base_path_url((string) config('app.asset_base', 'template-files') . '/' . ltrim($path, '/'));
}
function public_asset(string $path): string
{
return base_path_url('public-assets/' . ltrim($path, '/'));
}
function favicon_links(): string
{
$faviconPath = (string) config('app.favicon', 'img/dcp-favicon.png');
$faviconUrl = htmlspecialchars(public_asset($faviconPath), ENT_QUOTES, 'UTF-8');
return implode("\n", [
'<link rel="icon" type="image/png" href="' . $faviconUrl . '">',
'<link rel="shortcut icon" type="image/png" href="' . $faviconUrl . '">',
'<link rel="apple-touch-icon" href="' . $faviconUrl . '">',
]);
}
function url(string $route, array $params = []): string
{
$query = array_merge(['route' => $route], $params);
return base_path_url('index.php') . '?' . http_build_query($query);
}
function redirect(string $route, array $params = []): never
{
header('Location: ' . url($route, $params));
exit;
}
function e(?string $value): string
{
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
}
function request_value(string $key, mixed $default = null): mixed
{
return $_POST[$key] ?? $_GET[$key] ?? $default;
}
function csrf_token(): string
{
if (! isset($_SESSION['_csrf'])) {
$_SESSION['_csrf'] = bin2hex(random_bytes(32));
}
return $_SESSION['_csrf'];
}
function csrf_field(): string
{
return '<input type="hidden" name="_token" value="' . e(csrf_token()) . '">';
}
function verify_csrf(): void
{
$token = (string) ($_POST['_token'] ?? '');
if (! hash_equals((string) ($_SESSION['_csrf'] ?? ''), $token)) {
throw new RuntimeException('Your session token expired. Please retry the action.');
}
}
function app_base_path(): string
{
$scriptName = str_replace('\\', '/', (string) ($_SERVER['SCRIPT_NAME'] ?? '/index.php'));
$directory = str_replace('\\', '/', dirname($scriptName));
if ($directory === '/' || $directory === '.' || $directory === '\\') {
return '';
}
return rtrim($directory, '/');
}
function base_path_url(string $path = ''): string
{
$basePath = app_base_path();
$normalizedPath = ltrim($path, '/');
if ($normalizedPath === '') {
return $basePath === '' ? '/' : $basePath . '/';
}
return ($basePath === '' ? '' : $basePath) . '/' . $normalizedPath;
}