folderweb/app/context.php

41 lines
1.1 KiB
PHP

<?php
readonly class Templates {
public function __construct(
public string $base,
public string $page,
public string $list
) {}
}
class Context {
// Use asymmetric visibility for immutability (PHP 8.4)
public function __construct(
public private(set) string $contentDir,
public private(set) string $currentLang,
public private(set) string $defaultLang,
public private(set) array $availableLangs,
public private(set) Templates $templates,
public private(set) string $requestPath,
public private(set) bool $hasTrailingSlash
) {}
// Property hooks - computed properties (PHP 8.4)
public string $langPrefix {
get => $this->currentLang !== $this->defaultLang
? "/{$this->currentLang}"
: '';
}
public array $navigation {
get => buildNavigation($this);
}
public string $homeLabel {
get => loadMetadata($this->contentDir, $this->currentLang, $this->defaultLang)['slug'] ?? 'Home';
}
public array $translations {
get => loadTranslations($this->currentLang);
}
}