1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author: Viskov Sergey |
4
|
|
|
* @date : 3/18/16 |
5
|
|
|
* @time : 5:32 PM |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace LTDBeget\sphinx\configurator\configurationEntities\sections; |
9
|
|
|
|
10
|
|
|
use LTDBeget\sphinx\configurator\configurationEntities\base\Definition; |
11
|
|
|
use LTDBeget\sphinx\configurator\configurationEntities\Option; |
12
|
|
|
use LTDBeget\sphinx\enums\options\eIndexOption; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Index |
16
|
|
|
* |
17
|
|
|
* @package LTDBeget\sphinx\configurator\configurationEntities\base\sections |
18
|
|
|
*/ |
19
|
|
|
class Index extends Definition |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @param eIndexOption $name |
23
|
|
|
* @param string $value |
24
|
|
|
* |
25
|
|
|
* @return Option |
26
|
|
|
* @throws \LogicException |
27
|
|
|
* @throws \InvalidArgumentException |
28
|
|
|
* @throws \LTDBeget\sphinx\informer\exceptions\InformerRuntimeException |
29
|
|
|
*/ |
30
|
7 |
|
public function addOption(eIndexOption $name, string $value) : Option |
31
|
|
|
{ |
32
|
7 |
|
return $this->addOptionInternal($name, $value); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return Source |
37
|
|
|
*/ |
38
|
|
|
public function findSource() : Source |
39
|
|
|
{ |
40
|
|
|
$source_name = NULL; |
41
|
|
|
$index = $this; |
42
|
|
|
|
43
|
|
|
do { |
44
|
|
|
foreach ($index->iterateOptions() as $option) { |
45
|
|
|
if(eIndexOption::SOURCE()->is($option->getName()) ) { |
46
|
|
|
$source_name = $option->getValue(); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
if($index->isHasInheritance()) { |
50
|
|
|
$index = $index->getInheritance(); |
51
|
|
|
} |
52
|
|
|
} while($index->isHasInheritance()); |
53
|
|
|
|
54
|
|
|
foreach ($this->getConfiguration()->iterateSource() as $source) { |
55
|
|
|
if($source->getName() === $source_name) { |
56
|
|
|
return $source; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
throw new \RuntimeException('Source for index does not found'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
public function isDistributed() : bool |
67
|
|
|
{ |
68
|
|
|
$indexWithoutSource = false; |
69
|
|
|
foreach ($this->iterateOptions() as $option) { |
70
|
|
|
if ($option->getName()->is(eIndexOption::TYPE()) && $option->getValue() === 'distributed') { |
71
|
|
|
$indexWithoutSource = true; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $indexWithoutSource; |
76
|
|
|
} |
77
|
|
|
} |