1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
4
|
|
|
* |
5
|
|
|
* @author Joas Schilling <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license AGPL-3.0 |
8
|
|
|
* |
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
11
|
|
|
* as published by the Free Software Foundation. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\Activity\Parameter; |
24
|
|
|
|
25
|
|
|
use OCA\Activity\Formatter\IFormatter; |
26
|
|
|
use OCP\Activity\IEvent; |
27
|
|
|
|
28
|
|
|
class Parameter implements IParameter { |
29
|
|
|
/** @var IFormatter */ |
30
|
|
|
protected $formatter; |
31
|
|
|
|
32
|
|
|
/** @var mixed */ |
33
|
|
|
protected $parameter; |
34
|
|
|
|
35
|
|
|
/** @var IEvent */ |
36
|
|
|
protected $event; |
37
|
|
|
|
38
|
|
|
/** @var string */ |
39
|
|
|
protected $type; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param mixed $parameter |
43
|
|
|
* @param IEvent $event |
44
|
|
|
* @param IFormatter $formatter |
45
|
|
|
* @param string $type |
46
|
|
|
*/ |
47
|
14 |
|
public function __construct($parameter, |
48
|
|
|
IEvent $event, |
49
|
|
|
IFormatter $formatter, |
50
|
|
|
$type) { |
51
|
14 |
|
$this->parameter = $parameter; |
52
|
14 |
|
$this->event = $event; |
53
|
14 |
|
$this->formatter = $formatter; |
54
|
14 |
|
$this->type = $type; |
55
|
14 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return mixed |
59
|
|
|
*/ |
60
|
6 |
|
public function getParameter() { |
61
|
6 |
|
if ($this->event->getObjectType() && $this->event->getObjectId()) { |
62
|
2 |
|
return $this->event->getObjectType() . '#' . $this->event->getObjectId(); |
63
|
|
|
} |
64
|
|
|
|
65
|
4 |
|
return $this->parameter; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array With two entries: value and type |
70
|
|
|
*/ |
71
|
2 |
|
public function getParameterInfo() { |
72
|
|
|
return [ |
73
|
2 |
|
'value' => $this->parameter, |
74
|
2 |
|
'type' => $this->type, |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string The formatted parameter |
80
|
|
|
*/ |
81
|
6 |
|
public function format() { |
82
|
6 |
|
return $this->formatter->format($this->event, $this->parameter); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|