-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBeelabRecaptcha2Extension.php
More file actions
38 lines (32 loc) · 1.49 KB
/
BeelabRecaptcha2Extension.php
File metadata and controls
38 lines (32 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Beelab\Recaptcha2Bundle\DependencyInjection;
use Beelab\Recaptcha2Bundle\Recaptcha\SymfonyClientRequestMethod;
use ReCaptcha\RequestMethod\CurlPost;
use ReCaptcha\RequestMethod\Post;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
final class BeelabRecaptcha2Extension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('beelab_recaptcha2.site_key', $config['site_key']);
$container->setParameter('beelab_recaptcha2.secret', $config['secret']);
$container->setParameter('beelab_recaptcha2.enabled', $config['enabled']);
$requestMethodClass = $this->getRequestMethod($config['request_method']);
$container->setParameter('beelab_recaptcha2.request_method', $requestMethodClass);
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('services.php');
}
private function getRequestMethod(string $requestMethod): string
{
return match ($requestMethod) {
'curl_post' => CurlPost::class,
'http_client' => SymfonyClientRequestMethod::class,
default => Post::class,
};
}
}