Completed
Push — task/master/1311-combine-facet... ( c66844...a56b0a )
by Timo
21:49
created

FacetUrlDecoderRegistry::getUrlDecoder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.032
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
17
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Hierarchy\HierarchyUrlDecoder;
18
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\QueryGroup\QueryGroupUrlDecoder;
19
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\DateRange\DateRangeUrlDecoder;
20
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\NumericRange\NumericRangeUrlDecoder;
21
use ApacheSolrForTypo3\Solr\System\Object\AbstractClassRegistry;
22
23
/**
24
 * Class FacetUrlEncoderRegistry
25
 *
26
 * Responsibility: This class can be used to register and retrieve classed that are
27
 * responsible to encode and decode the facet values for the EXT:solr urls.
28
 *
29
 * @author Frans Saris <[email protected]>
30
 * @author Timo Hund <[email protected]>
31
 * @package ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets
32
 */
33
class FacetUrlDecoderRegistry extends AbstractClassRegistry
34
{
35
36
    /**
37
     * Array of available encoder classNames
38
     * @var array
39
     */
40
    protected $classMap = [
41
        'hierarchy' => HierarchyUrlDecoder::class,
42
        'queryGroup' => QueryGroupUrlDecoder::class,
43
        'dateRange' => DateRangeUrlDecoder::class,
44
        'numericRange' => NumericRangeUrlDecoder::class
45
    ];
46
47
    /**
48
     * Default parser className
49
     *
50
     * @var string
51
     */
52
    protected $defaultClass = DefaultUrlDecoder::class;
53
54
    /**
55
     * Get url encoder
56
     *
57
     * @param string $type
58
     * @return FacetUrlDecoderInterface
59
     * @throws \Exception
60
     */
61 3
    public function getUrlDecoder($type)
62
    {
63 3
        $instance = $this->getInstance($type);
64 3
        if(!$instance instanceof FacetUrlDecoderInterface) {
65
            throw new \Exception('Invalid class registered for ' . htmlspecialchars($type));
66
        }
67 3
        return $instance;
68
    }
69
}
70