| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
-
- namespace App\StorePlan;
-
- /**
- * The single definition of what a "store plan" may contain.
- *
- * A store plan is the saved design of a store: a theme plus an ordered list of sections.
- * It belongs to us, not to any AI provider. Whoever writes a plan (a person, Claude,
- * DeepSeek, anything later) must produce this shape, and PlanValidator checks it.
- *
- * Keep this file in step with resources/js/storefront/types.ts.
- */
- final class PlanSchema
- {
- public const int VERSION = 1;
-
- /**
- * Theme colours every plan must define, as 6-digit hex values.
- *
- * @var list<string>
- */
- public const array COLORS = [
- 'background',
- 'surface',
- 'foreground',
- 'muted',
- 'primary',
- 'primaryForeground',
- 'accent',
- 'border',
- ];
-
- /**
- * Fonts the storefront can load. Key is what the plan stores, value is the font family name.
- *
- * @var array<string, string>
- */
- public const array FONTS = [
- 'inter' => 'Inter',
- 'dm-sans' => 'DM Sans',
- 'poppins' => 'Poppins',
- 'manrope' => 'Manrope',
- 'space-grotesk' => 'Space Grotesk',
- 'playfair-display' => 'Playfair Display',
- 'lora' => 'Lora',
- 'fraunces' => 'Fraunces',
- ];
-
- /**
- * How rounded corners are.
- *
- * @var list<string>
- */
- public const array RADII = ['none', 'small', 'medium', 'large', 'full'];
-
- /**
- * Section types and the layout variants each one supports.
- *
- * @var array<string, list<string>>
- */
- public const array SECTIONS = [
- 'header' => ['simple', 'centered'],
- 'hero' => ['centered', 'split'],
- 'product_grid' => ['grid', 'minimal'],
- 'featured_product' => ['image-left', 'image-right'],
- 'about' => ['simple', 'with-stats'],
- 'testimonials' => ['cards', 'single'],
- 'faq' => ['list', 'two-column'],
- 'newsletter' => ['banner', 'card'],
- 'contact' => ['simple', 'card'],
- 'footer' => ['simple', 'centered'],
- ];
-
- public const int MAX_SECTIONS = 20;
-
- /**
- * Links may only point inside the page, inside the site, or to safe outside targets.
- * This blocks things like "javascript:" links.
- */
- public const string LINK_PATTERN = '/^(#[A-Za-z0-9_-]*|\/(?!\/)[^\s]*|https:\/\/[^\s]+|mailto:[^\s]+|tel:[0-9+\-\s]+)$/';
-
- public const string COLOR_PATTERN = '/^#[0-9A-Fa-f]{6}$/';
-
- public const string SECTION_ID_PATTERN = '/^[a-z][a-z0-9-]{0,39}$/';
-
- /**
- * Validation rules for the content of one section type.
- * Keys are relative to the section's "content" object.
- *
- * @return array<string, list<string>>
- */
- public static function contentRules(string $type): array
- {
- $text = fn (int $max) => ['required', 'string', 'max:'.$max];
- $optionalText = fn (int $max) => ['nullable', 'string', 'max:'.$max];
- $link = ['required', 'string', 'max:300', 'regex:'.self::LINK_PATTERN];
- $price = ['required', 'numeric', 'min:0', 'max:999999'];
-
- return match ($type) {
- 'header' => [
- 'logoText' => $text(40),
- 'links' => ['present', 'array', 'max:6'],
- 'links.*.label' => $text(30),
- 'links.*.href' => $link,
- 'cta' => ['nullable', 'array'],
- 'cta.label' => ['required_with:cta', 'string', 'max:30'],
- 'cta.href' => ['required_with:cta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
- ],
- 'hero' => [
- 'eyebrow' => $optionalText(60),
- 'headline' => $text(120),
- 'subheadline' => $text(300),
- 'primaryCta' => ['required', 'array'],
- 'primaryCta.label' => $text(30),
- 'primaryCta.href' => $link,
- 'secondaryCta' => ['nullable', 'array'],
- 'secondaryCta.label' => ['required_with:secondaryCta', 'string', 'max:30'],
- 'secondaryCta.href' => ['required_with:secondaryCta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
- ],
- 'product_grid' => [
- 'heading' => $text(80),
- 'subheading' => $optionalText(200),
- 'items' => ['required', 'array', 'min:2', 'max:8'],
- 'items.*.name' => $text(80),
- 'items.*.price' => $price,
- 'items.*.badge' => $optionalText(20),
- ],
- 'featured_product' => [
- 'eyebrow' => $optionalText(60),
- 'name' => $text(80),
- 'description' => $text(500),
- 'price' => $price,
- 'bullets' => ['present', 'array', 'max:5'],
- 'bullets.*' => $text(100),
- 'cta' => ['required', 'array'],
- 'cta.label' => $text(30),
- 'cta.href' => $link,
- ],
- 'about' => [
- 'heading' => $text(80),
- 'body' => $text(1200),
- 'stats' => ['present', 'array', 'max:4'],
- 'stats.*.value' => $text(12),
- 'stats.*.label' => $text(40),
- ],
- 'testimonials' => [
- 'heading' => $text(80),
- 'items' => ['required', 'array', 'min:1', 'max:6'],
- 'items.*.quote' => $text(400),
- 'items.*.name' => $text(60),
- 'items.*.role' => $optionalText(60),
- ],
- 'faq' => [
- 'heading' => $text(80),
- 'items' => ['required', 'array', 'min:1', 'max:10'],
- 'items.*.question' => $text(160),
- 'items.*.answer' => $text(600),
- ],
- 'newsletter' => [
- 'heading' => $text(80),
- 'body' => $optionalText(240),
- 'placeholder' => $text(40),
- 'buttonLabel' => $text(30),
- ],
- 'contact' => [
- 'heading' => $text(80),
- 'body' => $optionalText(300),
- 'email' => ['nullable', 'email', 'max:120'],
- 'phone' => $optionalText(30),
- 'whatsapp' => ['nullable', 'string', 'regex:/^[0-9]{8,15}$/'],
- 'address' => $optionalText(200),
- ],
- 'footer' => [
- 'text' => $text(160),
- 'links' => ['present', 'array', 'max:8'],
- 'links.*.label' => $text(30),
- 'links.*.href' => $link,
- ],
- default => [],
- };
- }
- }
|