1 | <?php |
||
16 | class PageProvider |
||
17 | { |
||
18 | /** |
||
19 | * @var PageService |
||
20 | */ |
||
21 | private $pageService; |
||
22 | |||
23 | /** |
||
24 | * @var BlockService |
||
25 | */ |
||
26 | private $blockService; |
||
27 | |||
28 | /** |
||
29 | * @var GlobalContext |
||
30 | */ |
||
31 | private $globalContext; |
||
32 | |||
33 | /** |
||
34 | * PageProvider constructor. |
||
35 | * |
||
36 | * @param PageService $pageService |
||
37 | * @param BlockService $blockService |
||
38 | * @param GlobalContext $globalContext |
||
39 | */ |
||
40 | public function __construct(PageService $pageService, BlockService $blockService, GlobalContext $globalContext) |
||
46 | |||
47 | /** |
||
48 | * Fetches the page by the slug. |
||
49 | * |
||
50 | * Page blocks are translated in the user language, if the translation does not exist the default language is used. |
||
51 | * If the default language is also not available a exception is thrown. |
||
52 | * |
||
53 | * @param string $slug |
||
54 | * |
||
55 | * @return PageStruct |
||
56 | * |
||
57 | * @throws PageNotFoundException Thrown if the page could not be found |
||
58 | * @throws PageTranslationNotFoundException Thrown if no translation of the page could be found |
||
59 | */ |
||
60 | public function getPageBySlug($slug) |
||
100 | |||
101 | /** |
||
102 | * Fetches all page blocks by the given page and locale. |
||
103 | * |
||
104 | * @param PageEntity $page |
||
105 | * @param string $locale |
||
106 | * |
||
107 | * @return BlockEntity[] |
||
108 | */ |
||
109 | private function getPageBlocks(PageEntity $page, $locale) |
||
117 | |||
118 | /** |
||
119 | * Fetches the page by the given slug. |
||
120 | * |
||
121 | * @param string $slug |
||
122 | * |
||
123 | * @return null|PageEntity |
||
124 | * |
||
125 | * @throws PageNotFoundException Thrown if the page could not be found |
||
126 | */ |
||
127 | private function getPage($slug) |
||
140 | } |
||
141 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: