-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigGenerator.php
85 lines (68 loc) · 1.56 KB
/
ConfigGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @link https://github.com/ruskid/sphinx-config-generator-php
* @copyright Copyright (c) 2014 Victor Demin
* @license https://raw.githubusercontent.com/ruskid/sphinx-config-generator-php/master/LICENSE
*/
namespace ruskid\sphinx;
/**
* @author Victor Demin <[email protected]>
*/
class ConfigGenerator extends Object {
/**
* @var string
*/
public $filepath;
/**
* @var Source[]
*/
private $_sources = [];
/**
* @var Index[]
*/
private $_indexes = [];
/**
* @var Config[]
*/
private $_configs = [];
/**
* @param Source $source
*/
public function addSource(Source $source) {
$this->_sources[] = $source;
}
/**
* @param Config $config
*/
public function addConfig(Config $config) {
$this->_configs[] = $config;
}
/**
* @param Index $index
*/
public function addIndex(Index $index) {
$this->_indexes[] = $index;
}
/**
* @return string
*/
public function getContent() {
$content = '';
foreach ($this->_configs as $config) {
$content .= $config->getContent();
}
foreach ($this->_sources as $source) {
$content .= $source->getContent();
}
foreach ($this->_indexes as $index) {
$content .= $index->getContent();
}
return $content;
}
/**
* Save content to filepath
*/
public function saveConfig() {
file_put_contents($this->filepath, $this->getContent());
}
}