Remove language-specific content handling
Refactor to use plugin system for language support Remove hardcoded language features from core Move language handling to plugin system Improve content file discovery Simplify context creation Add plugin system documentation Implement hook system for extensibility Add template variable hook Add context storage for plugins Improve error handling Refactor rendering logic Improve list view sorting Add support for custom list templates Improve metadata handling Add plugin system reference documentation
This commit is contained in:
parent
24ee209e17
commit
a205f2cbd7
8 changed files with 524 additions and 315 deletions
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
readonly class Templates {
|
||||
public function __construct(
|
||||
public string $base,
|
||||
|
|
@ -9,33 +8,43 @@ readonly class Templates {
|
|||
}
|
||||
|
||||
class Context {
|
||||
// Use asymmetric visibility for immutability (PHP 8.4)
|
||||
private array $data = [];
|
||||
|
||||
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}"
|
||||
: '';
|
||||
// Plugin data storage
|
||||
public function set(string $key, mixed $value): void {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
||||
public function get(string $key, mixed $default = null): mixed {
|
||||
return $this->data[$key] ?? $default;
|
||||
}
|
||||
|
||||
public function has(string $key): bool {
|
||||
return isset($this->data[$key]);
|
||||
}
|
||||
|
||||
// Allow magic property access for plugin data
|
||||
public function __get(string $name): mixed {
|
||||
return $this->data[$name] ?? null;
|
||||
}
|
||||
|
||||
public function __set(string $name, mixed $value): void {
|
||||
$this->data[$name] = $value;
|
||||
}
|
||||
|
||||
// Computed properties
|
||||
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);
|
||||
get => loadMetadata($this->contentDir)["slug"] ?? "Home";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue