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')
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     */
57    public function getIndex()
58    {
59        return $this->index;
60    }
61
62    /**
63     *
64     * @return \Elastica\Client
65     */
66    protected function getConnection()
67    {
68        return $this->connection;
69    }
70
71    /**
72     *
73     * @return self
74     */
75    #[\Override]
76    public function loadLocations($locationJson, $locale = 'de')
77    {
78        $this->accessInstance[$locale]['Location'] = new Elastic\Location($locationJson, $locale);
79        $this->accessInstance[$locale]['Location']->setAccessInstance($this);
80        return $this;
81    }
82
83    /**
84     *
85     * @return self
86     */
87    #[\Override]
88    public function loadServices($serviceJson, $locale = 'de')
89    {
90        $this->accessInstance[$locale]['Service'] = new Elastic\Service($serviceJson, $locale);
91        $this->accessInstance[$locale]['Service']->setAccessInstance($this);
92        return $this;
93    }
94
95    /**
96     *
97     * @return self
98     */
99    #[\Override]
100    public function loadTopics($topicJson, $locale = 'de')
101    {
102        $this->accessInstance[$locale]['Topic'] = new Elastic\Topic($topicJson, $locale);
103        $this->accessInstance[$locale]['Topic']->setAccessInstance($this);
104        $this->accessInstance[$locale]['Link'] = new Elastic\Link($topicJson, $locale);
105        $this->accessInstance[$locale]['Link']->setAccessInstance($this);
106        return $this;
107    }
108
109    /**
110     *
111     * @return self
112     */
113    #[\Override]
114    public function loadSettings($settingsJson)
115    {
116        $this->accessInstance['de']['Setting'] = new Elastic\Setting($settingsJson);
117        $this->accessInstance['de']['Setting']->setAccessInstance($this);
118        $this->accessInstance['de']['Office'] = new Elastic\Office($settingsJson);
119        $this->accessInstance['de']['Office']->setAccessInstance($this);
120        $this->accessInstance['de']['Borough'] = new Elastic\Borough($settingsJson);
121        $this->accessInstance['de']['Borough']->setAccessInstance($this);
122        return $this;
123    }
124
125
126    /**
127     *
128     * @return self
129     */
130    #[\Override]
131    public function loadAuthorities($authorityJson, $locale = 'de')
132    {
133        $this->accessInstance[$locale]['Authority'] = new Elastic\Authority($authorityJson, $locale);
134        $this->accessInstance[$locale]['Authority']->setAccessInstance($this);
135        return $this;
136    }
137}