Issues (202)

Classes/ViewHelpers/Uri/AbstractUriViewHelper.php (1 issue)

Severity
1
<?php
2
namespace ApacheSolrForTypo3\Solr\ViewHelpers\Uri;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
18
use ApacheSolrForTypo3\Solr\Domain\Search\Uri\SearchUriBuilder;
19
use ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext;
20
use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper;
21
use TYPO3\CMS\Core\Utility\GeneralUtility;
22
use TYPO3\CMS\Extbase\Object\ObjectManager;
23
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
24
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
25
26
/**
27
 * Class AbstractUriViewHelper
28
 *
29
 * @author Frans Saris <[email protected]>
30
 * @author Timo Hund <[email protected]>
31
 */
32
abstract class AbstractUriViewHelper extends AbstractSolrFrontendViewHelper
33
{
34
    use CompileWithRenderStatic;
35
36
    /**
37
     * @var SearchUriBuilder
38
     */
39
    protected static $searchUriBuilder;
40
41
    /**
42
     * @param SearchUriBuilder $searchUriBuilder
43
     */
44 38
    public function injectSearchUriBuilder(SearchUriBuilder $searchUriBuilder)
45
    {
46 38
        self::$searchUriBuilder = $searchUriBuilder;
47 38
    }
48
49
    /**
50
     * @param RenderingContextInterface|null $renderingContext
51
     * @return SearchUriBuilder|object
52 39
     */
53
    protected static function getSearchUriBuilder(RenderingContextInterface $renderingContext = null)
54 39
    {
55 27
        if (!isset(self::$searchUriBuilder)) {
56 27
            $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
57
            self::$searchUriBuilder = $objectManager->get(SearchUriBuilder::class);
58
        }
59 39
60
        if ($renderingContext && method_exists($renderingContext, 'getControllerContext')) {
61
            self::$searchUriBuilder->injectUriBuilder($renderingContext->getControllerContext()->getUriBuilder());
62
        }
63
64
        return self::$searchUriBuilder;
65
    }
66 35
67 35
    /**
68 35
     * @param RenderingContextInterface $renderingContext
69
     * @return mixed
70
     */
71
    protected static function getUsedSearchRequestFromRenderingContext(RenderingContextInterface $renderingContext) {
72 35
        $resultSet = static::getUsedSearchResultSetFromRenderingContext($renderingContext);
73
        if (!$resultSet instanceof SearchResultSet) {
0 ignored issues
show
$resultSet is always a sub-type of ApacheSolrForTypo3\Solr\...sultSet\SearchResultSet.
Loading history...
74
            throw new \InvalidArgumentException("The variable resultSet need to be defined in the scope of " . static::class);
75
        }
76
77
        return $resultSet->getUsedSearchRequest();
78
    }
79
}
80