|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\ViewHelpers; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the TYPO3 CMS project. |
|
7
|
|
|
* |
|
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
10
|
|
|
* of the License, or any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please read the |
|
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
14
|
|
|
* |
|
15
|
|
|
* The TYPO3 project - inspiring people to share! |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
|
19
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; |
|
20
|
|
|
use ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext; |
|
21
|
|
|
use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrViewHelper; |
|
22
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class AbstractViewHelper |
|
26
|
|
|
* |
|
27
|
|
|
* @author Frans Saris <[email protected]> |
|
28
|
|
|
* @author Timo Hund <[email protected]> |
|
29
|
|
|
* @package ApacheSolrForTypo3\Solr\ViewHelpers |
|
30
|
|
|
*/ |
|
31
|
|
|
abstract class AbstractSolrFrontendViewHelper extends AbstractSolrViewHelper |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var SolrControllerContext |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $controllerContext; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return TypoScriptConfiguration |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function getTypoScriptConfiguration() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->getControllerContext()->getTypoScriptConfiguration(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return SearchResultSet |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function getSearchResultSet() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->getControllerContext()->getSearchResultSet(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @todo The fallback on $this->controllerContext is only needed for TYPO3 8 backwards compatibility and can be dropped when TYPO3 8 is not supported anymore |
|
56
|
|
|
* @return SolrControllerContext |
|
57
|
|
|
* @throws \InvalidArgumentException |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function getControllerContext() |
|
60
|
|
|
{ |
|
61
|
|
|
$controllerContext = null; |
|
62
|
|
|
if (!is_null($this->controllerContext)) { |
|
63
|
|
|
$controllerContext = $this->controllerContext; |
|
64
|
|
|
} elseif (method_exists($this->renderingContext, 'getControllerContext')) { |
|
65
|
|
|
$controllerContext = $this->renderingContext->getControllerContext(); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if (!$controllerContext instanceof SolrControllerContext) { |
|
69
|
|
|
throw new \InvalidArgumentException('No valid SolrControllerContext found', 1512998673); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $controllerContext; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param RenderingContextInterface $renderingContext |
|
77
|
|
|
* @return SearchResultSet |
|
78
|
|
|
*/ |
|
79
|
31 |
|
protected static function getUsedSearchResultSetFromRenderingContext(RenderingContextInterface $renderingContext) |
|
80
|
|
|
{ |
|
81
|
31 |
|
$resultSet = $renderingContext->getVariableProvider()->get('resultSet'); |
|
82
|
31 |
|
return $resultSet; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: