Phase 6, Anwendungsseite: Bildwelten und die Marke je Website

Die Theme-Sitzung wartete darauf: Seebad ruft schon ortsneutrale Plätze
über `partials/motif` auf und behilft sich mit einem eigenen `motifs/`-
Ordner. Der Kommentar dort sagt es selbst – „so a later picture-world
system can replace the mapping below". Das System gibt es jetzt.

**Bildwelten** (A18–A20) sind Pakete wie Themes: `resources/image-worlds/
<key>/` mit `world.json` und `svg/`. Eine Website wählt eine Bildwelt, eine
Wohnung darf eine andere tragen – das ist der Platz für die Bergwohnung auf
einer Küsten-Website. Vorlagen fragen über `$theme->motif($slot)` nach einem
Platz, nie nach einer Datei.

Die Render-Logik ist aus Seebads Partial in die Anwendung gewandert, damit
jedes Theme sie bekommt: Inline-SVG (nimmt die Textfarbe an, kein zweiter
Request), Titel und ARIA entfernt, und die internen Ids je Aufruf eindeutig
gemacht – zwei Kopien derselben Grafik auf einer Seite würden sonst auf
denselben Verlauf zeigen und eine davon verlöre ihre Farben.

Ein leerer Platz ist kein Fehler: die Vorlage bekommt schlicht keine
Dekoration. Weil das leicht zu übersehen ist, meldet
`php artisan image-worlds:check`, welcher Platz ohne Datei dasteht.

**Marke je Website** (A14/A22): Logo, Favicon und ein Logo für E-Mail und
Vertrag als Medien der Website. Der Mietvertrag bettet die Datei ein statt
eine URL zu holen – er wird auf dem Server gerendert und darf nicht davon
abhängen, dass dieser sich selbst erreicht. Ohne Logo bleibt der Vertrag
wie bisher.

`resources/themes/**` ist unberührt: die Ostsee-Grafiken sind kopiert, nicht
verschoben. Was die Theme-Sitzung nun tun kann, steht in
ZUSAMMENARBEIT.md §6; ihr Wunsch aus §5 ist als erledigt vermerkt.

272 Feature-Tests grün.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Lars StommerandClaude Opus 5 committed 2026-10-26 07:35:17 +01:00
1 parent f686996122
commit 4e66add1f0
28 files changed
+906 -5

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
<?php
namespace App\ImageWorlds;
use JsonException;
use RuntimeException;
/**
* One picture world ("Bildwelt"): a folder with a world.json and SVG files, exactly like a theme is a
* folder with a theme.json. Themes ask for a slot (divider, vignette.beach …), never for a file, so a
* website can be dressed in "Ostsee" or later in "Berge" without touching a single template (A18/A19).
*/
class ImageWorldManifest
{
/**
* @param array<string, string> $slots slot => file name without .svg
*/
public function __construct(
public readonly string $key,
public readonly string $name,
public readonly ?string $description,
public readonly string $path,
public readonly array $slots,
) {}
public static function fromFile(string $file): self
{
try {
$data = json_decode((string) file_get_contents($file), true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $exception) {
throw new RuntimeException('Bildwelt '.$file.' ist kein gültiges JSON: '.$exception->getMessage());
}
$path = dirname($file);
$key = basename($path);
return new self(
key: $key,
name: is_string($data['name'] ?? null) ? $data['name'] : $key,
description: is_string($data['description'] ?? null) ? $data['description'] : null,
path: $path,
slots: array_filter(
is_array($data['slots'] ?? null) ? $data['slots'] : [],
fn (mixed $file, mixed $slot): bool => is_string($slot) && is_string($file),
ARRAY_FILTER_USE_BOTH,
),
);
}
/**
* The file behind a slot, or null when this world does not fill it. A missing slot is not an error:
* a template asks for decoration and simply gets none.
*/
public function fileFor(string $slot): ?string
{
$name = $this->slots[$slot] ?? null;
if ($name === null) {
return null;
}
$file = $this->path.DIRECTORY_SEPARATOR.'svg'.DIRECTORY_SEPARATOR.$name.'.svg';
return is_file($file) ? $file : null;
}
/**
* @return list<string>
*/
public function missingFiles(): array
{
return array_values(array_filter(
array_keys($this->slots),
fn (string $slot): bool => $this->fileFor($slot) === null,
));
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace App\ImageWorlds;
/**
* Discovers the picture worlds below config('image-worlds.paths'), the same way themes are discovered.
*/
class ImageWorldRegistry
{
/** @var array<string, ImageWorldManifest>|null */
private ?array $worlds = null;
/**
* @return array<string, ImageWorldManifest>
*/
public function all(): array
{
if ($this->worlds === null) {
$this->worlds = [];
foreach (config('image-worlds.paths') as $path) {
foreach (glob(rtrim($path, '/\\').'/*/world.json') ?: [] as $file) {
$manifest = ImageWorldManifest::fromFile($file);
$this->worlds[$manifest->key] = $manifest;
}
}
ksort($this->worlds);
}
return $this->worlds;
}
public function get(?string $key): ?ImageWorldManifest
{
if ($key === null || $key === '') {
return null;
}
return $this->all()[$key] ?? null;
}
/**
* Key => name, for a select in the admin.
*
* @return array<string, string>
*/
public function options(): array
{
return array_map(fn (ImageWorldManifest $world): string => $world->name, $this->all());
}
}
+65
View File
@@ -0,0 +1,65 @@
<?php
namespace App\ImageWorlds;
use App\Themes\Theme;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
/**
* Renders the graphic behind a slot. Inline SVG, so the graphics take the text colour and need no second
* request; the ids inside are made unique per call, because two copies of the same gradient on one page
* would otherwise refer to the same definition and one of them would lose its colours.
*
* Which world applies: the apartment overrules the website (A20), the website overrules the installation.
*/
class MotifRenderer
{
/** @var array<string, string> */
private array $cache = [];
public function render(string $slot, ?string $class = null, ?string $label = null): HtmlString
{
$world = $this->world();
$file = $world?->fileFor($slot);
if ($file === null) {
return new HtmlString(''); // a template asks for decoration and gets none
}
$svg = $this->cache[$file] ??= (string) file_get_contents($file);
if ($svg === '') {
return new HtmlString('');
}
$unique = 'm'.Str::lower(Str::random(6));
$svg = (string) preg_replace(['/\s(role|aria-label|aria-hidden)="[^"]*"/', '/<title>.*?<\/title>/s'], '', $svg);
$svg = (string) preg_replace(['/id="([^"]+)"/', '/url\(#([^)]+)\)/'], ['id="$1-'.$unique.'"', 'url(#$1-'.$unique.')'], $svg);
$attributes = 'class="'.e((string) $class).'" '.($label !== null
? 'role="img" aria-label="'.e($label).'"'
: 'aria-hidden="true" focusable="false"');
return new HtmlString((string) preg_replace('/<svg\s/', '<svg '.$attributes.' ', $svg, 1));
}
public function has(string $slot): bool
{
return $this->world()?->fileFor($slot) !== null;
}
/**
* The picture world in force for what is being rendered right now.
*/
public function world(): ?ImageWorldManifest
{
$registry = app(ImageWorldRegistry::class);
$theme = app()->bound(Theme::class) ? app(Theme::class) : null;
return $registry->get($theme?->property()?->image_world)
?? $registry->get($theme?->site->image_world)
?? $registry->get(config('image-worlds.default'));
}
}