1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file was created by the 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\CmsPlugin\Resolver; |
14
|
|
|
|
15
|
|
|
use BitBag\CmsPlugin\Entity\PageInterface; |
16
|
|
|
use BitBag\CmsPlugin\Repository\PageRepositoryInterface; |
17
|
|
|
use Psr\Log\LoggerInterface; |
18
|
|
|
use Sylius\Component\Locale\Context\LocaleContextInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Mikołaj Król <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
final class PageResourceResolver implements PageResourceResolverInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var PageRepositoryInterface |
27
|
|
|
*/ |
28
|
|
|
private $pageRepository; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var LocaleContextInterface |
32
|
|
|
*/ |
33
|
|
|
private $localeContext; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var LoggerInterface |
37
|
|
|
*/ |
38
|
|
|
private $logger; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param PageRepositoryInterface $pageRepository |
42
|
|
|
* @param LocaleContextInterface $localeContext |
43
|
|
|
* @param LoggerInterface $logger |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
PageRepositoryInterface $pageRepository, |
47
|
|
|
LocaleContextInterface $localeContext, |
48
|
|
|
LoggerInterface $logger |
49
|
|
|
) |
50
|
|
|
{ |
51
|
|
|
$this->pageRepository = $pageRepository; |
52
|
|
|
$this->localeContext = $localeContext; |
53
|
|
|
$this->logger = $logger; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function findOrLog(string $code): ?PageInterface |
60
|
|
|
{ |
61
|
|
|
$page = $this->pageRepository->findOneEnabledByCode($code, $this->localeContext->getLocaleCode()); |
62
|
|
|
|
63
|
|
|
if (false === $page instanceof PageInterface) { |
64
|
|
|
$this->logger->warning(sprintf( |
65
|
|
|
'Page with "%s" code was not found in the database.', |
66
|
|
|
$code |
67
|
|
|
)); |
68
|
|
|
|
69
|
|
|
return null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $page; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|