Completed
Push — master ( 977a48...a95e66 )
by Fabien
03:07
created

FabienCrassatCurriculumVitaeExtension   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 71
ccs 0
cts 46
cp 0
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 12 1
A setPathToCVDirectory() 0 12 3
A setTemplate() 0 7 2
A setDefaultCV() 0 7 2
A setDefaultLanguage() 0 7 2
1
<?php
2
3
/*
4
 * This file is part of the FabienCrassat\CurriculumVitaeBundle Symfony bundle.
5
 *
6
 * (c) Fabien Crassat <[email protected]>
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 FabienCrassat\CurriculumVitaeBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Loader;
17
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
19
20
/**
21
 * This is the class that loads and manages your bundle configuration
22
 *
23
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
24
 */
25
class FabienCrassatCurriculumVitaeExtension extends Extension
26
{
27
28
    private $config;
29
    private $container;
30
31
    const PATH_TO_CV   = 'fabiencrassat_curriculumvitae.path_to_cv';
32
    const DEFAULT_CV   = 'fabiencrassat_curriculumvitae.default_cv';
33
    const DEFAULT_LANG = 'fabiencrassat_curriculumvitae.default_lang';
34
    const TEMPLATE     = 'fabiencrassat_curriculumvitae.template';
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    public function load(array $configs, ContainerBuilder $container)
40
    {
41
        $this->container = $container;
42
        $this->config    = $this->processConfiguration(new Configuration(), $configs);
43
44
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
45
        $loader->load('services.yml');
46
47
        $this->setPathToCVDirectory();
48
        $this->setDefaultCV();
49
        $this->setTemplate();
50
        $this->setDefaultLanguage();
51
    }
52
53
    private function setPathToCVDirectory()
54
    {
55
        // Path to Curriculum Vitae Directory
56
        $pathToCV = __DIR__.'/../'.$this->container->getParameter(self::PATH_TO_CV);
57
        if (isset($this->config['path_to_cv'])) {
58
            $pathToCV = $this->config['path_to_cv'];
59
        }
60
61
        if (!is_dir($pathToCV)) {
62
            throw new NotFoundHttpException('There is no directory defined here ('.$pathToCV.').');
63
        }
64
        $this->container->setParameter(self::PATH_TO_CV, $pathToCV);
65
    }
66
67
    private function setDefaultCV()
68
    {
69
        // Default Curriculum Vitae
70
        if (isset($this->config['custo_default_cv'])) {
71
            $this->container->setParameter(
72
                self::DEFAULT_CV,
73
                $this->config['custo_default_cv']
74
            );
75
        }
76
    }
77
78
    private function setTemplate()
79
    {
80
        // Twig template of the Curriculum Vitae
81
        if (isset($this->config['template'])) {
82
            $this->container->setParameter(
83
                self::TEMPLATE,
84
                $this->config['template']
85
            );
86
        }
87
    }
88
89
    private function setDefaultLanguage()
90
    {
91
        // default_lang of the Curriculum Vitae
92
        if (isset($this->config['default_lang'])) {
93
            $this->container->setParameter(
94
                self::DEFAULT_LANG,
95
                $this->config['default_lang']
96
            );
97
        }
98
    }
99
}
100