|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the eluceo/iCal package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Markus Poerschke <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Eluceo\iCal; |
|
13
|
|
|
|
|
14
|
|
|
use Eluceo\iCal\Property\ArrayValue; |
|
15
|
|
|
use Eluceo\iCal\Property\StringValue; |
|
16
|
|
|
use Eluceo\iCal\Property\ValueInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The Property Class represents a property as defined in RFC 2445. |
|
20
|
|
|
* |
|
21
|
|
|
* The content of a line (unfolded) will be rendered in this class |
|
22
|
|
|
*/ |
|
23
|
|
|
class Property |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* The value of the Property. |
|
27
|
|
|
* |
|
28
|
|
|
* @var ValueInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $value; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The params of the Property. |
|
34
|
|
|
* |
|
35
|
|
|
* @var ParameterBag |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $parameterBag; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $name; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param $name |
|
46
|
|
|
* @param $value |
|
47
|
|
|
* @param array $params |
|
48
|
|
|
*/ |
|
49
|
9 |
|
public function __construct($name, $value, $params = []) |
|
50
|
|
|
{ |
|
51
|
9 |
|
$this->name = $name; |
|
52
|
9 |
|
$this->setValue($value); |
|
53
|
9 |
|
$this->parameterBag = new ParameterBag($params); |
|
54
|
9 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Renders an unfolded line. |
|
58
|
|
|
* |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
8 |
|
public function toLine() |
|
62
|
|
|
{ |
|
63
|
|
|
// Property-name |
|
64
|
8 |
|
$line = $this->getName(); |
|
65
|
|
|
|
|
66
|
|
|
// Adding params |
|
67
|
8 |
|
if ($this->parameterBag->hasParams()) { |
|
68
|
3 |
|
$line .= ';' . $this->parameterBag->toString(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// Property value |
|
72
|
8 |
|
$line .= ':' . $this->value->getEscapedValue(); |
|
73
|
|
|
|
|
74
|
8 |
|
return $line; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Get all unfolded lines. |
|
79
|
|
|
* |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
4 |
|
public function toLines() |
|
83
|
|
|
{ |
|
84
|
4 |
|
return [$this->toLine()]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param $value |
|
89
|
|
|
* |
|
90
|
|
|
* @return $this |
|
91
|
|
|
* |
|
92
|
|
|
* @throws \InvalidArgumentException |
|
93
|
|
|
*/ |
|
94
|
9 |
|
protected function setValue($value) |
|
95
|
|
|
{ |
|
96
|
9 |
|
if (is_scalar($value)) { |
|
97
|
9 |
|
$this->value = new StringValue($value); |
|
98
|
2 |
|
} elseif (is_array($value)) { |
|
99
|
|
|
$this->value = new ArrayValue($value); |
|
100
|
|
|
} else { |
|
101
|
2 |
|
if (!$value instanceof ValueInterface) { |
|
102
|
|
|
throw new \InvalidArgumentException('The value must implement the ValueInterface.'); |
|
103
|
|
|
} |
|
104
|
2 |
|
$this->value = $value; |
|
105
|
|
|
} |
|
106
|
9 |
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
9 |
|
public function getName() |
|
112
|
|
|
{ |
|
113
|
9 |
|
return $this->name; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|