1 | <?php |
||||
2 | namespace ApacheSolrForTypo3\Solr\System\Configuration; |
||||
3 | |||||
4 | /*************************************************************** |
||||
5 | * Copyright notice |
||||
6 | * |
||||
7 | * (c) 2010-2016 Timo Schmidt <[email protected] |
||||
8 | * All rights reserved |
||||
9 | * |
||||
10 | * This script is part of the TYPO3 project. The TYPO3 project is |
||||
11 | * free software; you can redistribute it and/or modify |
||||
12 | * it under the terms of the GNU General Public License as published by |
||||
13 | * the Free Software Foundation; either version 3 of the License, or |
||||
14 | * (at your option) any later version. |
||||
15 | * |
||||
16 | * The GNU General Public License can be found at |
||||
17 | * http://www.gnu.org/copyleft/gpl.html. |
||||
18 | * |
||||
19 | * This script is distributed in the hope that it will be useful, |
||||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
22 | * GNU General Public License for more details. |
||||
23 | * |
||||
24 | * This copyright notice MUST APPEAR in all copies of the script! |
||||
25 | ***************************************************************/ |
||||
26 | |||||
27 | use ApacheSolrForTypo3\Solr\System\Cache\TwoLevelCache; |
||||
28 | use ApacheSolrForTypo3\Solr\System\Records\SystemTemplate\SystemTemplateRepository; |
||||
29 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||||
30 | use TYPO3\CMS\Core\Utility\RootlineUtility; |
||||
31 | use TYPO3\CMS\Frontend\Page\PageRepository; |
||||
32 | |||||
33 | /** |
||||
34 | * This class is responsible to find the closest page id from the rootline where |
||||
35 | * a typoscript template is stored on. |
||||
36 | * |
||||
37 | * @author Timo Hund <[email protected]> |
||||
38 | */ |
||||
39 | class ConfigurationPageResolver |
||||
40 | { |
||||
41 | |||||
42 | /** |
||||
43 | * @var SystemTemplateRepository |
||||
44 | */ |
||||
45 | protected $systemTemplateRepository; |
||||
46 | |||||
47 | /** |
||||
48 | * @var TwoLevelCache |
||||
49 | */ |
||||
50 | protected $twoLevelCache; |
||||
51 | |||||
52 | /** |
||||
53 | * @var TwoLevelCache |
||||
54 | */ |
||||
55 | protected $runtimeCache; |
||||
56 | |||||
57 | /** |
||||
58 | * ConfigurationPageResolver constructor. |
||||
59 | * @param PageRepository|null $pageRepository |
||||
60 | * @param TwoLevelCache|null $twoLevelCache |
||||
61 | * @param SystemTemplateRepository $systemTemplateRepository |
||||
62 | */ |
||||
63 | public function __construct(PageRepository $pageRepository = null, TwoLevelCache $twoLevelCache = null, SystemTemplateRepository $systemTemplateRepository = null) |
||||
0 ignored issues
–
show
|
|||||
64 | { |
||||
65 | $this->runtimeCache = $twoLevelCache ?? GeneralUtility::makeInstance(TwoLevelCache::class, /** @scrutinizer ignore-type */ 'cache_runtime'); |
||||
66 | $this->systemTemplateRepository = $systemTemplateRepository ?? GeneralUtility::makeInstance(SystemTemplateRepository::class); |
||||
67 | 1 | } |
|||
68 | |||||
69 | 1 | /** |
|||
70 | 1 | * This method fetches the rootLine and calculates the id of the closest template in the rootLine. |
|||
71 | 1 | * The result is stored in the runtime cache. |
|||
72 | 1 | * |
|||
73 | * @param integer $startPageId |
||||
74 | * @return integer |
||||
75 | */ |
||||
76 | public function getClosestPageIdWithActiveTemplate($startPageId) |
||||
77 | { |
||||
78 | if ($startPageId === 0) { |
||||
79 | return 0; |
||||
80 | } |
||||
81 | 1 | ||||
82 | $cacheId = 'ConfigurationPageResolver' . '_' . 'getClosestPageIdWithActiveTemplate' . '_' . $startPageId; |
||||
83 | 1 | $methodResult = $this->runtimeCache->get($cacheId); |
|||
84 | if (!empty($methodResult)) { |
||||
85 | return $methodResult; |
||||
86 | } |
||||
87 | 1 | ||||
88 | 1 | $methodResult = $this->calculateClosestPageIdWithActiveTemplate($startPageId); |
|||
89 | 1 | $this->runtimeCache->set($cacheId, $methodResult); |
|||
90 | |||||
91 | return $methodResult; |
||||
92 | } |
||||
93 | 1 | ||||
94 | 1 | /** |
|||
95 | * This method fetches the rootLine and calculates the id of the closest template in the rootLine. |
||||
96 | 1 | * |
|||
97 | * @param integer $startPageId |
||||
98 | * @return int |
||||
99 | */ |
||||
100 | protected function calculateClosestPageIdWithActiveTemplate($startPageId) |
||||
101 | { |
||||
102 | |||||
103 | $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $startPageId); |
||||
0 ignored issues
–
show
$startPageId of type integer is incompatible with the type array|array<mixed,mixed> expected by parameter $constructorArguments of TYPO3\CMS\Core\Utility\G...Utility::makeInstance() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
104 | try { |
||||
105 | 1 | $rootline = $rootlineUtility->get(); |
|||
106 | } catch (\RuntimeException $e) { |
||||
107 | 1 | return $startPageId; |
|||
108 | } |
||||
109 | 1 | ||||
110 | $closestPageIdWithTemplate = $this->systemTemplateRepository->findOneClosestPageIdWithActiveTemplateByRootLine($rootline); |
||||
111 | if ($closestPageIdWithTemplate === 0) { |
||||
112 | return $startPageId; |
||||
113 | 1 | } |
|||
114 | 1 | ||||
115 | return (int)$closestPageIdWithTemplate; |
||||
116 | } |
||||
117 | } |
||||
118 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.