PluginProbe
The Innovative Form Builder – IvyForms / 1.4.1
The Innovative Form Builder – IvyForms v1.4.1
1.5.1 1.5 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 All 27 releases
ivyforms / backend / src / Factory / Security / CaptchaServiceFactory.php

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

81 lines 2.2 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 use IvyForms\Services\Security\Common\CaptchaServiceInterface;
11 use IvyForms\Services\Security\HCaptcha\HCaptchaService;
12 use IvyForms\Services\Security\Recaptcha\RecaptchaService;
13 use IvyForms\Services\Security\Turnstile\TurnstileService;
14 use IvyForms\Services\Settings\SettingsService;
15
16 /**
17 * Simple factory for creating CAPTCHA service instances
18 *
19 * Focused on just creating service instances without caching or business logic.
20 * Uses composition with Registry and Resolver for advanced functionality.
21 *
22 * @package IvyForms\Factory\Security
23 */
24 class CaptchaServiceFactory
25 {
26 private SettingsService $settingsService;
27
28 public function __construct(SettingsService $settingsService)
29 {
30 $this->settingsService = $settingsService;
31 }
32
33 /**
34 * Create a CAPTCHA service instance for the given provider
35 *
36 * @param string $provider The CAPTCHA provider
37 * @return CaptchaServiceInterface|null
38 */
39 public function create(string $provider): ?CaptchaServiceInterface
40 {
41 switch ($provider) {
42 case CaptchaProviderResolver::PROVIDER_RECAPTCHA:
43 return new RecaptchaService($this->settingsService);
44
45 case CaptchaProviderResolver::PROVIDER_HCAPTCHA:
46 return new HCaptchaService($this->settingsService);
47
48 case CaptchaProviderResolver::PROVIDER_TURNSTILE:
49 return new TurnstileService($this->settingsService);
50
51 default:
52 return null;
53 }
54 }
55
56 /**
57 * Get all supported CAPTCHA providers
58 *
59 * @return array<string>
60 */
61 public function getSupportedProviders(): array
62 {
63 return [
64 CaptchaProviderResolver::PROVIDER_RECAPTCHA,
65 CaptchaProviderResolver::PROVIDER_HCAPTCHA,
66 CaptchaProviderResolver::PROVIDER_TURNSTILE,
67 ];
68 }
69
70 /**
71 * Check if a provider is supported (has implementation)
72 *
73 * @param string $provider
74 * @return bool
75 */
76 public function isSupported(string $provider): bool
77 {
78 return $this->create($provider) !== null;
79 }
80 }
81