Update PHP version to 8.4 and add property hooks
This commit is contained in:
parent
32449d2edd
commit
673c02d237
14 changed files with 939 additions and 606 deletions
|
|
@ -1,38 +1,52 @@
|
|||
<?php
|
||||
|
||||
// Load configuration
|
||||
$configFile = file_exists(__DIR__ . '/../custom/config.ini')
|
||||
? __DIR__ . '/../custom/config.ini'
|
||||
: __DIR__ . '/config.ini';
|
||||
$config = parse_ini_file($configFile, true);
|
||||
function createContext(): Context {
|
||||
// Load configuration
|
||||
$configFile = file_exists(__DIR__ . '/../custom/config.ini')
|
||||
? __DIR__ . '/../custom/config.ini'
|
||||
: __DIR__ . '/config.ini';
|
||||
$config = parse_ini_file($configFile, true);
|
||||
|
||||
$defaultLang = $config['languages']['default'] ?? 'no';
|
||||
$availableLangs = array_map('trim', explode(',', $config['languages']['available'] ?? 'no'));
|
||||
$defaultLang = $config['languages']['default'] ?? 'no';
|
||||
$availableLangs = array_map('trim', explode(',', $config['languages']['available'] ?? 'no'));
|
||||
|
||||
// Use user content if exists and has content, otherwise fall back to demo content
|
||||
$userContentDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
$demoContentDir = __DIR__ . '/default/content';
|
||||
// Use user content if exists and has content, otherwise fall back to demo content
|
||||
$userContentDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
$demoContentDir = __DIR__ . '/default/content';
|
||||
|
||||
// Check if user content directory has actual content (more than just . and ..)
|
||||
$hasUserContent = is_dir($userContentDir) && count(scandir($userContentDir) ?: []) > 2;
|
||||
// Check if user content directory has actual content (more than just . and ..)
|
||||
$hasUserContent = is_dir($userContentDir) && count(scandir($userContentDir) ?: []) > 2;
|
||||
|
||||
$contentDir = $hasUserContent ? realpath($userContentDir) : realpath($demoContentDir);
|
||||
$contentDir = $hasUserContent ? realpath($userContentDir) : realpath($demoContentDir);
|
||||
|
||||
// Extract request information
|
||||
$requestUri = parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?: '/';
|
||||
$hasTrailingSlash = str_ends_with($requestUri, '/') && $requestUri !== '/';
|
||||
$requestPath = trim($requestUri, '/');
|
||||
// Extract request information
|
||||
$requestUri = parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?: '/';
|
||||
$hasTrailingSlash = str_ends_with($requestUri, '/') && $requestUri !== '/';
|
||||
$requestPath = trim($requestUri, '/');
|
||||
|
||||
// Extract language from URL
|
||||
$currentLang = $defaultLang;
|
||||
$pathParts = explode('/', $requestPath);
|
||||
if (!empty($pathParts[0]) && in_array($pathParts[0], $availableLangs) && $pathParts[0] !== $defaultLang) {
|
||||
$currentLang = $pathParts[0];
|
||||
array_shift($pathParts);
|
||||
$requestPath = implode('/', $pathParts);
|
||||
// Extract language from URL
|
||||
$currentLang = $defaultLang;
|
||||
$pathParts = explode('/', $requestPath);
|
||||
if (!empty($pathParts[0]) && in_array($pathParts[0], $availableLangs) && $pathParts[0] !== $defaultLang) {
|
||||
$currentLang = $pathParts[0];
|
||||
array_shift($pathParts);
|
||||
$requestPath = implode('/', $pathParts);
|
||||
}
|
||||
|
||||
// Resolve templates with custom fallback to defaults
|
||||
$templates = new Templates(
|
||||
base: resolveTemplate('base'),
|
||||
page: resolveTemplate('page'),
|
||||
list: resolveTemplate('list')
|
||||
);
|
||||
|
||||
return new Context(
|
||||
contentDir: $contentDir,
|
||||
currentLang: $currentLang,
|
||||
defaultLang: $defaultLang,
|
||||
availableLangs: $availableLangs,
|
||||
templates: $templates,
|
||||
requestPath: $requestPath,
|
||||
hasTrailingSlash: $hasTrailingSlash
|
||||
);
|
||||
}
|
||||
|
||||
// Resolve templates with custom fallback to defaults
|
||||
$baseTemplate = resolveTemplate('base');
|
||||
$pageTemplate = resolveTemplate('page');
|
||||
$listTemplate = resolveTemplate('list');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue