Files
HexaHost-Web-Prod/public/bootstrap.php

74 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* HexaHost Bootstrap (gleiches Prinzip wie dev-Branch: backend/ zuerst)
*
* Priorität (wie Deploy auf dev.hexahost.de):
* 1. ../backend/{includes,config} Monorepo / Dev-Server
* 2. public/{includes,config} Prod nur mit Webroot public/
* 3. Hybrid (includes/config gemischt)
*/
if (!defined('HEXAHOST_BOOTSTRAPPED')) {
function hexahost_path_candidates(): array
{
$backendIncludes = dirname(__DIR__) . '/backend/includes';
$backendConfig = dirname(__DIR__) . '/backend/config';
$publicIncludes = __DIR__ . '/includes';
$publicConfig = __DIR__ . '/config';
return [
['includes' => $backendIncludes, 'config' => $backendConfig],
['includes' => $publicIncludes, 'config' => $publicConfig],
['includes' => $publicIncludes, 'config' => $backendConfig],
['includes' => $backendIncludes, 'config' => $publicConfig],
];
}
function hexahost_is_app_root_valid(string $includesDir, string $configDir): bool
{
$required = [
$includesDir . '/functions.php',
$includesDir . '/header.php',
$includesDir . '/footer.php',
$configDir . '/products-config.php',
];
foreach ($required as $file) {
if (!is_file($file)) {
return false;
}
}
return true;
}
$resolved = false;
foreach (hexahost_path_candidates() as $paths) {
if (!hexahost_is_app_root_valid($paths['includes'], $paths['config'])) {
continue;
}
define('HEXAHOST_INCLUDES_DIR', $paths['includes']);
define('HEXAHOST_CONFIG_DIR', $paths['config']);
require_once $paths['includes'] . '/functions.php';
$resolved = true;
break;
}
if (!$resolved) {
http_response_code(500);
header('Content-Type: text/html; charset=utf-8');
echo '<!DOCTYPE html><html lang="de"><head><meta charset="utf-8"><title>HexaHost</title></head><body>';
echo '<h1>HexaHost: Seite konnte nicht geladen werden</h1>';
echo '<p>PHP konnte die Anwendungsdateien nicht finden.</p>';
echo '<p><strong>Dev-Branch:</strong> Repository mit Ordner <code>backend/</code> neben <code>public/</code> deployen.</p>';
echo '<p><strong>Produktion:</strong> Vor dem Upload <code>scripts/sync-backend-to-public.ps1</code> ausführen ';
echo 'oder <code>backend/includes</code> und <code>backend/config</code> nach <code>public/</code> kopieren.</p>';
echo '</body></html>';
exit;
}
define('HEXAHOST_BOOTSTRAPPED', true);
}