1
|
|
|
<?php |
2
|
|
|
namespace Boekkooi\Bundle\JqueryValidationBundle\DependencyInjection; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\Config\Definition\Processor; |
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Warnar Boekkooi <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class BoekkooiJqueryValidationExtension extends Extension |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritdoc} |
18
|
|
|
*/ |
19
|
|
|
public function load(array $config, ContainerBuilder $container) |
20
|
|
|
{ |
21
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
22
|
|
|
$loader->load('services.yml'); |
23
|
|
|
|
24
|
|
|
$processor = new Processor(); |
25
|
|
|
$config = $processor->processConfiguration(new Configuration(), $config); |
26
|
|
|
|
27
|
|
|
$this->configureForm($container, $config, $loader); |
28
|
|
|
$this->configureFormAdditionals($container, $config, $loader); |
29
|
|
|
$this->configureTwig($config, $loader); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param array $config |
34
|
|
|
* @param $loader |
35
|
|
|
*/ |
36
|
|
|
private function configureTwig(array $config, LoaderInterface $loader) |
37
|
|
|
{ |
38
|
|
|
if ($config['twig']['enabled']) { |
39
|
|
|
$loader->load('twig.yml'); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param array $config |
45
|
|
|
* @param ContainerBuilder $container |
46
|
|
|
* @param LoaderInterface $loader |
47
|
|
|
*/ |
48
|
|
|
private function configureForm(ContainerBuilder $container, array $config, LoaderInterface $loader) |
49
|
|
|
{ |
50
|
|
|
$container->setParameter('boekkooi.jquery_validation.enabled', $config['form']['enabled']); |
51
|
|
|
|
52
|
|
|
$loader->load('form_rule_processors.yml'); |
53
|
|
|
$loader->load('form_rule_mappers.yml'); |
54
|
|
|
$loader->load('form_rule_compilers.yml'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param array $config |
59
|
|
|
* @param ContainerBuilder $container |
60
|
|
|
* @param LoaderInterface $loader |
61
|
|
|
*/ |
62
|
|
|
private function configureFormAdditionals(ContainerBuilder $container, array $config, LoaderInterface $loader) |
63
|
|
|
{ |
64
|
|
|
$includeAdditional = false; |
65
|
|
|
foreach ($config['form']['additionals'] as $name => $active) { |
66
|
|
|
$container->setParameter( |
67
|
|
|
sprintf('boekkooi.jquery_validation.additional.%s', $name), |
68
|
|
|
$active |
69
|
|
|
); |
70
|
|
|
$includeAdditional = $includeAdditional || $active; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if ($includeAdditional) { |
74
|
|
|
$loader->load('form_rule_additional_mappers.yml'); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|