@@ -37,11 +37,15 @@ class Bouncer
3737 /** @var int */
3838 private $ maxRemediationLevelIndex = 0 ;
3939
40+ /** @var array */
41+ private $ configs = [];
42+
4043 public function __construct (
4144 TagAwareAdapterInterface $ cacheAdapter = null ,
42- LoggerInterface $ logger = null ,
43- ApiCache $ apiCache = null
44- ) {
45+ LoggerInterface $ logger = null ,
46+ ApiCache $ apiCache = null
47+ )
48+ {
4549 if (!$ logger ) {
4650 $ logger = new Logger ('null ' );
4751 $ logger ->pushHandler (new NullHandler ());
@@ -50,6 +54,16 @@ public function __construct(
5054 $ this ->apiCache = $ apiCache ?: new ApiCache ($ logger , new ApiClient ($ logger ), $ cacheAdapter );
5155 }
5256
57+ /**
58+ * Retrieve Bouncer configurations
59+ *
60+ * @return array
61+ */
62+ public function getConfigs (): array
63+ {
64+ return $ this ->configs ;
65+ }
66+
5367 /**
5468 * Configure this instance.
5569 *
@@ -59,33 +73,33 @@ public function __construct(
5973 */
6074 public function configure (array $ config ): void
6175 {
62- // Process input configuration.
76+ // Process and validate input configuration.
6377 $ configuration = new Configuration ();
6478 $ processor = new Processor ();
65- $ finalConfig = $ processor ->processConfiguration ($ configuration , [$ config ]);
79+ $ this -> configs = $ processor ->processConfiguration ($ configuration , [$ config ]);
6680 /** @var int */
6781 $ index = array_search (
68- $ finalConfig ['max_remediation_level ' ],
82+ $ this -> configs ['max_remediation_level ' ],
6983 Constants::ORDERED_REMEDIATIONS
7084 );
7185 $ this ->maxRemediationLevelIndex = $ index ;
7286 $ cacheDurations = [
73- 'clean_ip_cache_duration ' => $ finalConfig ['clean_ip_cache_duration ' ],
74- 'bad_ip_cache_duration ' => $ finalConfig ['bad_ip_cache_duration ' ],
75- 'captcha_cache_duration ' => $ finalConfig ['captcha_cache_duration ' ],
76- 'geolocation_cache_duration ' => $ finalConfig ['geolocation_cache_duration ' ],
87+ 'clean_ip_cache_duration ' => $ this -> configs ['clean_ip_cache_duration ' ],
88+ 'bad_ip_cache_duration ' => $ this -> configs ['bad_ip_cache_duration ' ],
89+ 'captcha_cache_duration ' => $ this -> configs ['captcha_cache_duration ' ],
90+ 'geolocation_cache_duration ' => $ this -> configs ['geolocation_cache_duration ' ],
7791 ];
7892
7993 // Configure Api Cache.
8094 $ this ->apiCache ->configure (
81- $ finalConfig ['stream_mode ' ],
82- $ finalConfig ['api_url ' ],
83- $ finalConfig ['api_timeout ' ],
84- $ finalConfig ['api_user_agent ' ],
85- $ finalConfig ['api_key ' ],
95+ $ this -> configs ['stream_mode ' ],
96+ $ this -> configs ['api_url ' ],
97+ $ this -> configs ['api_timeout ' ],
98+ $ this -> configs ['api_user_agent ' ],
99+ $ this -> configs ['api_key ' ],
86100 $ cacheDurations ,
87- $ finalConfig ['fallback_remediation ' ],
88- $ finalConfig ['geolocation ' ]
101+ $ this -> configs ['fallback_remediation ' ],
102+ $ this -> configs ['geolocation ' ]
89103 );
90104 }
91105
@@ -115,7 +129,7 @@ private function capRemediationLevel(string $remediation): string
115129 *
116130 * @return string the remediation to apply (ex: 'ban', 'captcha', 'bypass')
117131 *
118- * @throws InvalidArgumentException
132+ * @throws InvalidArgumentException|\Psr\Cache\CacheException
119133 */
120134 public function getRemediationForIp (string $ ip ): string
121135 {
@@ -154,11 +168,12 @@ public static function getAccessForbiddenHtmlTemplate(array $config): string
154168 * The input $config should match the TemplateConfiguration input format.
155169 */
156170 public static function getCaptchaHtmlTemplate (
157- bool $ error ,
171+ bool $ error ,
158172 string $ captchaImageSrc ,
159173 string $ captchaResolutionFormUrl ,
160- array $ config
161- ): string {
174+ array $ config
175+ ): string
176+ {
162177 // Process template configuration.
163178 $ configuration = new TemplateConfiguration ();
164179 $ processor = new Processor ();
@@ -176,7 +191,7 @@ public static function getCaptchaHtmlTemplate(
176191 *
177192 * @return array "count": number of decisions added, "errors": decisions not added
178193 *
179- * @throws InvalidArgumentException
194+ * @throws InvalidArgumentException|\Psr\Cache\CacheException
180195 */
181196 public function warmBlocklistCacheUp (): array
182197 {
@@ -189,7 +204,7 @@ public function warmBlocklistCacheUp(): array
189204 *
190205 * @return array Number of deleted and new decisions, and errors when processing decisions
191206 *
192- * @throws InvalidArgumentException
207+ * @throws InvalidArgumentException|\Psr\Cache\CacheException
193208 */
194209 public function refreshBlocklistCache (): array
195210 {
0 commit comments