Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 35
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 / 35
0.00% covered (danger)
0.00%
0 / 9
156
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 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getConnection
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 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|null
22     */
23    protected $connection = null;
24
25    /**
26      * Index from elastic search
27      *
28      * @var \Elastica\Index|null $index
29      */
30    protected $index = null;
31
32    /**
33     *
34     * @return self
35     */
36    public function __construct(mixed $index = null, string $host = 'localhost', string $port = '9200', string $transport = 'Http')
37    {
38        if ($index) {
39            $this->connectElasticSearch($index, $host, $port, $transport);
40        }
41    }
42
43    public function connectElasticSearch(mixed $index, string $host = 'localhost', string $port = '9200', string $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        if (!$this->index instanceof \Elastica\Index) {
61            throw new Exception('ElasticSearch index is not initialized');
62        }
63        return $this->index;
64    }
65
66    /**
67     *
68     * @return \Elastica\Client
69     */
70    protected function getConnection()
71    {
72        if (!$this->connection instanceof \Elastica\Client) {
73            throw new Exception('ElasticSearch connection is not initialized');
74        }
75        return $this->connection;
76    }
77
78    /**
79     *
80     * @return self
81     */
82    #[\Override]
83    public function loadLocations(mixed $locationJson, string $locale = 'de')
84    {
85        $this->accessInstance[$locale]['Location'] = new Elastic\Location($locationJson, $locale);
86        $this->accessInstance[$locale]['Location']->setAccessInstance($this);
87        return $this;
88    }
89
90    /**
91     *
92     * @return self
93     */
94    #[\Override]
95    public function loadServices(mixed $serviceJson, string $locale = 'de')
96    {
97        $this->accessInstance[$locale]['Service'] = new Elastic\Service($serviceJson, $locale);
98        $this->accessInstance[$locale]['Service']->setAccessInstance($this);
99        return $this;
100    }
101
102    /**
103     *
104     * @return self
105     */
106    #[\Override]
107    public function loadTopics(mixed $topicJson, string $locale = 'de')
108    {
109        $this->accessInstance[$locale]['Topic'] = new Elastic\Topic($topicJson, $locale);
110        $this->accessInstance[$locale]['Topic']->setAccessInstance($this);
111        $this->accessInstance[$locale]['Link'] = new Elastic\Link($topicJson, $locale);
112        $this->accessInstance[$locale]['Link']->setAccessInstance($this);
113        return $this;
114    }
115
116    /**
117     *
118     * @return self
119     */
120    #[\Override]
121    public function loadSettings(mixed $settingsJson)
122    {
123        $this->accessInstance['de']['Setting'] = new Elastic\Setting($settingsJson);
124        $this->accessInstance['de']['Setting']->setAccessInstance($this);
125        $this->accessInstance['de']['Office'] = new Elastic\Office($settingsJson);
126        $this->accessInstance['de']['Office']->setAccessInstance($this);
127        $this->accessInstance['de']['Borough'] = new Elastic\Borough($settingsJson);
128        $this->accessInstance['de']['Borough']->setAccessInstance($this);
129        return $this;
130    }
131
132
133    /**
134     *
135     * @return self
136     */
137    #[\Override]
138    public function loadAuthorities(mixed $authorityJson, string $locale = 'de')
139    {
140        $this->accessInstance[$locale]['Authority'] = new Elastic\Authority($authorityJson, $locale);
141        $this->accessInstance[$locale]['Authority']->setAccessInstance($this);
142        return $this;
143    }
144}