Layer: Core · Source: lib/core/ThemeRenderer.php:31 (lines 31–235)
class ThemeRenderer implements ThemeRendererInterface
Default theme renderer implementation.
Resolves the active theme directory from a given name, falls back to a configured fallback theme when the primary theme is missing, and renders header / content / footer templates via include statements.
Usage:
\
// Constructor injection (preferred)
$renderer = new ThemeRenderer('/var/www/public/themes/', 'my-theme');
// Global-context factory (legacy bootstrap)
$renderer = ThemeRenderer::fromGlobalContext();
// Full-page render
$renderer->render('single', 200);
// 404 response
$renderer->render404();
\
| Relation | Type | Meaning |
|---|---|---|
| implements | ''ThemeRendererInterface'' | contract |
| Visibility | Name | Value | Line |
|---|---|---|---|
private | HEADER_TEMPLATE | 'header.php'; | 36 |
private | FOOTER_TEMPLATE | 'footer.php'; | 41 |
private | NOT_FOUND_TEMPLATE | '404.php'; | 46 |
private | TEMPLATE_EXTENSION | '.php'; | 51 |
private | FALLBACK_THEME | 'blog'; | 56 |
| Visibility | Type | Name | Default | Line |
|---|---|---|---|---|
private | string | $themeDir | 66 | |
private | (untyped) | $errorLogger | 75 |
| Visibility | Method | Summary | Line |
|---|---|---|---|
| public | __construct() | Construct a new ThemeRenderer. | 89 |
| public static | fromGlobalContext() | Factory method that constructs a ThemeRenderer from global application context. | 117 |
| public | render() | Render a full page: header, content template, and footer. | 135 |
| public | renderHeader() | Include the current theme's header template. | 146 |
| public | renderContent() | Include a content template from the current theme directory. | 162 |
| public | renderFooter() | Include the current theme's footer template. | 183 |
| public | render404() | Render a 404 response. | 199 |
| public | getThemeDir() | Return the resolved absolute path to the active theme directory. | 219 |
| private | log() | Log a message via the configured error logger, if one is set. | 229 |
public function __construct(string $themesRootPath, string $themeName, ?callable $errorLogger = null, string $fallbackTheme = 'blog')
lines 89–106 (18)
Construct a new ThemeRenderer.
| Parameter | Type | Default | Description |
|---|---|---|---|
$themesRootPath | string | required | Absolute path to the parent directory containing all theme directories, e.g. “/var/www/public/themes/”. |
$themeName | string | required | Name of the active theme directory (sanitized with {@see basename()}). |
$errorLogger | ?callable | null | Optional error logger. |
$fallbackTheme | string | 'blog' | Fallback theme name when the primary theme is missing required templates. |
public static function fromGlobalContext(): self
lines 117–130 (14)
Factory method that constructs a ThemeRenderer from global application context.
Uses {@see theme_identifier()} to determine the active theme and the {@see APP_ROOT} / {@see APP_THEME} constants for the root path. The default error logger is {@see scriptlog_error()}.
Takes no parameters.
Returns: self — self
public function render(string $template, int $statusCode = 200): void
lines 135–141 (7)
Documentation inherited from ''Scriptlog\Core\ThemeRendererInterface''.
Render a full page: header, content template, and footer.
Sets the HTTP response code before any output is sent.
| Parameter | Type | Default | Description |
|---|---|---|---|
$template | string | required | Content template name (without .php extension). |
$statusCode | int | 200 | HTTP status code (default 200). |
Returns: void
public function renderHeader(): void
lines 146–157 (12)
Documentation inherited from ''Scriptlog\Core\ThemeRendererInterface''.
Include the current theme's header template.
Outputs the opening HTML structure (doctype, head, navigation). Called internally by {@see render()}.
Takes no parameters.
Returns: void
public function renderContent(string $template): void
lines 162–178 (17)
Documentation inherited from ''Scriptlog\Core\ThemeRendererInterface''.
Include a content template from the current theme directory.
The template name is sanitized with {@see basename()} before inclusion to prevent directory traversal attacks.
| Parameter | Type | Default | Description |
|---|---|---|---|
$template | string | required | Content template name (without .php extension). |
Returns: void
public function renderFooter(): void
lines 183–194 (12)
Documentation inherited from ''Scriptlog\Core\ThemeRendererInterface''.
Include the current theme's footer template.
Takes no parameters.
Returns: void
public function render404(): void
lines 199–213 (15)
Documentation inherited from ''Scriptlog\Core\ThemeRendererInterface''.
Render a 404 response.
Sets a 404 HTTP status code, then renders the header, the 404 content template, and the footer. If the 404 template does not exist a warning is logged and rendering continues silently.
Takes no parameters.
Returns: void
public function getThemeDir(): string
lines 219–222 (4)
Documentation inherited from ''Scriptlog\Core\ThemeRendererInterface''.
Return the resolved absolute path to the active theme directory.
The path always ends with a directory separator.
Takes no parameters.
Returns: string — string Absolute path to the theme directory, e.g. “/var/www/public/themes/blog/”
private function log(string $message): void
lines 229–234 (6)
Log a message via the configured error logger, if one is set.
| Parameter | Type | Default | Description |
|---|---|---|---|
$message | string | required | The log message. |
Returns: void
This page is generated from source by 'tools/gendoc'. Edits will be overwritten.