Completed
Push — master ( 5919d7...94bd1b )
by Rafael
05:28
created

SolrConnection   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 183
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 2
dl 0
loc 183
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 25 1
A getAdminService() 0 8 2
A buildAdminService() 0 4 1
A getReadService() 0 8 2
A buildReadService() 0 4 1
A getWriteService() 0 8 2
A buildWriteService() 0 4 1
A initializeService() 0 7 2
1
<?php
2
namespace ApacheSolrForTypo3\Solr\System\Solr;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2009-2015 Ingo Renner <[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 2 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\Configuration\TypoScriptConfiguration;
28
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
29
use ApacheSolrForTypo3\Solr\System\Solr\Parser\SchemaParser;
30
use ApacheSolrForTypo3\Solr\System\Solr\Parser\StopWordParser;
31
use ApacheSolrForTypo3\Solr\System\Solr\Parser\SynonymParser;
32
use ApacheSolrForTypo3\Solr\System\Solr\Service\AbstractSolrService;
33
use ApacheSolrForTypo3\Solr\System\Solr\Service\SolrAdminService;
34
use ApacheSolrForTypo3\Solr\System\Solr\Service\SolrReadService;
35
use ApacheSolrForTypo3\Solr\System\Solr\Service\SolrWriteService;
36
use TYPO3\CMS\Core\Utility\GeneralUtility;
37
38
/**
39
 * Solr Service Access
40
 *
41
 * @author Ingo Renner <[email protected]>
42
 */
43
class SolrConnection
44
{
45
    /**
46
     * @var SolrAdminService
47
     */
48
    protected $adminService;
49
50
    /**
51
     * @var SolrReadService
52
     */
53
    protected $readService;
54
55
    /**
56
     * @var SolrWriteService
57
     */
58
    protected $writeService;
59
60
    /**
61
     * @var TypoScriptConfiguration
62
     */
63
    protected $configuration;
64
65
    /**
66
     * @var SynonymParser
67
     */
68
    protected $synonymParser = null;
69
70
    /**
71
     * @var StopWordParser
72
     */
73
    protected $stopWordParser = null;
74
75
    /**
76
     * @var SchemaParser
77
     */
78
    protected $schemaParser = null;
79
80
    /**
81
     * @var string
82
     */
83
    protected $host = '';
84
85
    /**
86
     * @var string
87
     */
88
    protected $port = '8983';
89
90
    /**
91
     * @var string
92
     */
93
    protected $path = '/solr/';
94
95
    /**
96
     * @var string
97
     */
98
    protected $scheme = 'http';
99
100
    /**
101
     * @var string
102
     */
103
    protected $username = '';
104
105
    /**
106
     * @var string
107
     */
108
    protected $password = '';
109
110
    /**
111
     * @var SolrLogManager
112
     */
113
    protected $logger = null;
114
115
    /**
116
     * Constructor
117
     *
118
     * @param string $host Solr host
119
     * @param string $port Solr port
120
     * @param string $path Solr path
121
     * @param string $scheme Scheme, defaults to http, can be https
122
     * @param TypoScriptConfiguration $typoScriptConfiguration
123
     * @param SynonymParser $synonymParser
124
     * @param StopWordParser $stopWordParser
125
     * @param SchemaParser $schemaParser
126
     * @param SolrLogManager $logManager
127
     */
128
    public function __construct(
129
        $host = '',
130
        $port = '8983',
131
        $path = '/solr/',
132
        $scheme = 'http',
133
        $username = '',
134
        $password = '',
135
        TypoScriptConfiguration $typoScriptConfiguration = null,
136
        SynonymParser $synonymParser = null,
137
        StopWordParser $stopWordParser = null,
138
        SchemaParser $schemaParser = null,
139
        SolrLogManager $logManager = null
140
    ) {
141
        $this->host = $host;
142
        $this->port = $port;
143
        $this->path = $path;
144
        $this->scheme = $scheme;
145
        $this->username = $username;
146
        $this->password = $password;
147
        $this->configuration = $typoScriptConfiguration;
148
        $this->synonymParser = $synonymParser;
149
        $this->stopWordParser = $stopWordParser;
150
        $this->schemaParser = $schemaParser;
151
        $this->logger = $logManager;
152
    }
153
154
    /**
155
     * @return SolrAdminService
156
     */
157
    public function getAdminService()
158
    {
159
        if ($this->adminService === null) {
160
            $this->adminService = $this->buildAdminService();
161
        }
162
163
        return $this->initializeService($this->adminService);
164
    }
165
166
    /**
167
     * @return SolrAdminService
168
     */
169
    protected function buildAdminService()
170
    {
171
        return GeneralUtility::makeInstance(SolrAdminService::class, $this->host, $this->port, $this->path, $this->scheme, $this->configuration, $this->logger, $this->synonymParser, $this->stopWordParser, $this->schemaParser);
172
    }
173
174
    /**
175
     * @return SolrReadService
176
     */
177
    public function getReadService()
178
    {
179
        if ($this->readService === null) {
180
            $this->readService = $this->buildReadService();
181
        }
182
183
        return $this->initializeService($this->readService);
184
    }
185
186
    /**
187
     * @return SolrReadService
188
     */
189
    protected function buildReadService()
190
    {
191
        return GeneralUtility::makeInstance(SolrReadService::class, $this->host, $this->port, $this->path, $this->scheme, $this->configuration, $this->logger);
192
    }
193
194
    /**
195
     * @return SolrWriteService
196
     */
197
    public function getWriteService()
198
    {
199
        if ($this->writeService === null) {
200
            $this->writeService = $this->buildWriteService();
201
        }
202
203
        return $this->initializeService($this->writeService);
204
    }
205
206
    /**
207
     * @return SolrWriteService
208
     */
209
    protected function buildWriteService()
210
    {
211
        return GeneralUtility::makeInstance(SolrWriteService::class, $this->host, $this->port, $this->path, $this->scheme, $this->configuration, $this->logger);
212
    }
213
214
    /**
215
     * @param AbstractSolrService $service
216
     * @return AbstractSolrService
217
     */
218
    protected function initializeService(AbstractSolrService $service) {
219
        if (trim($this->username) !== '') {
220
            $service->setAuthenticationCredentials($this->username, $this->password);
221
        }
222
223
        return $service;
224
    }
225
}
226