-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJoseFrameworkBundle.php
74 lines (65 loc) · 2.75 KB
/
JoseFrameworkBundle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
namespace Jose\Bundle\JoseFramework;
use Jose\Bundle\JoseFramework\DependencyInjection\Compiler\EventDispatcherAliasCompilerPass;
use Jose\Bundle\JoseFramework\DependencyInjection\Compiler\SymfonySerializerCompilerPass;
use Jose\Bundle\JoseFramework\DependencyInjection\JoseFrameworkExtension;
use Jose\Bundle\JoseFramework\DependencyInjection\Source;
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Checker\CheckerSource;
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Console\ConsoleSource;
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Core\CoreSource;
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Encryption\EncryptionSource;
use Jose\Bundle\JoseFramework\DependencyInjection\Source\KeyManagement\KeyManagementSource;
use Jose\Bundle\JoseFramework\DependencyInjection\Source\NestedToken\NestedToken;
use Jose\Bundle\JoseFramework\DependencyInjection\Source\Signature\SignatureSource;
use Jose\Bundle\JoseFramework\DependencyInjection\Source\SourceWithCompilerPasses;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;
final class JoseFrameworkBundle extends Bundle
{
/**
* @var Source\Source[]
*/
private array $sources = [];
public function __construct()
{
foreach ($this->getSources() as $source) {
$this->sources[$source->name()] = $source;
}
}
public function getContainerExtension(): ExtensionInterface
{
return new JoseFrameworkExtension('jose', $this->sources);
}
public function build(ContainerBuilder $container): void
{
parent::build($container);
foreach ($this->sources as $source) {
if ($source instanceof SourceWithCompilerPasses) {
$compilerPasses = $source->getCompilerPasses();
foreach ($compilerPasses as $compilerPass) {
$container->addCompilerPass($compilerPass, PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
}
}
}
$container->addCompilerPass(new EventDispatcherAliasCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
$container->addCompilerPass(new SymfonySerializerCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 10);
}
/**
* @return Source\Source[]
*/
private function getSources(): iterable
{
return [
new CoreSource(),
new CheckerSource(),
new ConsoleSource(),
new SignatureSource(),
new EncryptionSource(),
new NestedToken(),
new KeyManagementSource(),
];
}
}