PluginProbe
The Innovative Form Builder – IvyForms / 0.8
The Innovative Form Builder – IvyForms v0.8
1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 1.2 1.3
ivyforms / backend / src / Factory / Security / CaptchaServiceFactory.php

CaptchaServiceFactory.php in The Innovative Form Builder – IvyForms 0.8, at backend/src/Factory/Security/CaptchaServiceFactory.php

88 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © Melograno Venture Studio. All rights reserved.
5 * @licence See COPYING.md for license details.
6 */
7
8 namespace IvyForms\Factory\Security;
9
10 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use IvyForms\Services\Security\CaptchaServiceInterface;
16 use IvyForms\Services\Security\RecaptchaService;
17 use IvyForms\Services\Settings\SettingsService;
18
19 /**
20 * Simple factory for creating CAPTCHA service instances
21 *
22 * Focused on just creating service instances without caching or business logic.
23 * Uses composition with Registry and Resolver for advanced functionality.
24 *
25 * @package IvyForms\Factory\Security
26 */
27 class CaptchaServiceFactory
28 {
29 private SettingsService $settingsService;
30
31 public function __construct(SettingsService $settingsService)
32 {
33 $this->settingsService = $settingsService;
34 }
35
36 /**
37 * Create a CAPTCHA service instance for the given provider
38 *
39 * @param string $provider The CAPTCHA provider
40 * @return CaptchaServiceInterface|null
41 */
42 public function create(string $provider): ?CaptchaServiceInterface
43 {
44 switch ($provider) {
45 case CaptchaProviderResolver::PROVIDER_RECAPTCHA:
46 return new RecaptchaService($this->settingsService);
47
48 case CaptchaProviderResolver::PROVIDER_HCAPTCHA:
49 // Future implementation for hCaptcha
50 // return new HCaptchaService($this->settingsService);
51 return null;
52
53 case CaptchaProviderResolver::PROVIDER_TURNSTILE:
54 // Future implementation for Cloudflare Turnstile
55 // return new TurnstileService($this->settingsService);
56 return null;
57
58 default:
59 return null;
60 }
61 }
62
63 /**
64 * Get all supported CAPTCHA providers
65 *
66 * @return array<string>
67 */
68 public function getSupportedProviders(): array
69 {
70 return [
71 CaptchaProviderResolver::PROVIDER_RECAPTCHA,
72 CaptchaProviderResolver::PROVIDER_HCAPTCHA,
73 CaptchaProviderResolver::PROVIDER_TURNSTILE,
74 ];
75 }
76
77 /**
78 * Check if a provider is supported (has implementation)
79 *
80 * @param string $provider
81 * @return bool
82 */
83 public function isSupported(string $provider): bool
84 {
85 return $this->create($provider) !== null;
86 }
87 }
88