PluginProbe
The Innovative Form Builder – IvyForms / 0.9
The Innovative Form Builder – IvyForms v0.9
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 / CaptchaProviderRegistry.php

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

103 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
17 /**
18 * Registry for managing CAPTCHA service instances
19 *
20 * Handles caching and lifecycle management of CAPTCHA service instances
21 * to avoid unnecessary object creation and improve performance.
22 *
23 * @package IvyForms\Factory\Security
24 */
25 class CaptchaProviderRegistry
26 {
27 /**
28 * @var array<string, CaptchaServiceInterface>
29 */
30 private array $services = [];
31
32 /**
33 * Register a service instance for a provider
34 *
35 * @param string $provider The provider identifier
36 * @param CaptchaServiceInterface $service The service instance
37 */
38 public function register(string $provider, CaptchaServiceInterface $service): void
39 {
40 $this->services[$provider] = $service;
41 }
42
43 /**
44 * Get a registered service instance
45 *
46 * @param string $provider The provider identifier
47 * @return CaptchaServiceInterface|null
48 */
49 public function get(string $provider): ?CaptchaServiceInterface
50 {
51 return $this->services[$provider] ?? null;
52 }
53
54 /**
55 * Check if a provider is registered
56 *
57 * @param string $provider The provider identifier
58 * @return bool
59 */
60 public function has(string $provider): bool
61 {
62 return isset($this->services[$provider]);
63 }
64
65 /**
66 * Remove a provider from the registry
67 *
68 * @param string $provider The provider identifier
69 */
70 public function remove(string $provider): void
71 {
72 unset($this->services[$provider]);
73 }
74
75 /**
76 * Clear all registered services
77 */
78 public function clear(): void
79 {
80 $this->services = [];
81 }
82
83 /**
84 * Get all registered provider names
85 *
86 * @return array<string>
87 */
88 public function getRegisteredProviders(): array
89 {
90 return array_keys($this->services);
91 }
92
93 /**
94 * Get count of registered services
95 *
96 * @return int
97 */
98 public function count(): int
99 {
100 return count($this->services);
101 }
102 }
103