MsalsasVotingExtension::load()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the MsalsasVotingBundle package.
5
 *
6
 * (c) Manolo Salsas
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Msalsas\VotingBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
17
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19
20
class MsalsasVotingExtension extends Extension implements PrependExtensionInterface
21
{
22 3
    public function load(array $configs, ContainerBuilder $container)
23
    {
24 3
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
25
26 3
        $loader->load('services.xml');
27 3
        $config = $this->processConfiguration(new Configuration(), $configs);
28 1
        $container->setParameter('msalsas_voting.negative_reasons', $config['negative_reasons']);
29 1
        $container->setParameter('msalsas_voting.anonymous_percent_allowed', $config['anonymous_percent_allowed']);
30 1
        $container->setParameter('msalsas_voting.anonymous_min_allowed', $config['anonymous_min_allowed']);
31 1
    }
32
33 1
    public function prepend(ContainerBuilder $container)
34
    {
35 1
        $configs = $container->getExtensionConfig($this->getAlias());
36 1
        $config = $this->processConfiguration(new Configuration(), $configs);
37
38 1
        $doctrineConfig = [];
39 1
        $doctrineConfig['orm']['resolve_target_entities']['Msalsas\VotingBundle\Entity\Vote\UserInterface'] = $config['user_provider'];
40 1
        $doctrineConfig['orm']['mappings'][] = array(
41
            'name' => 'MsalsasVotingBundle',
42
            'is_bundle' => true,
43
            'type' => 'xml',
44
            'prefix' => 'Msalsas\VotingBundle\Entity'
45
        );
46 1
        $container->prependExtensionConfig('doctrine', $doctrineConfig);
47
48 1
        $twigConfig = [];
49 1
        $twigConfig['globals']['msalsas_voting_voter'] = "@msalsas_voting.voter";
50 1
        $twigConfig['globals']['msalsas_voting_clicker'] = "@msalsas_voting.clicker";
51 1
        $twigConfig['paths'][__DIR__.'/../Resources/views'] = "msalsas_voting";
52 1
        $twigConfig['paths'][__DIR__.'/../Resources/public'] = "msalsas_voting.public";
53 1
        $container->prependExtensionConfig('twig', $twigConfig);
54 1
    }
55
56 1
    public function getAlias()
57
    {
58 1
        return 'msalsas_voting';
59
    }
60
}