sessionless-1.x-dev/modules/sessionless_session/src/StickyQueryStorageEncryptionDecorator.php
modules/sessionless_session/src/StickyQueryStorageEncryptionDecorator.php
<?php
namespace Drupal\sessionless_session;
use Drupal\sessionless\SessionlessEncryptAndSign;
use Drupal\sticky_query\StickyQueryStorage\StickyQueryStorageInterface;
/**
* StickyQueryDecorator that signs and encrypts.
*/
final class StickyQueryStorageEncryptionDecorator implements StickyQueryStorageInterface {
protected StickyQueryStorageInterface $decorated;
protected SessionlessEncryptAndSign $cryptoService;
protected bool $mustEncrypt;
/**
* @param \Drupal\sticky_query\StickyQueryStorage\StickyQueryStorageInterface $decorated
* @param \Drupal\sessionless\SessionlessEncryptAndSign $cryptoService
* @param bool $mustEncrypt
*/
public function __construct(StickyQueryStorageInterface $decorated, SessionlessEncryptAndSign $cryptoService, bool $mustEncrypt = TRUE) {
$this->decorated = $decorated;
$this->cryptoService = $cryptoService;
$this->mustEncrypt = $mustEncrypt;
}
public function getValue() {
$data = $this->decorated->getValue();
if ($data) {
$jwtString = $this->cryptoService->encode($data);
}
else {
$jwtString = NULL;
}
return $jwtString;
}
public function setValue($value): void {
if ($value && is_string($value)) {
$this->decorated->setValue($this->cryptoService->decode($value));
}
else {
$this->decorated->setValue(NULL);
}
}
}
