1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file was created by developers working at BitBag |
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
6
|
|
|
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace BitBag\SyliusCmsPlugin\Resolver; |
12
|
|
|
|
13
|
|
|
use BitBag\SyliusCmsPlugin\Entity\BlockInterface; |
14
|
|
|
use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface; |
15
|
|
|
use Psr\Log\LoggerInterface; |
16
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
17
|
|
|
use Webmozart\Assert\Assert; |
18
|
|
|
|
19
|
|
|
final class BlockResourceResolver implements BlockResourceResolverInterface |
20
|
|
|
{ |
21
|
|
|
/** @var BlockRepositoryInterface */ |
22
|
|
|
private $blockRepository; |
23
|
|
|
|
24
|
|
|
/** @var LoggerInterface */ |
25
|
|
|
private $logger; |
26
|
|
|
|
27
|
|
|
/** @var ChannelContextInterface */ |
28
|
|
|
private $channelContext; |
29
|
|
|
|
30
|
|
|
public function __construct( |
31
|
|
|
BlockRepositoryInterface $blockRepository, |
32
|
|
|
LoggerInterface $logger, |
33
|
|
|
ChannelContextInterface $channelContext |
34
|
|
|
) { |
35
|
|
|
$this->blockRepository = $blockRepository; |
36
|
|
|
$this->logger = $logger; |
37
|
|
|
$this->channelContext = $channelContext; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function findOrLog(string $code): ?BlockInterface |
41
|
|
|
{ |
42
|
|
|
$channel = $this->channelContext->getChannel(); |
43
|
|
|
Assert::notNull($channel->getCode()); |
44
|
|
|
$block = $this->blockRepository->findEnabledByCode($code, $channel->getCode()); |
|
|
|
|
45
|
|
|
|
46
|
|
|
if (false === $block instanceof BlockInterface) { |
47
|
|
|
$this->logger->warning(sprintf( |
48
|
|
|
'Block with "%s" code was not found in the database.', |
49
|
|
|
$code |
50
|
|
|
)); |
51
|
|
|
|
52
|
|
|
return null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $block; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|