PluginProbe
The Innovative Form Builder – IvyForms / 0.8.2
The Innovative Form Builder – IvyForms v0.8.2
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 0.8.2, at backend/src/Factory/Security/CaptchaServiceFactory.php

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