-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathCartProxyMapper.php
More file actions
46 lines (37 loc) · 1.38 KB
/
CartProxyMapper.php
File metadata and controls
46 lines (37 loc) · 1.38 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
<?php declare(strict_types=1);
namespace App\Collaboration\Cart\Mapper;
use Ibexa\Contracts\Cart\CartServiceInterface;
use Ibexa\Contracts\Cart\Value\CartInterface;
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Core\Repository\ProxyFactory\ProxyGeneratorInterface;
use ProxyManager\Proxy\LazyLoadingInterface;
final class CartProxyMapper implements CartProxyMapperInterface
{
private Repository $repository;
private CartServiceInterface $cartService;
private ProxyGeneratorInterface $proxyGenerator;
public function __construct(
Repository $repository,
CartServiceInterface $cartService,
ProxyGeneratorInterface $proxyGenerator
) {
$this->repository = $repository;
$this->cartService = $cartService;
$this->proxyGenerator = $proxyGenerator;
}
public function createCartProxy(string $identifier): CartInterface
{
$initializer = function (
&$wrappedObject,
LazyLoadingInterface $proxy,
$method,
array $parameters,
&$initializer
) use ($identifier): bool {
$initializer = null;
$wrappedObject = $this->repository->sudo(fn (): CartInterface => $this->cartService->getCart($identifier));
return true;
};
return $this->proxyGenerator->createProxy(CartInterface::class, $initializer);
}
}