2025-11-01 23:33:09 +01:00
|
|
|
<?php
|
|
|
|
|
readonly class Templates {
|
|
|
|
|
public function __construct(
|
|
|
|
|
public string $base,
|
|
|
|
|
public string $page,
|
|
|
|
|
public string $list
|
|
|
|
|
) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Context {
|
2025-11-25 20:19:12 +01:00
|
|
|
private array $data = [];
|
|
|
|
|
|
2025-11-01 23:33:09 +01:00
|
|
|
public function __construct(
|
|
|
|
|
public private(set) string $contentDir,
|
|
|
|
|
public private(set) Templates $templates,
|
|
|
|
|
public private(set) string $requestPath,
|
|
|
|
|
public private(set) bool $hasTrailingSlash
|
|
|
|
|
) {}
|
|
|
|
|
|
2025-11-25 20:19:12 +01:00
|
|
|
// 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]);
|
2025-11-01 23:33:09 +01:00
|
|
|
}
|
|
|
|
|
|
2025-11-25 20:19:12 +01:00
|
|
|
// 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
|
2025-11-01 23:33:09 +01:00
|
|
|
public array $navigation {
|
|
|
|
|
get => buildNavigation($this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string $homeLabel {
|
2025-11-25 20:19:12 +01:00
|
|
|
get => loadMetadata($this->contentDir)["slug"] ?? "Home";
|
2025-11-01 23:33:09 +01:00
|
|
|
}
|
|
|
|
|
}
|