-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJWEBuilder.php
47 lines (40 loc) · 1.49 KB
/
JWEBuilder.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
<?php
declare(strict_types=1);
namespace Jose\Bundle\JoseFramework\Services;
use Jose\Bundle\JoseFramework\Event\JWEBuiltFailureEvent;
use Jose\Bundle\JoseFramework\Event\JWEBuiltSuccessEvent;
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Encryption\Compression\CompressionMethodManager;
use Jose\Component\Encryption\JWE;
use Jose\Component\Encryption\JWEBuilder as BaseJWEBuilder;
use Psr\EventDispatcher\EventDispatcherInterface;
use Throwable;
final class JWEBuilder extends BaseJWEBuilder
{
public function __construct(
AlgorithmManager $keyEncryptionKeyEncryptionAlgorithmManager,
AlgorithmManager $contentEncryptionAlgorithmManager,
CompressionMethodManager $compressionManager,
private readonly EventDispatcherInterface $eventDispatcher
) {
parent::__construct($keyEncryptionKeyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager);
}
public function build(): JWE
{
try {
$jwe = parent::build();
$this->eventDispatcher->dispatch(new JWEBuiltSuccessEvent($jwe));
return $jwe;
} catch (Throwable $throwable) {
$this->eventDispatcher->dispatch(new JWEBuiltFailureEvent(
$this->payload,
$this->recipients,
$this->sharedProtectedHeader,
$this->sharedHeader,
$this->aad,
$throwable
));
throw $throwable;
}
}
}