Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
ElasticAccess
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 9
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 connectElasticSearch
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 getIndex
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getConnection
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 loadLocations
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 loadServices
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 loadTopics
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 loadSettings
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 loadAuthorities
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * @package 115Mandant
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsdldb;
9
10/**
11 * @SuppressWarnings(TooManyMethods)
12 *
13 * Using elastica query classes increases object dependencies dramatically
14 * @SuppressWarnings(CouplingBetweenObjects)
15 */
16class ElasticAccess extends FileAccess
17{
18    /**
19     * The client used to talk to elastic search.
20     *
21     * @var \Elastica\Client
22     */
23    protected $connection;
24
25    /**
26      * Index from elastic search
27      *
28      * @var \Elastica\Index $index
29      */
30    protected $index;
31
32    /**
33     *
34     * @return self
35     */
36    public function __construct($index = null, $host = 'localhost', $port = '9200', $transport = 'Http')
37    {
38        if ($index) {
39            $this->connectElasticSearch($index, $host, $port, $transport);
40        }
41    }
42
43    public function connectElasticSearch($index, $host = 'localhost', $port = '9200', $transport = 'Http'): void
44    {
45        $this->connection = new \Elastica\Client(array(
46                'host' => $host,
47                'port' => $port,
48                'transport' => $transport
49        ));
50        $this->index = $this->getConnection()->getIndex($index);
51    }
52
53    /**
54     *
55     * @return \Elastica\Index
56     * @psalm-api
57     */
58    public function getIndex()
59    {
60        return $this->index;
61    }
62
63    /**
64     *
65     * @return \Elastica\Client
66     */
67    protected function getConnection()
68    {
69        return $this->connection;
70    }
71
72    /**
73     *
74     * @return self
75     */
76    #[\Override]
77    public function loadLocations($locationJson, $locale = 'de')
78    {
79        $this->accessInstance[$locale]['Location'] = new Elastic\Location($locationJson, $locale);
80        $this->accessInstance[$locale]['Location']->setAccessInstance($this);
81        return $this;
82    }
83
84    /**
85     *
86     * @return self
87     */
88    #[\Override]
89    public function loadServices($serviceJson, $locale = 'de')
90    {
91        $this->accessInstance[$locale]['Service'] = new Elastic\Service($serviceJson, $locale);
92        $this->accessInstance[$locale]['Service']->setAccessInstance($this);
93        return $this;
94    }
95
96    /**
97     *
98     * @return self
99     */
100    #[\Override]
101    public function loadTopics($topicJson, $locale = 'de')
102    {
103        $this->accessInstance[$locale]['Topic'] = new Elastic\Topic($topicJson, $locale);
104        $this->accessInstance[$locale]['Topic']->setAccessInstance($this);
105        $this->accessInstance[$locale]['Link'] = new Elastic\Link($topicJson, $locale);
106        $this->accessInstance[$locale]['Link']->setAccessInstance($this);
107        return $this;
108    }
109
110    /**
111     *
112     * @return self
113     */
114    #[\Override]
115    public function loadSettings($settingsJson)
116    {
117        $this->accessInstance['de']['Setting'] = new Elastic\Setting($settingsJson);
118        $this->accessInstance['de']['Setting']->setAccessInstance($this);
119        $this->accessInstance['de']['Office'] = new Elastic\Office($settingsJson);
120        $this->accessInstance['de']['Office']->setAccessInstance($this);
121        $this->accessInstance['de']['Borough'] = new Elastic\Borough($settingsJson);
122        $this->accessInstance['de']['Borough']->setAccessInstance($this);
123        return $this;
124    }
125
126
127    /**
128     *
129     * @return self
130     */
131    #[\Override]
132    public function loadAuthorities($authorityJson, $locale = 'de')
133    {
134        $this->accessInstance[$locale]['Authority'] = new Elastic\Authority($authorityJson, $locale);
135        $this->accessInstance[$locale]['Authority']->setAccessInstance($this);
136        return $this;
137    }
138}