1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Joas Schilling <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace OCA\Activity\Parameter; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
use OCA\Activity\Formatter\BaseFormatter; |
26
|
|
|
use OCA\Activity\Formatter\GroupFormatter; |
27
|
|
|
use OCA\Activity\Formatter\IFormatter; |
28
|
|
|
use OCA\Activity\Formatter\CloudIDFormatter; |
29
|
|
|
use OCA\Activity\Formatter\FileFormatter; |
30
|
|
|
use OCA\Activity\Formatter\UserFormatter; |
31
|
|
|
use OCA\Activity\ViewInfoCache; |
32
|
|
|
use OCP\Activity\IEvent; |
33
|
|
|
use OCP\Activity\IManager; |
34
|
|
|
use OCP\Contacts\IManager as IContactsManager; |
35
|
|
|
use OCP\IConfig; |
36
|
|
|
use OCP\IGroupManager; |
37
|
|
|
use OCP\IL10N; |
38
|
|
|
use OCP\IURLGenerator; |
39
|
|
|
use OCP\IUserManager; |
40
|
|
|
|
41
|
|
|
class Factory { |
42
|
|
|
/** @var IManager */ |
43
|
|
|
protected $activityManager; |
44
|
|
|
|
45
|
|
|
/** @var IUserManager */ |
46
|
|
|
protected $userManager; |
47
|
|
|
|
48
|
|
|
/** @var IContactsManager */ |
49
|
|
|
protected $contactsManager; |
50
|
|
|
|
51
|
|
|
/** @var IL10N */ |
52
|
|
|
protected $l; |
53
|
|
|
|
54
|
|
|
/** @var IGroupManager */ |
55
|
|
|
protected $groupManager; |
56
|
|
|
|
57
|
|
|
/** @var ViewInfoCache */ |
58
|
|
|
protected $infoCache; |
59
|
|
|
|
60
|
|
|
/** @var string */ |
61
|
|
|
protected $user; |
62
|
|
|
|
63
|
|
|
/** @var IURLGenerator */ |
64
|
|
|
protected $urlGenerator; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param IManager $activityManager |
68
|
|
|
* @param IUserManager $userManager |
69
|
|
|
* @param IURLGenerator $urlGenerator |
70
|
|
|
* @param IContactsManager $contactsManager |
71
|
|
|
* @param ViewInfoCache $infoCache, |
|
|
|
|
72
|
|
|
* @param IL10N $l |
73
|
|
|
* @param string $user |
74
|
|
|
*/ |
75
|
21 |
View Code Duplication |
public function __construct(IManager $activityManager, |
|
|
|
|
76
|
|
|
IUserManager $userManager, |
77
|
|
|
IURLGenerator $urlGenerator, |
78
|
|
|
IContactsManager $contactsManager, |
79
|
|
|
ViewInfoCache $infoCache, |
80
|
|
|
IL10N $l, |
81
|
|
|
IGroupManager $groupManager, |
82
|
|
|
$user) { |
83
|
21 |
|
$this->activityManager = $activityManager; |
84
|
21 |
|
$this->userManager = $userManager; |
85
|
21 |
|
$this->urlGenerator = $urlGenerator; |
86
|
21 |
|
$this->contactsManager = $contactsManager; |
87
|
21 |
|
$this->infoCache = $infoCache; |
88
|
21 |
|
$this->l = $l; |
89
|
21 |
|
$this->groupManager = $groupManager; |
90
|
21 |
|
$this->user = $user; |
91
|
21 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $user |
95
|
|
|
*/ |
96
|
7 |
|
public function setUser($user) { |
97
|
7 |
|
$this->user = (string) $user; |
98
|
7 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param IL10N $l |
102
|
|
|
*/ |
103
|
1 |
|
public function setL10n(IL10N $l) { |
104
|
1 |
|
$this->l = $l; |
105
|
1 |
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string $parameter |
109
|
|
|
* @param IEvent $event |
110
|
|
|
* @param string $formatter |
111
|
|
|
* @return IParameter |
112
|
|
|
*/ |
113
|
6 |
|
public function get($parameter, IEvent $event, $formatter) { |
114
|
6 |
|
return new Parameter( |
115
|
6 |
|
$parameter, |
116
|
6 |
|
$event, |
117
|
6 |
|
$this->getFormatter($formatter), |
118
|
|
|
$formatter |
119
|
6 |
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return Collection |
124
|
|
|
*/ |
125
|
1 |
|
public function createCollection() { |
126
|
1 |
|
return new Collection($this->l, sha1(microtime() . mt_rand())); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $formatter |
131
|
|
|
* @return IFormatter |
132
|
|
|
*/ |
133
|
9 |
|
protected function getFormatter($formatter) { |
134
|
9 |
|
if ($formatter === 'file') { |
135
|
5 |
|
return new FileFormatter($this->infoCache, $this->urlGenerator, $this->l, $this->user); |
136
|
7 |
|
} else if ($formatter === 'username') { |
137
|
4 |
|
return new UserFormatter($this->userManager, $this->l); |
138
|
3 |
|
} else if ($formatter === 'federated_cloud_id') { |
139
|
1 |
|
return new CloudIDFormatter($this->contactsManager); |
140
|
2 |
|
} else if ($formatter === 'group') { |
141
|
1 |
|
return new GroupFormatter($this->groupManager); |
142
|
|
|
} else { |
143
|
1 |
|
return new BaseFormatter(); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.