-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAttribute.php
79 lines (71 loc) · 2 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
// Attribute class (an extended key value pair)
class Attribute
{
private $key;
private $value;
private $extras;
public function __construct($input)
{
$bits = explode(':', trim($input));
if (count($bits) > 1) {
$this->key = $bits[0];
$this->value = $bits[1];
$extras_array = array();
// Check if there is extras
if (count($bits) > 2) {
for ($i = 2; $i < count($bits); $i++) {
$extras_array[] = $bits[$i];
}
}
$this->extras = $extras_array;
} else {
throw new BiscuitException('Invalid amount of arguments given for Attribute: ' . $input);
}
}
public function getKey()
{
return $this->key;
}
public function getValue()
{
return $this->value;
}
// Return the attribute extras (true) will return the extras as literals
public function getExtras($literal = false)
{
if (!$literal) {
return $this->extras;
} else {
$literals = array();
for ($i = 0; $i < count($this->extras); $i++) {
$literals[$i] = Attribute::extraAttributeLiteral($this->extras[$i]);
}
return $literals;
}
}
public function toString()
{
$str = "Attribute Key: " . $this->key;
$str .= " || Attribute Value: " . $this->value;
$extras_array = $this->extras;
foreach ($extras_array as $extra) {
$str .= " || Attribute Extra: " . $extra;
}
return $str;
}
public static function extraAttributeLiteral($extra_attribute)
{
switch (strtolower($extra_attribute)) {
case 'notnull':
return 'Not Null';
case 'autoinc':
return 'Auto Increment';
case 'unique':
return 'Unique';
default:
return 'Not Defined';
}
}
}
?>