- Fix RedisCache driver to handle MGET failures gracefully with fallback - Add comprehensive discovery context comparison debug tools - Identify root cause: WEB context discovery missing 166 items vs CLI - WEB context missing RequestFactory class entirely (52 vs 69 commands) - Improved exception handling with detailed binding diagnostics
148 lines
4.0 KiB
PHP
148 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Design\ValueObjects;
|
|
|
|
/**
|
|
* Design Token Value Object
|
|
*/
|
|
final readonly class DesignToken
|
|
{
|
|
public function __construct(
|
|
public string $name,
|
|
public DesignTokenType $type,
|
|
public mixed $value,
|
|
public string $description,
|
|
public array $metadata = []
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Factory für Color Token
|
|
*/
|
|
public static function color(string $name, CssColor $color, string $description = ''): self
|
|
{
|
|
return new self(
|
|
name: $name,
|
|
type: DesignTokenType::COLOR,
|
|
value: $color,
|
|
description: $description ?: "Color: " . ucwords(str_replace(['-', '_'], ' ', $name)),
|
|
metadata: ['source' => 'css_custom_property']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Factory für Spacing Token
|
|
*/
|
|
public static function spacing(string $name, string|int $value, string $description = ''): self
|
|
{
|
|
return new self(
|
|
name: $name,
|
|
type: DesignTokenType::SPACING,
|
|
value: $value,
|
|
description: $description ?: "Spacing: " . ucwords(str_replace(['-', '_'], ' ', $name)),
|
|
metadata: ['source' => 'css_custom_property']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Factory für Typography Token
|
|
*/
|
|
public static function typography(string $name, mixed $value, string $description = ''): self
|
|
{
|
|
return new self(
|
|
name: $name,
|
|
type: DesignTokenType::TYPOGRAPHY,
|
|
value: $value,
|
|
description: $description ?: "Typography: " . ucwords(str_replace(['-', '_'], ' ', $name)),
|
|
metadata: ['source' => 'css_custom_property']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Konvertiert zu Array für Export/Serialisierung
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'name' => $this->name,
|
|
'type' => $this->type->value,
|
|
'value' => $this->serializeValue(),
|
|
'description' => $this->description,
|
|
'metadata' => $this->metadata,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Erstellt CSS Custom Property String
|
|
*/
|
|
public function toCssCustomProperty(): string
|
|
{
|
|
$value = match($this->type) {
|
|
DesignTokenType::COLOR => $this->value instanceof CssColor ? $this->value->toString() : (string) $this->value,
|
|
default => (string) $this->value
|
|
};
|
|
|
|
return "--{$this->name}: {$value};";
|
|
}
|
|
|
|
/**
|
|
* Gibt CSS var() Referenz zurück
|
|
*/
|
|
public function toCssVar(): string
|
|
{
|
|
return "var(--{$this->name})";
|
|
}
|
|
|
|
/**
|
|
* Prüft ob Token einen bestimmten Wert-Typ hat
|
|
*/
|
|
public function hasValueType(string $type): bool
|
|
{
|
|
return match($type) {
|
|
'color' => $this->value instanceof CssColor,
|
|
'string' => is_string($this->value),
|
|
'int' => is_int($this->value),
|
|
'float' => is_float($this->value),
|
|
'array' => is_array($this->value),
|
|
default => false
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Gibt Wert als bestimmten Typ zurück
|
|
*/
|
|
public function getValueAs(string $type): mixed
|
|
{
|
|
return match($type) {
|
|
'string' => (string) $this->value,
|
|
'int' => (int) $this->value,
|
|
'float' => (float) $this->value,
|
|
'array' => is_array($this->value) ? $this->value : [$this->value],
|
|
'color' => $this->value instanceof CssColor ? $this->value : null,
|
|
default => $this->value
|
|
};
|
|
}
|
|
|
|
private function serializeValue(): mixed
|
|
{
|
|
if ($this->value instanceof CssColor) {
|
|
return [
|
|
'original' => $this->value->originalValue,
|
|
'format' => $this->value->format->value,
|
|
'hex' => $this->value->toHex(),
|
|
'rgb' => $this->value->toRGB()?->toArray(),
|
|
];
|
|
}
|
|
|
|
return $this->value;
|
|
}
|
|
|
|
public function toString(): string
|
|
{
|
|
return $this->toCssVar();
|
|
}
|
|
}
|