Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
146
src/Framework/Design/ValueObjects/DesignToken.php
Normal file
146
src/Framework/Design/ValueObjects/DesignToken.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?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
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user