# ivyforms/0.3.1/backend/src/Factory/Security/CaptchaServiceFactory.php

The Innovative Form Builder – IvyForms, version 0.3.1. 88 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.3.1/code/backend/src/Factory/Security/CaptchaServiceFactory.php
- Raw: https://pluginprobe.com/plugins/ivyforms/0.3.1/raw/backend/src/Factory/Security/CaptchaServiceFactory.php
- Modified: 2025-09-04T07:37:14+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.3.1/code/backend/src/Factory/Security/CaptchaServiceFactory.php#L10-L20`.

```php
<?php

/**
 * @copyright © TMS-Plugins. All rights reserved.
 * @licence   See COPYING.md for license details.
 */

namespace IvyForms\Factory\Security;

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

use IvyForms\Services\Security\CaptchaServiceInterface;
use IvyForms\Services\Security\RecaptchaService;
use IvyForms\Services\Settings\SettingsService;

/**
 * Simple factory for creating CAPTCHA service instances
 *
 * Focused on just creating service instances without caching or business logic.
 * Uses composition with Registry and Resolver for advanced functionality.
 *
 * @package IvyForms\Factory\Security
 */
class CaptchaServiceFactory
{
    private SettingsService $settingsService;

    public function __construct(SettingsService $settingsService)
    {
        $this->settingsService = $settingsService;
    }

    /**
     * Create a CAPTCHA service instance for the given provider
     *
     * @param string $provider The CAPTCHA provider
     * @return CaptchaServiceInterface|null
     */
    public function create(string $provider): ?CaptchaServiceInterface
    {
        switch ($provider) {
            case CaptchaProviderResolver::PROVIDER_RECAPTCHA:
                return new RecaptchaService($this->settingsService);

            case CaptchaProviderResolver::PROVIDER_HCAPTCHA:
                // Future implementation for hCaptcha
                // return new HCaptchaService($this->settingsService);
                return null;

            case CaptchaProviderResolver::PROVIDER_TURNSTILE:
                // Future implementation for Cloudflare Turnstile
                // return new TurnstileService($this->settingsService);
                return null;

            default:
                return null;
        }
    }

    /**
     * Get all supported CAPTCHA providers
     *
     * @return array<string>
     */
    public function getSupportedProviders(): array
    {
        return [
            CaptchaProviderResolver::PROVIDER_RECAPTCHA,
            CaptchaProviderResolver::PROVIDER_HCAPTCHA,
            CaptchaProviderResolver::PROVIDER_TURNSTILE,
        ];
    }

    /**
     * Check if a provider is supported (has implementation)
     *
     * @param string $provider
     * @return bool
     */
    public function isSupported(string $provider): bool
    {
        return $this->create($provider) !== null;
    }
}

```
