1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file has been created by developers from BitBag. |
||
5 | * Feel free to contact us once you face any issues or want to start |
||
6 | * another great project. |
||
7 | * You can find more information about us on https://bitbag.shop and write us |
||
8 | * an email on [email protected]. |
||
9 | */ |
||
10 | |||
11 | declare(strict_types=1); |
||
12 | |||
13 | namespace BitBag\SyliusCmsPlugin\Resolver; |
||
14 | |||
15 | use BitBag\SyliusCmsPlugin\Entity\MediaInterface; |
||
16 | use BitBag\SyliusCmsPlugin\Repository\MediaRepositoryInterface; |
||
17 | use Psr\Log\LoggerInterface; |
||
18 | use Sylius\Component\Channel\Context\ChannelContextInterface; |
||
19 | |||
20 | final class MediaResourceResolver implements MediaResourceResolverInterface |
||
21 | { |
||
22 | /** @var MediaRepositoryInterface */ |
||
23 | private $mediaRepository; |
||
24 | |||
25 | /** @var ChannelContextInterface */ |
||
26 | private $channelContext; |
||
27 | |||
28 | /** @var LoggerInterface */ |
||
29 | private $logger; |
||
30 | |||
31 | public function __construct( |
||
32 | MediaRepositoryInterface $mediaRepository, |
||
33 | ChannelContextInterface $channelContext, |
||
34 | LoggerInterface $logger |
||
35 | ) { |
||
36 | $this->mediaRepository = $mediaRepository; |
||
37 | $this->channelContext = $channelContext; |
||
38 | $this->logger = $logger; |
||
39 | } |
||
40 | |||
41 | public function findOrLog(string $code): ?MediaInterface |
||
42 | { |
||
43 | $media = $this->mediaRepository->findOneEnabledByCode($code, $this->channelContext->getChannel()->getCode()); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
44 | |||
45 | if (false === $media instanceof MediaInterface) { |
||
46 | $this->logger->warning(sprintf( |
||
47 | 'Media with "%s" code was not found in the database.', |
||
48 | $code |
||
49 | )); |
||
50 | |||
51 | return null; |
||
52 | } |
||
53 | |||
54 | return $media; |
||
55 | } |
||
56 | } |
||
57 |