|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BenTools\Shh\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
9
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
10
|
|
|
|
|
11
|
|
|
final class ShhExtension extends Extension |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @inheritDoc |
|
15
|
|
|
*/ |
|
16
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
17
|
|
|
{ |
|
18
|
|
|
$configuration = new Configuration(); |
|
19
|
|
|
$container->setParameter('env(SHH_PASSPHRASE)', null); |
|
20
|
|
|
$container->setParameter('env(SHH_SECRETS_FILE)', \sprintf('%s/.secrets.json', $container->getParameter('kernel.project_dir'))); |
|
21
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
22
|
|
|
$container->setParameter('shh.private_key_file', $config['private_key_file']); |
|
23
|
|
|
$container->setParameter('shh.public_key_file', $config['public_key_file']); |
|
24
|
|
|
$container->setParameter('shh.passphrase', $config['passphrase']); |
|
25
|
|
|
$container->setParameter('shh.keys_dir', $this->guessKeysDirectory($container)); |
|
26
|
|
|
|
|
27
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config')); |
|
28
|
|
|
$loader->load('services.xml'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return string |
|
33
|
|
|
*/ |
|
34
|
|
|
private function guessKeysDirectory(ContainerBuilder $container) |
|
35
|
|
|
{ |
|
36
|
|
|
if (Kernel::MAJOR_VERSION < 4) { |
|
37
|
|
|
return $container->getParameter('kernel.project_dir').'/app/config/shh'; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return $container->getParameter('kernel.project_dir').'/config/shh'; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|