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
41
app/context.php
Normal file
41
app/context.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue