-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathCartSessionPersistenceMapper.php
More file actions
51 lines (45 loc) · 1.96 KB
/
CartSessionPersistenceMapper.php
File metadata and controls
51 lines (45 loc) · 1.96 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php declare(strict_types=1);
namespace App\Collaboration\Cart\Mapper;
use App\Collaboration\Cart\Persistence\Values\CartSessionCreateStruct;
use App\Collaboration\Cart\Persistence\Values\CartSessionUpdateStruct;
use Ibexa\Collaboration\Mapper\Persistence\SessionPersistenceMapperInterface;
use Ibexa\Collaboration\Persistence\Values\AbstractSessionCreateStruct as PersistenceSessionCreateStruct;
use Ibexa\Collaboration\Persistence\Values\AbstractSessionUpdateStruct as PersistenceSessionUpdateStruct;
use Ibexa\Contracts\Collaboration\Session\AbstractSessionCreateStruct as SessionCreateStruct;
use Ibexa\Contracts\Collaboration\Session\AbstractSessionUpdateStruct as SessionUpdateStruct;
use Ibexa\Contracts\Collaboration\Session\SessionInterface;
final class CartSessionPersistenceMapper implements SessionPersistenceMapperInterface
{
/**
* @param \App\Collaboration\Cart\CartSessionCreateStruct $createStruct
*/
public function toPersistenceCreateStruct(
SessionCreateStruct $createStruct
): PersistenceSessionCreateStruct {
$token = $createStruct->getToken();
$owner = $createStruct->getOwner();
$hasPublicLink = $createStruct->hasPublicLink();
assert($token !== null);
assert($owner !== null);
assert($hasPublicLink !== null);
return new CartSessionCreateStruct(
$token,
$createStruct->getCart()->getIdentifier(),
$owner->getUserId(),
$createStruct->isActive(),
$hasPublicLink,
new \DateTimeImmutable(),
new \DateTimeImmutable()
);
}
public function toPersistenceUpdateStruct(
SessionInterface $session,
SessionUpdateStruct $updateStruct
): PersistenceSessionUpdateStruct {
return new CartSessionUpdateStruct(
$session->getId(),
$updateStruct->getToken(),
($updateStruct->getOwner() ?? $session->getOwner())->getUserId()
);
}
}