1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author: Viskov Sergey |
4
|
|
|
* @date : 3/3/16 |
5
|
|
|
* @time : 5:13 PM |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace LTDBeget\sphinx\configurator\serializers; |
9
|
|
|
|
10
|
|
|
use LTDBeget\sphinx\configurator\Configuration; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class PlainSerializer |
14
|
|
|
* serialize Configuration object to string for file .conf |
15
|
|
|
* |
16
|
|
|
* @package LTDBeget\sphinx\configurator\serializers |
17
|
|
|
*/ |
18
|
|
|
final class PlainSerializer |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $string = ''; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Configuration |
27
|
|
|
*/ |
28
|
|
|
private $object; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @internal |
32
|
|
|
* ArrayDeserializer constructor. |
33
|
|
|
*/ |
34
|
3 |
|
private function __construct() |
35
|
|
|
{ |
36
|
3 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Make plain content for sphinx configuration file from Configuration object |
40
|
|
|
* |
41
|
|
|
* @param Configuration $configuration |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
* @throws \LTDBeget\sphinx\configurator\exceptions\ConfigurationException |
45
|
|
|
*/ |
46
|
3 |
|
public static function serialize(Configuration $configuration) : string |
47
|
|
|
{ |
48
|
3 |
|
$serializer = new self(); |
49
|
3 |
|
$serializer->object = $configuration; |
50
|
|
|
|
51
|
3 |
|
return $serializer->serializeInternal(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @internal |
56
|
|
|
* @return string |
57
|
|
|
* @throws \LTDBeget\sphinx\configurator\exceptions\ConfigurationException |
58
|
|
|
*/ |
59
|
3 |
|
public function serializeInternal() : string |
60
|
|
|
{ |
61
|
3 |
|
$this->serializeSources(); |
62
|
3 |
|
$this->serializeIndexes(); |
63
|
3 |
|
$this->serializeIndexer(); |
64
|
3 |
|
$this->serializeSearchd(); |
65
|
3 |
|
$this->serializeCommon(); |
66
|
|
|
|
67
|
3 |
|
return $this->string; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @internal |
72
|
|
|
*/ |
73
|
3 |
|
private function serializeSources() |
74
|
|
|
{ |
75
|
3 |
|
foreach ($this->object->iterateSource() as $source) { |
76
|
2 |
|
$this->string .= (string) $source; |
77
|
|
|
} |
78
|
3 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @internal |
82
|
|
|
*/ |
83
|
3 |
|
private function serializeIndexes() |
84
|
|
|
{ |
85
|
3 |
|
foreach ($this->object->iterateIndex() as $index) { |
86
|
2 |
|
$this->string .= (string) $index; |
87
|
|
|
} |
88
|
3 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @internal |
92
|
|
|
*/ |
93
|
3 |
|
private function serializeIndexer() |
94
|
|
|
{ |
95
|
3 |
|
if ($this->object->isHasIndexer()) { |
96
|
1 |
|
$this->string .= (string) $this->object->getIndexer(); |
97
|
|
|
} |
98
|
3 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @internal |
102
|
|
|
*/ |
103
|
3 |
|
private function serializeSearchd() |
104
|
|
|
{ |
105
|
3 |
|
if ($this->object->isHasSearchd()) { |
106
|
1 |
|
$this->string .= (string) $this->object->getSearchd(); |
107
|
|
|
} |
108
|
3 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @internal |
112
|
|
|
* @throws \LTDBeget\sphinx\configurator\exceptions\ConfigurationException |
113
|
|
|
*/ |
114
|
3 |
|
private function serializeCommon() |
115
|
|
|
{ |
116
|
3 |
|
if ($this->object->isHasCommon()) { |
117
|
2 |
|
$this->string .= (string) $this->object->getCommon(); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |