Files
Lars StommerandClaude Opus 5.5 7d0bc93abc Offers by their own rules, seasonal photos per section, theme authoring tooling
- 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>
2026-10-22 18:51:38 +02:00

83 lines
2.1 KiB
PHP

<?php
namespace App\Themes;
/**
* Discovers the themes below config('themes.paths').
*/
class ThemeRegistry
{
/** @var array<string, ThemeManifest>|null */
private ?array $themes = null;
/**
* @return array<string, ThemeManifest>
*/
public function all(): array
{
if ($this->themes === null) {
$this->themes = [];
foreach (config('themes.paths') as $path) {
foreach (glob(rtrim($path, '/\\').'/*/theme.json') ?: [] as $file) {
$manifest = ThemeManifest::fromFile($file);
$this->themes[$manifest->key] = $manifest;
}
}
}
return $this->themes;
}
public function get(string $key): ThemeManifest
{
return $this->all()[$key] ?? $this->all()[config('themes.base')];
}
/**
* The theme followed by its ancestors, ending with the base theme.
*
* @return list<ThemeManifest>
*/
public function chain(string $key): array
{
$chain = [];
$current = $this->get($key);
while (! isset($chain[$current->key])) {
$chain[$current->key] = $current;
if ($current->parent === null || ! isset($this->all()[$current->parent])) {
break;
}
$current = $this->all()[$current->parent];
}
$base = $this->get(config('themes.base'));
$chain[$base->key] ??= $base;
return array_values($chain);
}
/**
* Colour tokens of a theme including the inherited ones (base first, the theme's own definitions win).
*
* @return array<string, array{label: string, default: string}>
*/
public function tokens(string $key): array
{
$tokens = [];
foreach (array_reverse($this->chain($key)) as $theme) {
$tokens = [...$tokens, ...$theme->tokens];
}
return $tokens;
}
/**
* @return array<string, string>
*/
public function options(): array
{
return array_map(fn (ThemeManifest $theme): string => "{$theme->name} ({$theme->version})", $this->all());
}
}