'text', 'textarea' => 'text', 'richtext' => 'text', 'url' => 'url', 'media' => 'image', 'number' => 'number', 'color' => 'color', ]; /** @param mixed $value */ public static function is($value): bool { if (!is_array($value) || !isset($value[self::KEY]) || !is_array($value[self::KEY])) { return false; } $tag = $value[self::KEY]['tag'] ?? null; return is_string($tag) && $tag !== ''; } /** * Normalised dynamic data or null. * * @param mixed $value * @return array{tag: string, settings: array, before: string, after: string, fallback: string}|null */ public static function of($value): ?array { if (!self::is($value)) { return null; } $d = $value[self::KEY]; return [ 'tag' => (string) $d['tag'], 'settings' => is_array($d['settings'] ?? null) ? $d['settings'] : [], 'before' => is_scalar($d['before'] ?? null) ? (string) $d['before'] : '', 'after' => is_scalar($d['after'] ?? null) ? (string) $d['after'] : '', 'fallback' => is_scalar($d['fallback'] ?? null) ? (string) $d['fallback'] : '', ]; } /** @param array $settings */ public static function make(string $tag, array $settings = [], string $before = '', string $after = '', string $fallback = ''): array { return [self::KEY => ['tag' => $tag, 'settings' => $settings, 'before' => $before, 'after' => $after, 'fallback' => $fallback]]; } /** * True when the value is, or contains (nested arrays: background, repeater items), a dynamic value. * * @param mixed $value */ public static function contains($value, int $depth = 0): bool { if (!is_array($value) || $depth > 8) { return false; } if (self::is($value)) { return true; } foreach ($value as $v) { if (is_array($v) && self::contains($v, $depth + 1)) { return true; } } return false; } public static function category_for_control(string $type): ?string { return self::CONTROL_CATEGORIES[$type] ?? null; } }