# ivyforms/0.5/backend/src/Services/Template/TemplateMapper.php

The Innovative Form Builder – IvyForms, version 0.5. 104 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.5/code/backend/src/Services/Template/TemplateMapper.php
- Raw: https://pluginprobe.com/plugins/ivyforms/0.5/raw/backend/src/Services/Template/TemplateMapper.php
- Modified: 2025-10-23T15:35:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/0.5/code/backend/src/Services/Template/TemplateMapper.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace IvyForms\Services\Template;

// phpcs:disable PSR1.Files.SideEffects
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

/**
 * Class TemplateMapper
 *
 * Maps template IDs to their corresponding template classes
 *
 * @package IvyForms\Services\Template
 */
class TemplateMapper
{
    /**
     * Template ID to class mapping
     *
     * @var array<string, string>
     */
    private static array $templateMap = [
        'contact_form' => ContactFormTemplate::class,
        'blank_form' => BlankFormTemplate::class,
    ];

    /**
     * Get template class by template ID
     *
     * @param string $templateId
     * @return string|null Template class name or null if not found
     */
    public static function getTemplateClass(string $templateId): ?string
    {
        return self::$templateMap[$templateId] ?? null;
    }

    /**
     * Get template data by template ID
     *
     * @param string $templateId
     * @return array<string, mixed>|null Template data or null if not found
     */
    public static function getTemplate(string $templateId): ?array
    {
        $templateClass = self::getTemplateClass($templateId);

        if (!$templateClass || !class_exists($templateClass)) {
            return null;
        }

        return $templateClass::getTemplate();
    }

    /**
     * Get all template IDs
     *
     * @return array<int, string>
     */
    public static function getAllTemplateIds(): array
    {
        return array_keys(self::$templateMap);
    }

    /**
     * Check if template ID exists
     *
     * @param string $templateId
     * @return bool
     */
    public static function hasTemplate(string $templateId): bool
    {
        return isset(self::$templateMap[$templateId]);
    }

    /**
     * Get all templates as associative array
     *
     * @return array<string, array<string, mixed>>
     */
    public static function getAllTemplates(): array
    {
        $templates = [];

        foreach (self::$templateMap as $templateId => $templateClass) {
            // Skip BlankFormTemplate from public template list
            if ($templateClass === BlankFormTemplate::class) {
                continue;
            }

            if (class_exists($templateClass)) {
                $templateData = $templateClass::getTemplate();
                $templates[$templateId] = $templateData;
            }
        }

        return $templates;
    }
}

```
