-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.php
73 lines (59 loc) · 1.48 KB
/
Config.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
<?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 Config extends Object {
/**
* @var string Source name
*/
public $name;
/**
* @var array|Attribute[]
*/
public $attributes = [];
/**
* @var Attribute[]
*/
private $_attributes = [];
/**
* @param array $config
*/
public function __construct($config) {
parent::__construct($config);
if (!$this->name) {
throw new \Exception("Name is required for Config");
}
foreach ($this->attributes as $name => $value) {
if ($value instanceof Attribute) {
$this->_attributes[] = $value;
} else {
$this->_attributes[] = new Attribute([
'name' => $name, 'value' => $value
]);
}
}
}
/**
* @return string
*/
public function getContent() {
$content = "$this->name { \n";
foreach ($this->_attributes as $attribute) {
$content .= $attribute->getContent();
}
$content .= "} \n";
return $content;
}
/**
* @return Attribute[]
*/
public function getAttributes() {
return $this->_attributes;
}
}