|
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
|
4 |
|
public function load(array $configs, ContainerBuilder $container) |
|
40
|
|
|
{ |
|
41
|
4 |
|
$this->container = $container; |
|
42
|
4 |
|
$this->config = $this->processConfiguration(new Configuration(), $configs); |
|
43
|
|
|
|
|
44
|
4 |
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
45
|
4 |
|
$loader->load('services.yml'); |
|
46
|
|
|
|
|
47
|
4 |
|
$this->setPathToCVDirectory(); |
|
48
|
3 |
|
$this->setDefaultCV(); |
|
49
|
3 |
|
$this->setTemplate(); |
|
50
|
3 |
|
$this->setDefaultLanguage(); |
|
51
|
3 |
|
} |
|
52
|
|
|
|
|
53
|
4 |
|
private function setPathToCVDirectory() |
|
54
|
|
|
{ |
|
55
|
|
|
// Path to Curriculum Vitae Directory |
|
56
|
4 |
|
$pathToCV = __DIR__.'/../'.$this->container->getParameter(self::PATH_TO_CV); |
|
57
|
4 |
|
if (isset($this->config['path_to_cv'])) { |
|
58
|
2 |
|
$pathToCV = $this->config['path_to_cv']; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
4 |
|
if (!is_dir($pathToCV)) { |
|
62
|
1 |
|
throw new NotFoundHttpException('There is no directory defined here ('.$pathToCV.').'); |
|
63
|
|
|
} |
|
64
|
3 |
|
$this->container->setParameter(self::PATH_TO_CV, $pathToCV); |
|
65
|
3 |
|
} |
|
66
|
|
|
|
|
67
|
3 |
|
private function setDefaultCV() |
|
68
|
|
|
{ |
|
69
|
|
|
// Default Curriculum Vitae |
|
70
|
3 |
|
if (isset($this->config['custo_default_cv'])) { |
|
71
|
1 |
|
$this->container->setParameter( |
|
72
|
1 |
|
self::DEFAULT_CV, |
|
73
|
1 |
|
$this->config['custo_default_cv'] |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
3 |
|
} |
|
77
|
|
|
|
|
78
|
3 |
|
private function setTemplate() |
|
79
|
|
|
{ |
|
80
|
|
|
// Twig template of the Curriculum Vitae |
|
81
|
3 |
|
if (isset($this->config['template'])) { |
|
82
|
1 |
|
$this->container->setParameter( |
|
83
|
1 |
|
self::TEMPLATE, |
|
84
|
1 |
|
$this->config['template'] |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
3 |
|
} |
|
88
|
|
|
|
|
89
|
3 |
|
private function setDefaultLanguage() |
|
90
|
|
|
{ |
|
91
|
|
|
// default_lang of the Curriculum Vitae |
|
92
|
3 |
|
if (isset($this->config['default_lang'])) { |
|
93
|
1 |
|
$this->container->setParameter( |
|
94
|
1 |
|
self::DEFAULT_LANG, |
|
95
|
1 |
|
$this->config['default_lang'] |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
3 |
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|