folderweb/app/context.php

51 lines
1.3 KiB
PHP
Raw Normal View History

<?php
readonly class Templates {
public function __construct(
public string $base,
public string $page,
public string $list
) {}
}
class Context {
private array $data = [];
public function __construct(
public private(set) string $contentDir,
public private(set) Templates $templates,
public private(set) string $requestPath,
public private(set) bool $hasTrailingSlash
) {}
// 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)["slug"] ?? "Home";
}
}