|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Matks\MarkdownBlogBundle\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
|
|
|
class MarkdownBlogExtension extends Extension |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* {@inheritdoc} |
|
14
|
|
|
*/ |
|
15
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
16
|
|
|
{ |
|
17
|
|
|
$configuration = new Configuration(); |
|
18
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
19
|
|
|
|
|
20
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
21
|
|
|
$loader->load('blog_services.yml'); |
|
22
|
|
|
|
|
23
|
|
|
$this->injectBundleConfigurationParametersIntoContainer($container, $config); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param ContainerBuilder $container |
|
28
|
|
|
* @param array $bundleConfiguration |
|
29
|
|
|
* |
|
30
|
|
|
* @throws \RuntimeException |
|
31
|
|
|
*/ |
|
32
|
|
|
private function injectBundleConfigurationParametersIntoContainer( |
|
33
|
|
|
ContainerBuilder $container, |
|
34
|
|
|
array $bundleConfiguration) |
|
35
|
|
|
{ |
|
36
|
|
|
$parametersToInject = [ |
|
37
|
|
|
'posts_directory', |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
foreach ($parametersToInject as $parameter) { |
|
41
|
|
|
if (false === array_key_exists($parameter, $bundleConfiguration)) { |
|
42
|
|
|
throw new \RuntimeException("Expected bundle configuration to contain $parameter"); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$parameterAlias = 'markdown_blog.'.$parameter; |
|
46
|
|
|
|
|
47
|
|
|
$container->setParameter($parameterAlias, $bundleConfiguration[$parameter]); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|