- Special offers: kinds (rule, fixed dates, gap filler), package price, priority, highlight;
GapFinder detects calendar gaps (optionally waiving the minimum stay); OfferShowcase decides
what the website advertises and prices fixed dates/gaps with PriceCalculator; offers section
shows them side by side, as a list or rotating; hero can show the top offer. Appearances no
longer carry a featured offer.
- Sections get stable ids; appearances set photos per section ("Bilder je Baustein") and
sections can be limited to appearances. Photo pickers show thumbnails everywhere.
- Themes: themes:make (scaffold, never overwrites), themes:check (contract, build, markup,
colours, external resources, WCAG contrast), themes:preview (signed links per page and
appearance), signed ?theme= preview and preview action in the site form, inherited colour
tokens in the admin. Base CSS split into theme.css + reusable theme-base.css.
- docs/THEME-ERSTELLUNG.md: binding guide for building additional themes elsewhere.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
2.3 KiB
PHP
70 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Themes;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
/**
|
|
* The contents of a theme's theme.json.
|
|
*/
|
|
final readonly class ThemeManifest
|
|
{
|
|
/**
|
|
* @param array<string, array{label: string, default: string}> $tokens colour tokens, exposed as CSS variables --<key>
|
|
* @param array{css?: string, js?: string} $assets Vite entry points relative to the project root
|
|
*/
|
|
public function __construct(
|
|
public string $key,
|
|
public string $name,
|
|
public string $version,
|
|
public ?string $parent,
|
|
public string $description,
|
|
public array $tokens,
|
|
public array $assets,
|
|
public string $path,
|
|
) {}
|
|
|
|
public static function fromFile(string $file): self
|
|
{
|
|
$data = json_decode((string) file_get_contents($file), true, flags: JSON_THROW_ON_ERROR);
|
|
|
|
if (! is_array($data) || blank($data['key'] ?? null) || blank($data['name'] ?? null)) {
|
|
throw new InvalidArgumentException("Invalid theme manifest [{$file}]: key and name are required.");
|
|
}
|
|
|
|
return new self(
|
|
key: $data['key'],
|
|
name: $data['name'],
|
|
version: $data['version'] ?? '0.0.0',
|
|
parent: $data['parent'] ?? null,
|
|
description: $data['description'] ?? '',
|
|
tokens: $data['tokens'] ?? [],
|
|
assets: $data['assets'] ?? [],
|
|
path: dirname($file),
|
|
);
|
|
}
|
|
|
|
public function viewsPath(): string
|
|
{
|
|
return $this->path.DIRECTORY_SEPARATOR.'views';
|
|
}
|
|
|
|
/**
|
|
* Relative path with forward slashes from one directory to another, as used in CSS @import/@source
|
|
* and JS imports, e.g. "../ostsee-licht/views".
|
|
*/
|
|
public static function relativePath(string $fromDirectory, string $to): string
|
|
{
|
|
$normalise = fn (string $path): array => array_values(array_filter(explode('/', str_replace('\\', '/', realpath($path) ?: $path)), fn (string $part): bool => $part !== ''));
|
|
$from = $normalise($fromDirectory);
|
|
$target = $normalise($to);
|
|
|
|
while ($from !== [] && $target !== [] && strcasecmp($from[0], $target[0]) === 0) {
|
|
array_shift($from);
|
|
array_shift($target);
|
|
}
|
|
|
|
return implode('/', [...array_fill(0, count($from), '..'), ...$target]) ?: '.';
|
|
}
|
|
}
|