Passed
Push — master ( ee4dec...064f0a )
by Timo
53s
created

AbstractFacetPackage::getQueryBuilderClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets;
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
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
17
18
/**
19
 * Class AbstractFacetPackage
20
 * @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets
21
 */
22
abstract class AbstractFacetPackage {
23
    /**
24
     * @var ObjectManagerInterface
25
     */
26
    protected $objectManager;
27
28
    /**
29
     * @param ObjectManagerInterface $objectManager
30
     */
31
    public function setObjectManager(ObjectManagerInterface $objectManager)
32
    {
33
        $this->objectManager = $objectManager;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    abstract public function getParserClassName();
40
41
    /**
42
     * @return FacetParserInterface
43
     * @throws InvalidFacetPackageException
44
     */
45
    public function getParser()
46
    {
47
        $parser = $this->objectManager->get($this->getParserClassName());
48
        if (!$parser instanceof FacetParserInterface) {
49
            throw new InvalidFacetPackageException('Invalid parser for package ' . __CLASS__ );
50
        }
51
        return $parser;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getUrlDecoderClassName() {
58
        return (string)DefaultUrlDecoder::class;
59
    }
60
61
    /**
62
     * @throws InvalidUrlDecoderException
63
     * @return FacetUrlDecoderInterface
64
     */
65
    public function getUrlDecoder()
66
    {
67
        $urlDecoder = $this->objectManager->get($this->getUrlDecoderClassName());
68
        if (!$urlDecoder instanceof FacetUrlDecoderInterface) {
69
            throw new InvalidUrlDecoderException('Invalid urldecoder for package ' . __CLASS__ );
70
        }
71
        return $urlDecoder;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getQueryBuilderClassName() {
78
        return (string)DefaultFacetQueryBuilder::class;
79
    }
80
81
    /**
82
     * @throws InvalidQueryBuilderException
83
     * @return FacetQueryBuilderInterface
84
     */
85
    public function getQueryBuilder()
86
    {
87
        $urlDecoder = $this->objectManager->get($this->getQueryBuilderClassName());
88
        if(!$urlDecoder instanceof FacetQueryBuilderInterface) {
89
            throw new InvalidQueryBuilderException('Invalid querybuilder for package ' . __CLASS__ );
90
        }
91
        return $urlDecoder;
92
    }
93
}