*/ private const B2IN_BOOLEAN_KEYS = [ 'show_logo', 'show_claim', 'show_footer', 'display_active', ]; /** * @return array */ public static function defaults(DisplayVersionType|string $type): array { $typeValue = $type instanceof DisplayVersionType ? $type->value : $type; return match ($typeValue) { DisplayVersionType::VideoDisplay->value => [ 'qr_label' => 'Website', ], DisplayVersionType::B2in->value => [ 'theme' => 'dark', 'header_logo_url' => '/_cabinet/assets/b2in-logo-positive.svg', 'header_claim' => 'Connecting Design & Property', 'logo_position' => 'top-left', 'claim_position' => 'top-right', 'show_logo' => true, 'show_claim' => true, 'show_footer' => true, 'footer_url' => 'B2in.eu', 'footer_name' => '', 'footer_prefix' => 'by', 'qr_url' => '', 'transition' => [ 'type' => 'crossfade', 'duration_ms' => 800, ], 'default_image_duration' => 10, 'rotation_weights' => ['immobilien' => 70, 'moebel' => 30], 'display_active' => true, ], DisplayVersionType::Offers->value => [ 'loop' => true, 'transition' => [ 'type' => 'fade', 'duration' => 600, ], ], default => [], }; } /** * @param array|null $settings * @return array */ public static function merge(DisplayVersionType|string $type, ?array $settings): array { $merged = array_replace_recursive(self::defaults($type), $settings ?? []); $typeValue = $type instanceof DisplayVersionType ? $type->value : $type; if ($typeValue === DisplayVersionType::B2in->value) { return self::normalizeB2inBooleans($merged); } if ($typeValue === DisplayVersionType::Offers->value && array_key_exists('loop', $merged)) { $merged['loop'] = self::toBool($merged['loop']); } return $merged; } /** * @param array $settings * @return array */ private static function normalizeB2inBooleans(array $settings): array { foreach (self::B2IN_BOOLEAN_KEYS as $key) { if (array_key_exists($key, $settings)) { $settings[$key] = self::toBool($settings[$key]); } } return $settings; } private static function toBool(mixed $value): bool { if (is_bool($value)) { return $value; } $filtered = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); return $filtered ?? (bool) $value; } }