1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CoinhiveBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class CoinhiveExtension |
12
|
|
|
*/ |
13
|
|
|
class CoinhiveExtension extends Extension |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param array $configs |
17
|
|
|
* @param ContainerBuilder $container |
18
|
|
|
*/ |
19
|
|
|
public function load(array $configs, ContainerBuilder $container) |
20
|
|
|
{ |
21
|
|
|
$configuration = new Configuration(); |
22
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
23
|
|
|
|
24
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
25
|
|
|
$loader->load('services.yml'); |
26
|
|
|
|
27
|
|
|
$def = $container->getDefinition('coinhive_miner.twig'); |
28
|
|
|
$def->replaceArgument(0, $config['config']['site_key']); |
29
|
|
|
|
30
|
|
|
$def = $container->getDefinition('coinhive_captcha.form'); |
31
|
|
|
$def->replaceArgument(0, $config['config']['site_key']); |
32
|
|
|
|
33
|
|
|
$def = $container->getDefinition('coinhive_captcha.validator'); |
34
|
|
|
$def->replaceArgument(1, $config['config']['site_key']); |
35
|
|
|
|
36
|
|
|
$this->registerWidget($container); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param ContainerBuilder $container |
41
|
|
|
*/ |
42
|
|
|
protected function registerWidget(ContainerBuilder $container) |
43
|
|
|
{ |
44
|
|
|
$templatingEngines = $container->getParameter('templating.engines'); |
45
|
|
|
if (in_array('twig', $templatingEngines)) { |
46
|
|
|
$formRessource = 'MedzonerGlobalBundle:Form:coinhive_captcha_widget.html.twig'; |
47
|
|
|
$container->setParameter('twig.form.resources', array_merge( |
48
|
|
|
$container->getParameter('twig.form.resources'), |
49
|
|
|
[$formRessource] |
50
|
|
|
)); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|