-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEncryptionListener.php
More file actions
34 lines (29 loc) · 1.03 KB
/
EncryptionListener.php
File metadata and controls
34 lines (29 loc) · 1.03 KB
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
<?php
namespace CodedMonkey\Dirigent\EventListener;
use CodedMonkey\Dirigent\Doctrine\Type\EncryptedTextType;
use CodedMonkey\Dirigent\Encryption\Encryption;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Type;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;
readonly class EncryptionListener
{
/**
* @param Connection $connection unused, but this causes it to be loaded by the container
*/
public function __construct(
private Connection $connection,
private Encryption $encryption,
) {
}
/**
* Configure the custom encrypted text type for Doctrine at the start of every request (and after the container is built).
*/
#[AsEventListener(RequestEvent::class)]
public function configureDoctrineEncryptedTextType(): void
{
/** @var EncryptedTextType $doctrineType */
$doctrineType = Type::getType(EncryptedTextType::TYPE);
$doctrineType->setEncryptionUtility($this->encryption);
}
}