-
Notifications
You must be signed in to change notification settings - Fork 0
/
Attribute.php
62 lines (51 loc) · 1.24 KB
/
Attribute.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
<?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;
/**
* Sphinx config attribute
*
* @author Victor Demin <[email protected]>
*/
class Attribute extends Object {
/**
* @var string
*/
public $name;
/**
* @var mixed
*/
public $value;
/**
* @param array $config
*/
public function __construct($config) {
parent::__construct($config);
if (!$this->name && $this->value === null) {
throw new \Exception("Name and value is required for Attribute");
}
}
/**
* @param string $value
* @return string
*/
protected function handleSingleValue($value) {
return "\t{$this->name}={$value}\n";
}
/**
* @return string
*/
public function getContent() {
if (!is_array($this->value)) {
return $this->handleSingleValue($this->value);
}
$content = '';
foreach ($this->value as $value) {
$content .= $this->handleSingleValue($value);
}
return $content;
}
}