bpolaszek /
shh-bundle
| 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 | |||
| 10 | final class ShhExtension extends Extension |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @param array<string, mixed> $configs |
||
| 14 | */ |
||
| 15 | public function load(array $configs, ContainerBuilder $container): void |
||
| 16 | { |
||
| 17 | $configuration = new Configuration(); |
||
| 18 | $container->setParameter('env(SHH_PASSPHRASE)', null); |
||
| 19 | $container->setParameter( |
||
| 20 | 'env(SHH_SECRETS_FILE)', |
||
| 21 | \sprintf('%s/.secrets.json', $container->getParameter('kernel.project_dir')) // @phpstan-ignore-line |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 22 | ); |
||
| 23 | $config = $this->processConfiguration($configuration, $configs); |
||
| 24 | $container->setParameter('shh.private_key_file', $config['private_key_file']); |
||
| 25 | $container->setParameter('shh.public_key_file', $config['public_key_file']); |
||
| 26 | $container->setParameter('shh.passphrase', $config['passphrase']); |
||
| 27 | $container->setParameter('shh.keys_dir', $this->guessKeysDirectory($container)); |
||
| 28 | |||
| 29 | $loader = new XmlFileLoader($container, new FileLocator(\dirname(__DIR__) . '/Resources/config')); |
||
| 30 | $loader->load('services.xml'); |
||
| 31 | } |
||
| 32 | |||
| 33 | private function guessKeysDirectory(ContainerBuilder $container): string |
||
| 34 | { |
||
| 35 | return $container->getParameter('kernel.project_dir') . '/config/shh'; // @phpstan-ignore-line |
||
| 36 | } |
||
| 37 | } |
||
| 38 |