@@ -25,14 +25,12 @@ |
||
25 | 25 | |
26 | 26 | namespace OC\Contacts\ContactsMenu; |
27 | 27 | |
28 | -use OC\Share\Share; |
|
29 | 28 | use OCP\Contacts\ContactsMenu\IEntry; |
30 | 29 | use OCP\Contacts\IManager; |
31 | 30 | use OCP\IConfig; |
32 | 31 | use OCP\IGroupManager; |
33 | 32 | use OCP\IUser; |
34 | 33 | use OCP\IUserManager; |
35 | -use OCP\IUserSession; |
|
36 | 34 | use OCP\Contacts\ContactsMenu\IContactsStore; |
37 | 35 | |
38 | 36 | class ContactsStore implements IContactsStore { |
@@ -37,220 +37,220 @@ |
||
37 | 37 | |
38 | 38 | class ContactsStore implements IContactsStore { |
39 | 39 | |
40 | - /** @var IManager */ |
|
41 | - private $contactsManager; |
|
42 | - |
|
43 | - /** @var IConfig */ |
|
44 | - private $config; |
|
45 | - |
|
46 | - /** @var IUserManager */ |
|
47 | - private $userManager; |
|
48 | - |
|
49 | - /** @var IGroupManager */ |
|
50 | - private $groupManager; |
|
51 | - |
|
52 | - /** |
|
53 | - * @param IManager $contactsManager |
|
54 | - * @param IConfig $config |
|
55 | - * @param IUserManager $userManager |
|
56 | - * @param IGroupManager $groupManager |
|
57 | - */ |
|
58 | - public function __construct(IManager $contactsManager, |
|
59 | - IConfig $config, |
|
60 | - IUserManager $userManager, |
|
61 | - IGroupManager $groupManager) { |
|
62 | - $this->contactsManager = $contactsManager; |
|
63 | - $this->config = $config; |
|
64 | - $this->userManager = $userManager; |
|
65 | - $this->groupManager = $groupManager; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param IUser $user |
|
70 | - * @param string|null $filter |
|
71 | - * @return IEntry[] |
|
72 | - */ |
|
73 | - public function getContacts(IUser $user, $filter) { |
|
74 | - $allContacts = $this->contactsManager->search($filter ?: '', [ |
|
75 | - 'FN', |
|
76 | - 'EMAIL' |
|
77 | - ]); |
|
78 | - |
|
79 | - $entries = array_map(function(array $contact) { |
|
80 | - return $this->contactArrayToEntry($contact); |
|
81 | - }, $allContacts); |
|
82 | - return $this->filterContacts( |
|
83 | - $user, |
|
84 | - $entries, |
|
85 | - $filter |
|
86 | - ); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Filters the contacts. Applies 3 filters: |
|
91 | - * 1. filter the current user |
|
92 | - * 2. if the `shareapi_allow_share_dialog_user_enumeration` config option is |
|
93 | - * enabled it will filter all local users |
|
94 | - * 3. if the `shareapi_exclude_groups` config option is enabled and the |
|
95 | - * current user is in an excluded group it will filter all local users. |
|
96 | - * 4. if the `shareapi_only_share_with_group_members` config option is |
|
97 | - * enabled it will filter all users which doens't have a common group |
|
98 | - * with the current user. |
|
99 | - * |
|
100 | - * @param IUser $self |
|
101 | - * @param Entry[] $entries |
|
102 | - * @param string $filter |
|
103 | - * @return Entry[] the filtered contacts |
|
104 | - */ |
|
105 | - private function filterContacts(IUser $self, |
|
106 | - array $entries, |
|
107 | - $filter) { |
|
108 | - $disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes'; |
|
109 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes'; |
|
110 | - |
|
111 | - // whether to filter out local users |
|
112 | - $skipLocal = false; |
|
113 | - // whether to filter out all users which doesn't have the same group as the current user |
|
114 | - $ownGroupsOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
115 | - |
|
116 | - $selfGroups = $this->groupManager->getUserGroupIds($self); |
|
117 | - |
|
118 | - if ($excludedGroups) { |
|
119 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
120 | - $decodedExcludeGroups = json_decode($excludedGroups, true); |
|
121 | - $excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups : []; |
|
122 | - |
|
123 | - if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) { |
|
124 | - // a group of the current user is excluded -> filter all local users |
|
125 | - $skipLocal = true; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - $selfUID = $self->getUID(); |
|
130 | - |
|
131 | - return array_values(array_filter($entries, function(IEntry $entry) use ($self, $skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $filter) { |
|
132 | - if ($skipLocal && $entry->getProperty('isLocalSystemBook') === true) { |
|
133 | - return false; |
|
134 | - } |
|
135 | - |
|
136 | - // Prevent enumerating local users |
|
137 | - if($disallowEnumeration && $entry->getProperty('isLocalSystemBook')) { |
|
138 | - $filterUser = true; |
|
139 | - |
|
140 | - $mailAddresses = $entry->getEMailAddresses(); |
|
141 | - foreach($mailAddresses as $mailAddress) { |
|
142 | - if($mailAddress === $filter) { |
|
143 | - $filterUser = false; |
|
144 | - break; |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - if($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) { |
|
149 | - $filterUser = false; |
|
150 | - } |
|
151 | - |
|
152 | - if($filterUser) { |
|
153 | - return false; |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - if ($ownGroupsOnly && $entry->getProperty('isLocalSystemBook') === true) { |
|
158 | - $contactGroups = $this->groupManager->getUserGroupIds($this->userManager->get($entry->getProperty('UID'))); |
|
159 | - if (count(array_intersect($contactGroups, $selfGroups)) === 0) { |
|
160 | - // no groups in common, so shouldn't see the contact |
|
161 | - return false; |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - return $entry->getProperty('UID') !== $selfUID; |
|
166 | - })); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @param IUser $user |
|
171 | - * @param integer $shareType |
|
172 | - * @param string $shareWith |
|
173 | - * @return IEntry|null |
|
174 | - */ |
|
175 | - public function findOne(IUser $user, $shareType, $shareWith) { |
|
176 | - switch($shareType) { |
|
177 | - case 0: |
|
178 | - case 6: |
|
179 | - $filter = ['UID']; |
|
180 | - break; |
|
181 | - case 4: |
|
182 | - $filter = ['EMAIL']; |
|
183 | - break; |
|
184 | - default: |
|
185 | - return null; |
|
186 | - } |
|
187 | - |
|
188 | - $userId = $user->getUID(); |
|
189 | - $allContacts = $this->contactsManager->search($shareWith, $filter); |
|
190 | - $contacts = array_filter($allContacts, function($contact) use ($userId) { |
|
191 | - return $contact['UID'] !== $userId; |
|
192 | - }); |
|
193 | - $match = null; |
|
194 | - |
|
195 | - foreach ($contacts as $contact) { |
|
196 | - if ($shareType === 4 && isset($contact['EMAIL'])) { |
|
197 | - if (in_array($shareWith, $contact['EMAIL'])) { |
|
198 | - $match = $contact; |
|
199 | - break; |
|
200 | - } |
|
201 | - } |
|
202 | - if ($shareType === 0 || $shareType === 6) { |
|
203 | - if ($contact['UID'] === $shareWith && $contact['isLocalSystemBook'] === true) { |
|
204 | - $match = $contact; |
|
205 | - break; |
|
206 | - } |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - if ($match) { |
|
211 | - $match = $this->filterContacts($user, [$this->contactArrayToEntry($match)], $shareWith); |
|
212 | - if (count($match) === 1) { |
|
213 | - $match = $match[0]; |
|
214 | - } else { |
|
215 | - $match = null; |
|
216 | - } |
|
217 | - |
|
218 | - } |
|
219 | - |
|
220 | - return $match; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @param array $contact |
|
225 | - * @return Entry |
|
226 | - */ |
|
227 | - private function contactArrayToEntry(array $contact) { |
|
228 | - $entry = new Entry(); |
|
229 | - |
|
230 | - if (isset($contact['id'])) { |
|
231 | - $entry->setId($contact['id']); |
|
232 | - } |
|
233 | - |
|
234 | - if (isset($contact['FN'])) { |
|
235 | - $entry->setFullName($contact['FN']); |
|
236 | - } |
|
237 | - |
|
238 | - $avatarPrefix = "VALUE=uri:"; |
|
239 | - if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) { |
|
240 | - $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix))); |
|
241 | - } |
|
242 | - |
|
243 | - if (isset($contact['EMAIL'])) { |
|
244 | - foreach ($contact['EMAIL'] as $email) { |
|
245 | - $entry->addEMailAddress($email); |
|
246 | - } |
|
247 | - } |
|
248 | - |
|
249 | - // Attach all other properties to the entry too because some |
|
250 | - // providers might make use of it. |
|
251 | - $entry->setProperties($contact); |
|
252 | - |
|
253 | - return $entry; |
|
254 | - } |
|
40 | + /** @var IManager */ |
|
41 | + private $contactsManager; |
|
42 | + |
|
43 | + /** @var IConfig */ |
|
44 | + private $config; |
|
45 | + |
|
46 | + /** @var IUserManager */ |
|
47 | + private $userManager; |
|
48 | + |
|
49 | + /** @var IGroupManager */ |
|
50 | + private $groupManager; |
|
51 | + |
|
52 | + /** |
|
53 | + * @param IManager $contactsManager |
|
54 | + * @param IConfig $config |
|
55 | + * @param IUserManager $userManager |
|
56 | + * @param IGroupManager $groupManager |
|
57 | + */ |
|
58 | + public function __construct(IManager $contactsManager, |
|
59 | + IConfig $config, |
|
60 | + IUserManager $userManager, |
|
61 | + IGroupManager $groupManager) { |
|
62 | + $this->contactsManager = $contactsManager; |
|
63 | + $this->config = $config; |
|
64 | + $this->userManager = $userManager; |
|
65 | + $this->groupManager = $groupManager; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param IUser $user |
|
70 | + * @param string|null $filter |
|
71 | + * @return IEntry[] |
|
72 | + */ |
|
73 | + public function getContacts(IUser $user, $filter) { |
|
74 | + $allContacts = $this->contactsManager->search($filter ?: '', [ |
|
75 | + 'FN', |
|
76 | + 'EMAIL' |
|
77 | + ]); |
|
78 | + |
|
79 | + $entries = array_map(function(array $contact) { |
|
80 | + return $this->contactArrayToEntry($contact); |
|
81 | + }, $allContacts); |
|
82 | + return $this->filterContacts( |
|
83 | + $user, |
|
84 | + $entries, |
|
85 | + $filter |
|
86 | + ); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Filters the contacts. Applies 3 filters: |
|
91 | + * 1. filter the current user |
|
92 | + * 2. if the `shareapi_allow_share_dialog_user_enumeration` config option is |
|
93 | + * enabled it will filter all local users |
|
94 | + * 3. if the `shareapi_exclude_groups` config option is enabled and the |
|
95 | + * current user is in an excluded group it will filter all local users. |
|
96 | + * 4. if the `shareapi_only_share_with_group_members` config option is |
|
97 | + * enabled it will filter all users which doens't have a common group |
|
98 | + * with the current user. |
|
99 | + * |
|
100 | + * @param IUser $self |
|
101 | + * @param Entry[] $entries |
|
102 | + * @param string $filter |
|
103 | + * @return Entry[] the filtered contacts |
|
104 | + */ |
|
105 | + private function filterContacts(IUser $self, |
|
106 | + array $entries, |
|
107 | + $filter) { |
|
108 | + $disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes'; |
|
109 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes'; |
|
110 | + |
|
111 | + // whether to filter out local users |
|
112 | + $skipLocal = false; |
|
113 | + // whether to filter out all users which doesn't have the same group as the current user |
|
114 | + $ownGroupsOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
115 | + |
|
116 | + $selfGroups = $this->groupManager->getUserGroupIds($self); |
|
117 | + |
|
118 | + if ($excludedGroups) { |
|
119 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
120 | + $decodedExcludeGroups = json_decode($excludedGroups, true); |
|
121 | + $excludeGroupsList = ($decodedExcludeGroups !== null) ? $decodedExcludeGroups : []; |
|
122 | + |
|
123 | + if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) { |
|
124 | + // a group of the current user is excluded -> filter all local users |
|
125 | + $skipLocal = true; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + $selfUID = $self->getUID(); |
|
130 | + |
|
131 | + return array_values(array_filter($entries, function(IEntry $entry) use ($self, $skipLocal, $ownGroupsOnly, $selfGroups, $selfUID, $disallowEnumeration, $filter) { |
|
132 | + if ($skipLocal && $entry->getProperty('isLocalSystemBook') === true) { |
|
133 | + return false; |
|
134 | + } |
|
135 | + |
|
136 | + // Prevent enumerating local users |
|
137 | + if($disallowEnumeration && $entry->getProperty('isLocalSystemBook')) { |
|
138 | + $filterUser = true; |
|
139 | + |
|
140 | + $mailAddresses = $entry->getEMailAddresses(); |
|
141 | + foreach($mailAddresses as $mailAddress) { |
|
142 | + if($mailAddress === $filter) { |
|
143 | + $filterUser = false; |
|
144 | + break; |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + if($entry->getProperty('UID') && $entry->getProperty('UID') === $filter) { |
|
149 | + $filterUser = false; |
|
150 | + } |
|
151 | + |
|
152 | + if($filterUser) { |
|
153 | + return false; |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + if ($ownGroupsOnly && $entry->getProperty('isLocalSystemBook') === true) { |
|
158 | + $contactGroups = $this->groupManager->getUserGroupIds($this->userManager->get($entry->getProperty('UID'))); |
|
159 | + if (count(array_intersect($contactGroups, $selfGroups)) === 0) { |
|
160 | + // no groups in common, so shouldn't see the contact |
|
161 | + return false; |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + return $entry->getProperty('UID') !== $selfUID; |
|
166 | + })); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @param IUser $user |
|
171 | + * @param integer $shareType |
|
172 | + * @param string $shareWith |
|
173 | + * @return IEntry|null |
|
174 | + */ |
|
175 | + public function findOne(IUser $user, $shareType, $shareWith) { |
|
176 | + switch($shareType) { |
|
177 | + case 0: |
|
178 | + case 6: |
|
179 | + $filter = ['UID']; |
|
180 | + break; |
|
181 | + case 4: |
|
182 | + $filter = ['EMAIL']; |
|
183 | + break; |
|
184 | + default: |
|
185 | + return null; |
|
186 | + } |
|
187 | + |
|
188 | + $userId = $user->getUID(); |
|
189 | + $allContacts = $this->contactsManager->search($shareWith, $filter); |
|
190 | + $contacts = array_filter($allContacts, function($contact) use ($userId) { |
|
191 | + return $contact['UID'] !== $userId; |
|
192 | + }); |
|
193 | + $match = null; |
|
194 | + |
|
195 | + foreach ($contacts as $contact) { |
|
196 | + if ($shareType === 4 && isset($contact['EMAIL'])) { |
|
197 | + if (in_array($shareWith, $contact['EMAIL'])) { |
|
198 | + $match = $contact; |
|
199 | + break; |
|
200 | + } |
|
201 | + } |
|
202 | + if ($shareType === 0 || $shareType === 6) { |
|
203 | + if ($contact['UID'] === $shareWith && $contact['isLocalSystemBook'] === true) { |
|
204 | + $match = $contact; |
|
205 | + break; |
|
206 | + } |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + if ($match) { |
|
211 | + $match = $this->filterContacts($user, [$this->contactArrayToEntry($match)], $shareWith); |
|
212 | + if (count($match) === 1) { |
|
213 | + $match = $match[0]; |
|
214 | + } else { |
|
215 | + $match = null; |
|
216 | + } |
|
217 | + |
|
218 | + } |
|
219 | + |
|
220 | + return $match; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @param array $contact |
|
225 | + * @return Entry |
|
226 | + */ |
|
227 | + private function contactArrayToEntry(array $contact) { |
|
228 | + $entry = new Entry(); |
|
229 | + |
|
230 | + if (isset($contact['id'])) { |
|
231 | + $entry->setId($contact['id']); |
|
232 | + } |
|
233 | + |
|
234 | + if (isset($contact['FN'])) { |
|
235 | + $entry->setFullName($contact['FN']); |
|
236 | + } |
|
237 | + |
|
238 | + $avatarPrefix = "VALUE=uri:"; |
|
239 | + if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) { |
|
240 | + $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix))); |
|
241 | + } |
|
242 | + |
|
243 | + if (isset($contact['EMAIL'])) { |
|
244 | + foreach ($contact['EMAIL'] as $email) { |
|
245 | + $entry->addEMailAddress($email); |
|
246 | + } |
|
247 | + } |
|
248 | + |
|
249 | + // Attach all other properties to the entry too because some |
|
250 | + // providers might make use of it. |
|
251 | + $entry->setProperties($contact); |
|
252 | + |
|
253 | + return $entry; |
|
254 | + } |
|
255 | 255 | |
256 | 256 | } |
@@ -128,1702 +128,1702 @@ |
||
128 | 128 | * TODO: hookup all manager classes |
129 | 129 | */ |
130 | 130 | class Server extends ServerContainer implements IServerContainer { |
131 | - /** @var string */ |
|
132 | - private $webRoot; |
|
133 | - |
|
134 | - /** |
|
135 | - * @param string $webRoot |
|
136 | - * @param \OC\Config $config |
|
137 | - */ |
|
138 | - public function __construct($webRoot, \OC\Config $config) { |
|
139 | - parent::__construct(); |
|
140 | - $this->webRoot = $webRoot; |
|
141 | - |
|
142 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
143 | - return $c; |
|
144 | - }); |
|
145 | - |
|
146 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
147 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
148 | - |
|
149 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
150 | - |
|
151 | - |
|
152 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
153 | - return new PreviewManager( |
|
154 | - $c->getConfig(), |
|
155 | - $c->getRootFolder(), |
|
156 | - $c->getAppDataDir('preview'), |
|
157 | - $c->getEventDispatcher(), |
|
158 | - $c->getSession()->get('user_id') |
|
159 | - ); |
|
160 | - }); |
|
161 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
162 | - |
|
163 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
164 | - return new \OC\Preview\Watcher( |
|
165 | - $c->getAppDataDir('preview') |
|
166 | - ); |
|
167 | - }); |
|
168 | - |
|
169 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
170 | - $view = new View(); |
|
171 | - $util = new Encryption\Util( |
|
172 | - $view, |
|
173 | - $c->getUserManager(), |
|
174 | - $c->getGroupManager(), |
|
175 | - $c->getConfig() |
|
176 | - ); |
|
177 | - return new Encryption\Manager( |
|
178 | - $c->getConfig(), |
|
179 | - $c->getLogger(), |
|
180 | - $c->getL10N('core'), |
|
181 | - new View(), |
|
182 | - $util, |
|
183 | - new ArrayCache() |
|
184 | - ); |
|
185 | - }); |
|
186 | - |
|
187 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
188 | - $util = new Encryption\Util( |
|
189 | - new View(), |
|
190 | - $c->getUserManager(), |
|
191 | - $c->getGroupManager(), |
|
192 | - $c->getConfig() |
|
193 | - ); |
|
194 | - return new Encryption\File( |
|
195 | - $util, |
|
196 | - $c->getRootFolder(), |
|
197 | - $c->getShareManager() |
|
198 | - ); |
|
199 | - }); |
|
200 | - |
|
201 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
202 | - $view = new View(); |
|
203 | - $util = new Encryption\Util( |
|
204 | - $view, |
|
205 | - $c->getUserManager(), |
|
206 | - $c->getGroupManager(), |
|
207 | - $c->getConfig() |
|
208 | - ); |
|
209 | - |
|
210 | - return new Encryption\Keys\Storage($view, $util); |
|
211 | - }); |
|
212 | - $this->registerService('TagMapper', function (Server $c) { |
|
213 | - return new TagMapper($c->getDatabaseConnection()); |
|
214 | - }); |
|
215 | - |
|
216 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
217 | - $tagMapper = $c->query('TagMapper'); |
|
218 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
219 | - }); |
|
220 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
221 | - |
|
222 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
223 | - $config = $c->getConfig(); |
|
224 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
225 | - /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
226 | - $factory = new $factoryClass($this); |
|
227 | - return $factory; |
|
228 | - }); |
|
229 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
230 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
231 | - }); |
|
232 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
233 | - |
|
234 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
235 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
236 | - }); |
|
237 | - $this->registerService('RootFolder', function (Server $c) { |
|
238 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
239 | - $view = new View(); |
|
240 | - $root = new Root( |
|
241 | - $manager, |
|
242 | - $view, |
|
243 | - null, |
|
244 | - $c->getUserMountCache(), |
|
245 | - $this->getLogger(), |
|
246 | - $this->getUserManager() |
|
247 | - ); |
|
248 | - $connector = new HookConnector($root, $view); |
|
249 | - $connector->viewToNode(); |
|
250 | - |
|
251 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
252 | - $previewConnector->connectWatcher(); |
|
253 | - |
|
254 | - return $root; |
|
255 | - }); |
|
256 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
257 | - |
|
258 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
259 | - return new LazyRoot(function () use ($c) { |
|
260 | - return $c->query('RootFolder'); |
|
261 | - }); |
|
262 | - }); |
|
263 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
264 | - |
|
265 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
266 | - $config = $c->getConfig(); |
|
267 | - return new \OC\User\Manager($config); |
|
268 | - }); |
|
269 | - $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
270 | - |
|
271 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
272 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
273 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
274 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
275 | - }); |
|
276 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
277 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
278 | - }); |
|
279 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
280 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
281 | - }); |
|
282 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
283 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
284 | - }); |
|
285 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
286 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
287 | - }); |
|
288 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
289 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
290 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
291 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
292 | - }); |
|
293 | - return $groupManager; |
|
294 | - }); |
|
295 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
296 | - |
|
297 | - $this->registerService(Store::class, function (Server $c) { |
|
298 | - $session = $c->getSession(); |
|
299 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
300 | - $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
301 | - } else { |
|
302 | - $tokenProvider = null; |
|
303 | - } |
|
304 | - $logger = $c->getLogger(); |
|
305 | - return new Store($session, $logger, $tokenProvider); |
|
306 | - }); |
|
307 | - $this->registerAlias(IStore::class, Store::class); |
|
308 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
309 | - $dbConnection = $c->getDatabaseConnection(); |
|
310 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
311 | - }); |
|
312 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
313 | - $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
314 | - $crypto = $c->getCrypto(); |
|
315 | - $config = $c->getConfig(); |
|
316 | - $logger = $c->getLogger(); |
|
317 | - $timeFactory = new TimeFactory(); |
|
318 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
319 | - }); |
|
320 | - $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
321 | - |
|
322 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
323 | - $manager = $c->getUserManager(); |
|
324 | - $session = new \OC\Session\Memory(''); |
|
325 | - $timeFactory = new TimeFactory(); |
|
326 | - // Token providers might require a working database. This code |
|
327 | - // might however be called when ownCloud is not yet setup. |
|
328 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
329 | - $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
330 | - } else { |
|
331 | - $defaultTokenProvider = null; |
|
332 | - } |
|
333 | - |
|
334 | - $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
335 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
336 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
337 | - }); |
|
338 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
339 | - /** @var $user \OC\User\User */ |
|
340 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
341 | - }); |
|
342 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
343 | - /** @var $user \OC\User\User */ |
|
344 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
345 | - }); |
|
346 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
347 | - /** @var $user \OC\User\User */ |
|
348 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
349 | - }); |
|
350 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
351 | - /** @var $user \OC\User\User */ |
|
352 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
353 | - }); |
|
354 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
355 | - /** @var $user \OC\User\User */ |
|
356 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
357 | - }); |
|
358 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
359 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
360 | - }); |
|
361 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
362 | - /** @var $user \OC\User\User */ |
|
363 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
364 | - }); |
|
365 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
366 | - /** @var $user \OC\User\User */ |
|
367 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
368 | - }); |
|
369 | - $userSession->listen('\OC\User', 'logout', function () { |
|
370 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
371 | - }); |
|
372 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
373 | - /** @var $user \OC\User\User */ |
|
374 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
375 | - }); |
|
376 | - return $userSession; |
|
377 | - }); |
|
378 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
379 | - |
|
380 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
381 | - return new \OC\Authentication\TwoFactorAuth\Manager( |
|
382 | - $c->getAppManager(), |
|
383 | - $c->getSession(), |
|
384 | - $c->getConfig(), |
|
385 | - $c->getActivityManager(), |
|
386 | - $c->getLogger(), |
|
387 | - $c->query(\OC\Authentication\Token\IProvider::class), |
|
388 | - $c->query(ITimeFactory::class) |
|
389 | - ); |
|
390 | - }); |
|
391 | - |
|
392 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
393 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
394 | - |
|
395 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
396 | - return new \OC\AllConfig( |
|
397 | - $c->getSystemConfig() |
|
398 | - ); |
|
399 | - }); |
|
400 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
401 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
402 | - |
|
403 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
404 | - return new \OC\SystemConfig($config); |
|
405 | - }); |
|
406 | - |
|
407 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
408 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
409 | - }); |
|
410 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
411 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
412 | - |
|
413 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
414 | - return new \OC\L10N\Factory( |
|
415 | - $c->getConfig(), |
|
416 | - $c->getRequest(), |
|
417 | - $c->getUserSession(), |
|
418 | - \OC::$SERVERROOT |
|
419 | - ); |
|
420 | - }); |
|
421 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
422 | - |
|
423 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
424 | - $config = $c->getConfig(); |
|
425 | - $cacheFactory = $c->getMemCacheFactory(); |
|
426 | - $request = $c->getRequest(); |
|
427 | - return new \OC\URLGenerator( |
|
428 | - $config, |
|
429 | - $cacheFactory, |
|
430 | - $request |
|
431 | - ); |
|
432 | - }); |
|
433 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
434 | - |
|
435 | - $this->registerService('AppHelper', function ($c) { |
|
436 | - return new \OC\AppHelper(); |
|
437 | - }); |
|
438 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
439 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
440 | - |
|
441 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
442 | - return new Cache\File(); |
|
443 | - }); |
|
444 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
445 | - |
|
446 | - $this->registerService(Factory::class, function (Server $c) { |
|
447 | - |
|
448 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
449 | - '\\OC\\Memcache\\ArrayCache', |
|
450 | - '\\OC\\Memcache\\ArrayCache', |
|
451 | - '\\OC\\Memcache\\ArrayCache' |
|
452 | - ); |
|
453 | - $config = $c->getConfig(); |
|
454 | - $request = $c->getRequest(); |
|
455 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
456 | - |
|
457 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
458 | - $v = \OC_App::getAppVersions(); |
|
459 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
460 | - $version = implode(',', $v); |
|
461 | - $instanceId = \OC_Util::getInstanceId(); |
|
462 | - $path = \OC::$SERVERROOT; |
|
463 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
464 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
465 | - $config->getSystemValue('memcache.local', null), |
|
466 | - $config->getSystemValue('memcache.distributed', null), |
|
467 | - $config->getSystemValue('memcache.locking', null) |
|
468 | - ); |
|
469 | - } |
|
470 | - return $arrayCacheFactory; |
|
471 | - |
|
472 | - }); |
|
473 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
474 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
475 | - |
|
476 | - $this->registerService('RedisFactory', function (Server $c) { |
|
477 | - $systemConfig = $c->getSystemConfig(); |
|
478 | - return new RedisFactory($systemConfig); |
|
479 | - }); |
|
480 | - |
|
481 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
482 | - return new \OC\Activity\Manager( |
|
483 | - $c->getRequest(), |
|
484 | - $c->getUserSession(), |
|
485 | - $c->getConfig(), |
|
486 | - $c->query(IValidator::class) |
|
487 | - ); |
|
488 | - }); |
|
489 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
490 | - |
|
491 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
492 | - return new \OC\Activity\EventMerger( |
|
493 | - $c->getL10N('lib') |
|
494 | - ); |
|
495 | - }); |
|
496 | - $this->registerAlias(IValidator::class, Validator::class); |
|
497 | - |
|
498 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
499 | - return new AvatarManager( |
|
500 | - $c->getUserManager(), |
|
501 | - $c->getAppDataDir('avatar'), |
|
502 | - $c->getL10N('lib'), |
|
503 | - $c->getLogger(), |
|
504 | - $c->getConfig() |
|
505 | - ); |
|
506 | - }); |
|
507 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
508 | - |
|
509 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
510 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
511 | - $logger = Log::getLogClass($logType); |
|
512 | - call_user_func(array($logger, 'init')); |
|
513 | - |
|
514 | - return new Log($logger); |
|
515 | - }); |
|
516 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
517 | - |
|
518 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
519 | - $config = $c->getConfig(); |
|
520 | - return new \OC\BackgroundJob\JobList( |
|
521 | - $c->getDatabaseConnection(), |
|
522 | - $config, |
|
523 | - new TimeFactory() |
|
524 | - ); |
|
525 | - }); |
|
526 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
527 | - |
|
528 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
529 | - $cacheFactory = $c->getMemCacheFactory(); |
|
530 | - $logger = $c->getLogger(); |
|
531 | - if ($cacheFactory->isAvailable()) { |
|
532 | - $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
533 | - } else { |
|
534 | - $router = new \OC\Route\Router($logger); |
|
535 | - } |
|
536 | - return $router; |
|
537 | - }); |
|
538 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
539 | - |
|
540 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
541 | - return new Search(); |
|
542 | - }); |
|
543 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
544 | - |
|
545 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
546 | - return new \OC\Security\RateLimiting\Limiter( |
|
547 | - $this->getUserSession(), |
|
548 | - $this->getRequest(), |
|
549 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
550 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
551 | - ); |
|
552 | - }); |
|
553 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
554 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
555 | - $this->getMemCacheFactory(), |
|
556 | - new \OC\AppFramework\Utility\TimeFactory() |
|
557 | - ); |
|
558 | - }); |
|
559 | - |
|
560 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
561 | - return new SecureRandom(); |
|
562 | - }); |
|
563 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
564 | - |
|
565 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
566 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
567 | - }); |
|
568 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
569 | - |
|
570 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
571 | - return new Hasher($c->getConfig()); |
|
572 | - }); |
|
573 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
574 | - |
|
575 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
576 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
577 | - }); |
|
578 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
579 | - |
|
580 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
581 | - $systemConfig = $c->getSystemConfig(); |
|
582 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
583 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
584 | - if (!$factory->isValidType($type)) { |
|
585 | - throw new \OC\DatabaseException('Invalid database type'); |
|
586 | - } |
|
587 | - $connectionParams = $factory->createConnectionParams(); |
|
588 | - $connection = $factory->getConnection($type, $connectionParams); |
|
589 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
590 | - return $connection; |
|
591 | - }); |
|
592 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
593 | - |
|
594 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
595 | - $config = $c->getConfig(); |
|
596 | - return new HTTPHelper( |
|
597 | - $config, |
|
598 | - $c->getHTTPClientService() |
|
599 | - ); |
|
600 | - }); |
|
601 | - |
|
602 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
603 | - $user = \OC_User::getUser(); |
|
604 | - $uid = $user ? $user : null; |
|
605 | - return new ClientService( |
|
606 | - $c->getConfig(), |
|
607 | - new \OC\Security\CertificateManager( |
|
608 | - $uid, |
|
609 | - new View(), |
|
610 | - $c->getConfig(), |
|
611 | - $c->getLogger(), |
|
612 | - $c->getSecureRandom() |
|
613 | - ) |
|
614 | - ); |
|
615 | - }); |
|
616 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
617 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
618 | - $eventLogger = new EventLogger(); |
|
619 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
620 | - // In debug mode, module is being activated by default |
|
621 | - $eventLogger->activate(); |
|
622 | - } |
|
623 | - return $eventLogger; |
|
624 | - }); |
|
625 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
626 | - |
|
627 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
628 | - $queryLogger = new QueryLogger(); |
|
629 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
630 | - // In debug mode, module is being activated by default |
|
631 | - $queryLogger->activate(); |
|
632 | - } |
|
633 | - return $queryLogger; |
|
634 | - }); |
|
635 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
636 | - |
|
637 | - $this->registerService(TempManager::class, function (Server $c) { |
|
638 | - return new TempManager( |
|
639 | - $c->getLogger(), |
|
640 | - $c->getConfig() |
|
641 | - ); |
|
642 | - }); |
|
643 | - $this->registerAlias('TempManager', TempManager::class); |
|
644 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
645 | - |
|
646 | - $this->registerService(AppManager::class, function (Server $c) { |
|
647 | - return new \OC\App\AppManager( |
|
648 | - $c->getUserSession(), |
|
649 | - $c->getAppConfig(), |
|
650 | - $c->getGroupManager(), |
|
651 | - $c->getMemCacheFactory(), |
|
652 | - $c->getEventDispatcher() |
|
653 | - ); |
|
654 | - }); |
|
655 | - $this->registerAlias('AppManager', AppManager::class); |
|
656 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
657 | - |
|
658 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
659 | - return new DateTimeZone( |
|
660 | - $c->getConfig(), |
|
661 | - $c->getSession() |
|
662 | - ); |
|
663 | - }); |
|
664 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
665 | - |
|
666 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
667 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
668 | - |
|
669 | - return new DateTimeFormatter( |
|
670 | - $c->getDateTimeZone()->getTimeZone(), |
|
671 | - $c->getL10N('lib', $language) |
|
672 | - ); |
|
673 | - }); |
|
674 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
675 | - |
|
676 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
677 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
678 | - $listener = new UserMountCacheListener($mountCache); |
|
679 | - $listener->listen($c->getUserManager()); |
|
680 | - return $mountCache; |
|
681 | - }); |
|
682 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
683 | - |
|
684 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
685 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
686 | - $mountCache = $c->query('UserMountCache'); |
|
687 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
688 | - |
|
689 | - // builtin providers |
|
690 | - |
|
691 | - $config = $c->getConfig(); |
|
692 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
693 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
694 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
695 | - |
|
696 | - return $manager; |
|
697 | - }); |
|
698 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
699 | - |
|
700 | - $this->registerService('IniWrapper', function ($c) { |
|
701 | - return new IniGetWrapper(); |
|
702 | - }); |
|
703 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
704 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
705 | - if ($busClass) { |
|
706 | - list($app, $class) = explode('::', $busClass, 2); |
|
707 | - if ($c->getAppManager()->isInstalled($app)) { |
|
708 | - \OC_App::loadApp($app); |
|
709 | - return $c->query($class); |
|
710 | - } else { |
|
711 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
712 | - } |
|
713 | - } else { |
|
714 | - $jobList = $c->getJobList(); |
|
715 | - return new CronBus($jobList); |
|
716 | - } |
|
717 | - }); |
|
718 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
719 | - return new TrustedDomainHelper($this->getConfig()); |
|
720 | - }); |
|
721 | - $this->registerService('Throttler', function (Server $c) { |
|
722 | - return new Throttler( |
|
723 | - $c->getDatabaseConnection(), |
|
724 | - new TimeFactory(), |
|
725 | - $c->getLogger(), |
|
726 | - $c->getConfig() |
|
727 | - ); |
|
728 | - }); |
|
729 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
730 | - // IConfig and IAppManager requires a working database. This code |
|
731 | - // might however be called when ownCloud is not yet setup. |
|
732 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
733 | - $config = $c->getConfig(); |
|
734 | - $appManager = $c->getAppManager(); |
|
735 | - } else { |
|
736 | - $config = null; |
|
737 | - $appManager = null; |
|
738 | - } |
|
739 | - |
|
740 | - return new Checker( |
|
741 | - new EnvironmentHelper(), |
|
742 | - new FileAccessHelper(), |
|
743 | - new AppLocator(), |
|
744 | - $config, |
|
745 | - $c->getMemCacheFactory(), |
|
746 | - $appManager, |
|
747 | - $c->getTempManager() |
|
748 | - ); |
|
749 | - }); |
|
750 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
751 | - if (isset($this['urlParams'])) { |
|
752 | - $urlParams = $this['urlParams']; |
|
753 | - } else { |
|
754 | - $urlParams = []; |
|
755 | - } |
|
756 | - |
|
757 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
758 | - && in_array('fakeinput', stream_get_wrappers()) |
|
759 | - ) { |
|
760 | - $stream = 'fakeinput://data'; |
|
761 | - } else { |
|
762 | - $stream = 'php://input'; |
|
763 | - } |
|
764 | - |
|
765 | - return new Request( |
|
766 | - [ |
|
767 | - 'get' => $_GET, |
|
768 | - 'post' => $_POST, |
|
769 | - 'files' => $_FILES, |
|
770 | - 'server' => $_SERVER, |
|
771 | - 'env' => $_ENV, |
|
772 | - 'cookies' => $_COOKIE, |
|
773 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
774 | - ? $_SERVER['REQUEST_METHOD'] |
|
775 | - : null, |
|
776 | - 'urlParams' => $urlParams, |
|
777 | - ], |
|
778 | - $this->getSecureRandom(), |
|
779 | - $this->getConfig(), |
|
780 | - $this->getCsrfTokenManager(), |
|
781 | - $stream |
|
782 | - ); |
|
783 | - }); |
|
784 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
785 | - |
|
786 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
787 | - return new Mailer( |
|
788 | - $c->getConfig(), |
|
789 | - $c->getLogger(), |
|
790 | - $c->query(Defaults::class), |
|
791 | - $c->getURLGenerator(), |
|
792 | - $c->getL10N('lib') |
|
793 | - ); |
|
794 | - }); |
|
795 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
796 | - |
|
797 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
798 | - $config = $c->getConfig(); |
|
799 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
800 | - if (is_null($factoryClass)) { |
|
801 | - throw new \Exception('ldapProviderFactory not set'); |
|
802 | - } |
|
803 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
804 | - $factory = new $factoryClass($this); |
|
805 | - return $factory->getLDAPProvider(); |
|
806 | - }); |
|
807 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
808 | - $ini = $c->getIniWrapper(); |
|
809 | - $config = $c->getConfig(); |
|
810 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
811 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
812 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
813 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
814 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
815 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
816 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
817 | - } |
|
818 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
819 | - } |
|
820 | - return new NoopLockingProvider(); |
|
821 | - }); |
|
822 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
823 | - |
|
824 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
825 | - return new \OC\Files\Mount\Manager(); |
|
826 | - }); |
|
827 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
828 | - |
|
829 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
830 | - return new \OC\Files\Type\Detection( |
|
831 | - $c->getURLGenerator(), |
|
832 | - \OC::$configDir, |
|
833 | - \OC::$SERVERROOT . '/resources/config/' |
|
834 | - ); |
|
835 | - }); |
|
836 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
837 | - |
|
838 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
839 | - return new \OC\Files\Type\Loader( |
|
840 | - $c->getDatabaseConnection() |
|
841 | - ); |
|
842 | - }); |
|
843 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
844 | - $this->registerService(BundleFetcher::class, function () { |
|
845 | - return new BundleFetcher($this->getL10N('lib')); |
|
846 | - }); |
|
847 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
848 | - return new Manager( |
|
849 | - $c->query(IValidator::class) |
|
850 | - ); |
|
851 | - }); |
|
852 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
853 | - |
|
854 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
855 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
856 | - $manager->registerCapability(function () use ($c) { |
|
857 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
858 | - }); |
|
859 | - $manager->registerCapability(function () use ($c) { |
|
860 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
861 | - }); |
|
862 | - return $manager; |
|
863 | - }); |
|
864 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
865 | - |
|
866 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
867 | - $config = $c->getConfig(); |
|
868 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
869 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
870 | - $factory = new $factoryClass($this); |
|
871 | - return $factory->getManager(); |
|
872 | - }); |
|
873 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
874 | - |
|
875 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
876 | - /* |
|
131 | + /** @var string */ |
|
132 | + private $webRoot; |
|
133 | + |
|
134 | + /** |
|
135 | + * @param string $webRoot |
|
136 | + * @param \OC\Config $config |
|
137 | + */ |
|
138 | + public function __construct($webRoot, \OC\Config $config) { |
|
139 | + parent::__construct(); |
|
140 | + $this->webRoot = $webRoot; |
|
141 | + |
|
142 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
143 | + return $c; |
|
144 | + }); |
|
145 | + |
|
146 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
147 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
148 | + |
|
149 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
150 | + |
|
151 | + |
|
152 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
153 | + return new PreviewManager( |
|
154 | + $c->getConfig(), |
|
155 | + $c->getRootFolder(), |
|
156 | + $c->getAppDataDir('preview'), |
|
157 | + $c->getEventDispatcher(), |
|
158 | + $c->getSession()->get('user_id') |
|
159 | + ); |
|
160 | + }); |
|
161 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
162 | + |
|
163 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
164 | + return new \OC\Preview\Watcher( |
|
165 | + $c->getAppDataDir('preview') |
|
166 | + ); |
|
167 | + }); |
|
168 | + |
|
169 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
170 | + $view = new View(); |
|
171 | + $util = new Encryption\Util( |
|
172 | + $view, |
|
173 | + $c->getUserManager(), |
|
174 | + $c->getGroupManager(), |
|
175 | + $c->getConfig() |
|
176 | + ); |
|
177 | + return new Encryption\Manager( |
|
178 | + $c->getConfig(), |
|
179 | + $c->getLogger(), |
|
180 | + $c->getL10N('core'), |
|
181 | + new View(), |
|
182 | + $util, |
|
183 | + new ArrayCache() |
|
184 | + ); |
|
185 | + }); |
|
186 | + |
|
187 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
188 | + $util = new Encryption\Util( |
|
189 | + new View(), |
|
190 | + $c->getUserManager(), |
|
191 | + $c->getGroupManager(), |
|
192 | + $c->getConfig() |
|
193 | + ); |
|
194 | + return new Encryption\File( |
|
195 | + $util, |
|
196 | + $c->getRootFolder(), |
|
197 | + $c->getShareManager() |
|
198 | + ); |
|
199 | + }); |
|
200 | + |
|
201 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
202 | + $view = new View(); |
|
203 | + $util = new Encryption\Util( |
|
204 | + $view, |
|
205 | + $c->getUserManager(), |
|
206 | + $c->getGroupManager(), |
|
207 | + $c->getConfig() |
|
208 | + ); |
|
209 | + |
|
210 | + return new Encryption\Keys\Storage($view, $util); |
|
211 | + }); |
|
212 | + $this->registerService('TagMapper', function (Server $c) { |
|
213 | + return new TagMapper($c->getDatabaseConnection()); |
|
214 | + }); |
|
215 | + |
|
216 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
217 | + $tagMapper = $c->query('TagMapper'); |
|
218 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
219 | + }); |
|
220 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
221 | + |
|
222 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
223 | + $config = $c->getConfig(); |
|
224 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
225 | + /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
226 | + $factory = new $factoryClass($this); |
|
227 | + return $factory; |
|
228 | + }); |
|
229 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
230 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
231 | + }); |
|
232 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
233 | + |
|
234 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
235 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
236 | + }); |
|
237 | + $this->registerService('RootFolder', function (Server $c) { |
|
238 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
239 | + $view = new View(); |
|
240 | + $root = new Root( |
|
241 | + $manager, |
|
242 | + $view, |
|
243 | + null, |
|
244 | + $c->getUserMountCache(), |
|
245 | + $this->getLogger(), |
|
246 | + $this->getUserManager() |
|
247 | + ); |
|
248 | + $connector = new HookConnector($root, $view); |
|
249 | + $connector->viewToNode(); |
|
250 | + |
|
251 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
252 | + $previewConnector->connectWatcher(); |
|
253 | + |
|
254 | + return $root; |
|
255 | + }); |
|
256 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
257 | + |
|
258 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
259 | + return new LazyRoot(function () use ($c) { |
|
260 | + return $c->query('RootFolder'); |
|
261 | + }); |
|
262 | + }); |
|
263 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
264 | + |
|
265 | + $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
266 | + $config = $c->getConfig(); |
|
267 | + return new \OC\User\Manager($config); |
|
268 | + }); |
|
269 | + $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
270 | + |
|
271 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
272 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
273 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
274 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
275 | + }); |
|
276 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
277 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
278 | + }); |
|
279 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
280 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
281 | + }); |
|
282 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
283 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
284 | + }); |
|
285 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
286 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
287 | + }); |
|
288 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
289 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
290 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
291 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
292 | + }); |
|
293 | + return $groupManager; |
|
294 | + }); |
|
295 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
296 | + |
|
297 | + $this->registerService(Store::class, function (Server $c) { |
|
298 | + $session = $c->getSession(); |
|
299 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
300 | + $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
301 | + } else { |
|
302 | + $tokenProvider = null; |
|
303 | + } |
|
304 | + $logger = $c->getLogger(); |
|
305 | + return new Store($session, $logger, $tokenProvider); |
|
306 | + }); |
|
307 | + $this->registerAlias(IStore::class, Store::class); |
|
308 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
309 | + $dbConnection = $c->getDatabaseConnection(); |
|
310 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
311 | + }); |
|
312 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
313 | + $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
314 | + $crypto = $c->getCrypto(); |
|
315 | + $config = $c->getConfig(); |
|
316 | + $logger = $c->getLogger(); |
|
317 | + $timeFactory = new TimeFactory(); |
|
318 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
319 | + }); |
|
320 | + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
321 | + |
|
322 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
323 | + $manager = $c->getUserManager(); |
|
324 | + $session = new \OC\Session\Memory(''); |
|
325 | + $timeFactory = new TimeFactory(); |
|
326 | + // Token providers might require a working database. This code |
|
327 | + // might however be called when ownCloud is not yet setup. |
|
328 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
329 | + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
330 | + } else { |
|
331 | + $defaultTokenProvider = null; |
|
332 | + } |
|
333 | + |
|
334 | + $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
335 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
336 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
337 | + }); |
|
338 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
339 | + /** @var $user \OC\User\User */ |
|
340 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
341 | + }); |
|
342 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
343 | + /** @var $user \OC\User\User */ |
|
344 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
345 | + }); |
|
346 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
347 | + /** @var $user \OC\User\User */ |
|
348 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
349 | + }); |
|
350 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
351 | + /** @var $user \OC\User\User */ |
|
352 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
353 | + }); |
|
354 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
355 | + /** @var $user \OC\User\User */ |
|
356 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
357 | + }); |
|
358 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
359 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
360 | + }); |
|
361 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
362 | + /** @var $user \OC\User\User */ |
|
363 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
364 | + }); |
|
365 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
366 | + /** @var $user \OC\User\User */ |
|
367 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
368 | + }); |
|
369 | + $userSession->listen('\OC\User', 'logout', function () { |
|
370 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
371 | + }); |
|
372 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
373 | + /** @var $user \OC\User\User */ |
|
374 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
375 | + }); |
|
376 | + return $userSession; |
|
377 | + }); |
|
378 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
379 | + |
|
380 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
381 | + return new \OC\Authentication\TwoFactorAuth\Manager( |
|
382 | + $c->getAppManager(), |
|
383 | + $c->getSession(), |
|
384 | + $c->getConfig(), |
|
385 | + $c->getActivityManager(), |
|
386 | + $c->getLogger(), |
|
387 | + $c->query(\OC\Authentication\Token\IProvider::class), |
|
388 | + $c->query(ITimeFactory::class) |
|
389 | + ); |
|
390 | + }); |
|
391 | + |
|
392 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
393 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
394 | + |
|
395 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
396 | + return new \OC\AllConfig( |
|
397 | + $c->getSystemConfig() |
|
398 | + ); |
|
399 | + }); |
|
400 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
401 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
402 | + |
|
403 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
404 | + return new \OC\SystemConfig($config); |
|
405 | + }); |
|
406 | + |
|
407 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
408 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
409 | + }); |
|
410 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
411 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
412 | + |
|
413 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
414 | + return new \OC\L10N\Factory( |
|
415 | + $c->getConfig(), |
|
416 | + $c->getRequest(), |
|
417 | + $c->getUserSession(), |
|
418 | + \OC::$SERVERROOT |
|
419 | + ); |
|
420 | + }); |
|
421 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
422 | + |
|
423 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
424 | + $config = $c->getConfig(); |
|
425 | + $cacheFactory = $c->getMemCacheFactory(); |
|
426 | + $request = $c->getRequest(); |
|
427 | + return new \OC\URLGenerator( |
|
428 | + $config, |
|
429 | + $cacheFactory, |
|
430 | + $request |
|
431 | + ); |
|
432 | + }); |
|
433 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
434 | + |
|
435 | + $this->registerService('AppHelper', function ($c) { |
|
436 | + return new \OC\AppHelper(); |
|
437 | + }); |
|
438 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
439 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
440 | + |
|
441 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
442 | + return new Cache\File(); |
|
443 | + }); |
|
444 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
445 | + |
|
446 | + $this->registerService(Factory::class, function (Server $c) { |
|
447 | + |
|
448 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
449 | + '\\OC\\Memcache\\ArrayCache', |
|
450 | + '\\OC\\Memcache\\ArrayCache', |
|
451 | + '\\OC\\Memcache\\ArrayCache' |
|
452 | + ); |
|
453 | + $config = $c->getConfig(); |
|
454 | + $request = $c->getRequest(); |
|
455 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
456 | + |
|
457 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
458 | + $v = \OC_App::getAppVersions(); |
|
459 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
460 | + $version = implode(',', $v); |
|
461 | + $instanceId = \OC_Util::getInstanceId(); |
|
462 | + $path = \OC::$SERVERROOT; |
|
463 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
464 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
465 | + $config->getSystemValue('memcache.local', null), |
|
466 | + $config->getSystemValue('memcache.distributed', null), |
|
467 | + $config->getSystemValue('memcache.locking', null) |
|
468 | + ); |
|
469 | + } |
|
470 | + return $arrayCacheFactory; |
|
471 | + |
|
472 | + }); |
|
473 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
474 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
475 | + |
|
476 | + $this->registerService('RedisFactory', function (Server $c) { |
|
477 | + $systemConfig = $c->getSystemConfig(); |
|
478 | + return new RedisFactory($systemConfig); |
|
479 | + }); |
|
480 | + |
|
481 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
482 | + return new \OC\Activity\Manager( |
|
483 | + $c->getRequest(), |
|
484 | + $c->getUserSession(), |
|
485 | + $c->getConfig(), |
|
486 | + $c->query(IValidator::class) |
|
487 | + ); |
|
488 | + }); |
|
489 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
490 | + |
|
491 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
492 | + return new \OC\Activity\EventMerger( |
|
493 | + $c->getL10N('lib') |
|
494 | + ); |
|
495 | + }); |
|
496 | + $this->registerAlias(IValidator::class, Validator::class); |
|
497 | + |
|
498 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
499 | + return new AvatarManager( |
|
500 | + $c->getUserManager(), |
|
501 | + $c->getAppDataDir('avatar'), |
|
502 | + $c->getL10N('lib'), |
|
503 | + $c->getLogger(), |
|
504 | + $c->getConfig() |
|
505 | + ); |
|
506 | + }); |
|
507 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
508 | + |
|
509 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
510 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
511 | + $logger = Log::getLogClass($logType); |
|
512 | + call_user_func(array($logger, 'init')); |
|
513 | + |
|
514 | + return new Log($logger); |
|
515 | + }); |
|
516 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
517 | + |
|
518 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
519 | + $config = $c->getConfig(); |
|
520 | + return new \OC\BackgroundJob\JobList( |
|
521 | + $c->getDatabaseConnection(), |
|
522 | + $config, |
|
523 | + new TimeFactory() |
|
524 | + ); |
|
525 | + }); |
|
526 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
527 | + |
|
528 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
529 | + $cacheFactory = $c->getMemCacheFactory(); |
|
530 | + $logger = $c->getLogger(); |
|
531 | + if ($cacheFactory->isAvailable()) { |
|
532 | + $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
533 | + } else { |
|
534 | + $router = new \OC\Route\Router($logger); |
|
535 | + } |
|
536 | + return $router; |
|
537 | + }); |
|
538 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
539 | + |
|
540 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
541 | + return new Search(); |
|
542 | + }); |
|
543 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
544 | + |
|
545 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
546 | + return new \OC\Security\RateLimiting\Limiter( |
|
547 | + $this->getUserSession(), |
|
548 | + $this->getRequest(), |
|
549 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
550 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
551 | + ); |
|
552 | + }); |
|
553 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
554 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
555 | + $this->getMemCacheFactory(), |
|
556 | + new \OC\AppFramework\Utility\TimeFactory() |
|
557 | + ); |
|
558 | + }); |
|
559 | + |
|
560 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
561 | + return new SecureRandom(); |
|
562 | + }); |
|
563 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
564 | + |
|
565 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
566 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
567 | + }); |
|
568 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
569 | + |
|
570 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
571 | + return new Hasher($c->getConfig()); |
|
572 | + }); |
|
573 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
574 | + |
|
575 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
576 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
577 | + }); |
|
578 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
579 | + |
|
580 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
581 | + $systemConfig = $c->getSystemConfig(); |
|
582 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
583 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
584 | + if (!$factory->isValidType($type)) { |
|
585 | + throw new \OC\DatabaseException('Invalid database type'); |
|
586 | + } |
|
587 | + $connectionParams = $factory->createConnectionParams(); |
|
588 | + $connection = $factory->getConnection($type, $connectionParams); |
|
589 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
590 | + return $connection; |
|
591 | + }); |
|
592 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
593 | + |
|
594 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
595 | + $config = $c->getConfig(); |
|
596 | + return new HTTPHelper( |
|
597 | + $config, |
|
598 | + $c->getHTTPClientService() |
|
599 | + ); |
|
600 | + }); |
|
601 | + |
|
602 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
603 | + $user = \OC_User::getUser(); |
|
604 | + $uid = $user ? $user : null; |
|
605 | + return new ClientService( |
|
606 | + $c->getConfig(), |
|
607 | + new \OC\Security\CertificateManager( |
|
608 | + $uid, |
|
609 | + new View(), |
|
610 | + $c->getConfig(), |
|
611 | + $c->getLogger(), |
|
612 | + $c->getSecureRandom() |
|
613 | + ) |
|
614 | + ); |
|
615 | + }); |
|
616 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
617 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
618 | + $eventLogger = new EventLogger(); |
|
619 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
620 | + // In debug mode, module is being activated by default |
|
621 | + $eventLogger->activate(); |
|
622 | + } |
|
623 | + return $eventLogger; |
|
624 | + }); |
|
625 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
626 | + |
|
627 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
628 | + $queryLogger = new QueryLogger(); |
|
629 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
630 | + // In debug mode, module is being activated by default |
|
631 | + $queryLogger->activate(); |
|
632 | + } |
|
633 | + return $queryLogger; |
|
634 | + }); |
|
635 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
636 | + |
|
637 | + $this->registerService(TempManager::class, function (Server $c) { |
|
638 | + return new TempManager( |
|
639 | + $c->getLogger(), |
|
640 | + $c->getConfig() |
|
641 | + ); |
|
642 | + }); |
|
643 | + $this->registerAlias('TempManager', TempManager::class); |
|
644 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
645 | + |
|
646 | + $this->registerService(AppManager::class, function (Server $c) { |
|
647 | + return new \OC\App\AppManager( |
|
648 | + $c->getUserSession(), |
|
649 | + $c->getAppConfig(), |
|
650 | + $c->getGroupManager(), |
|
651 | + $c->getMemCacheFactory(), |
|
652 | + $c->getEventDispatcher() |
|
653 | + ); |
|
654 | + }); |
|
655 | + $this->registerAlias('AppManager', AppManager::class); |
|
656 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
657 | + |
|
658 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
659 | + return new DateTimeZone( |
|
660 | + $c->getConfig(), |
|
661 | + $c->getSession() |
|
662 | + ); |
|
663 | + }); |
|
664 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
665 | + |
|
666 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
667 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
668 | + |
|
669 | + return new DateTimeFormatter( |
|
670 | + $c->getDateTimeZone()->getTimeZone(), |
|
671 | + $c->getL10N('lib', $language) |
|
672 | + ); |
|
673 | + }); |
|
674 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
675 | + |
|
676 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
677 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
678 | + $listener = new UserMountCacheListener($mountCache); |
|
679 | + $listener->listen($c->getUserManager()); |
|
680 | + return $mountCache; |
|
681 | + }); |
|
682 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
683 | + |
|
684 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
685 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
686 | + $mountCache = $c->query('UserMountCache'); |
|
687 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
688 | + |
|
689 | + // builtin providers |
|
690 | + |
|
691 | + $config = $c->getConfig(); |
|
692 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
693 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
694 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
695 | + |
|
696 | + return $manager; |
|
697 | + }); |
|
698 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
699 | + |
|
700 | + $this->registerService('IniWrapper', function ($c) { |
|
701 | + return new IniGetWrapper(); |
|
702 | + }); |
|
703 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
704 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
705 | + if ($busClass) { |
|
706 | + list($app, $class) = explode('::', $busClass, 2); |
|
707 | + if ($c->getAppManager()->isInstalled($app)) { |
|
708 | + \OC_App::loadApp($app); |
|
709 | + return $c->query($class); |
|
710 | + } else { |
|
711 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
712 | + } |
|
713 | + } else { |
|
714 | + $jobList = $c->getJobList(); |
|
715 | + return new CronBus($jobList); |
|
716 | + } |
|
717 | + }); |
|
718 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
719 | + return new TrustedDomainHelper($this->getConfig()); |
|
720 | + }); |
|
721 | + $this->registerService('Throttler', function (Server $c) { |
|
722 | + return new Throttler( |
|
723 | + $c->getDatabaseConnection(), |
|
724 | + new TimeFactory(), |
|
725 | + $c->getLogger(), |
|
726 | + $c->getConfig() |
|
727 | + ); |
|
728 | + }); |
|
729 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
730 | + // IConfig and IAppManager requires a working database. This code |
|
731 | + // might however be called when ownCloud is not yet setup. |
|
732 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
733 | + $config = $c->getConfig(); |
|
734 | + $appManager = $c->getAppManager(); |
|
735 | + } else { |
|
736 | + $config = null; |
|
737 | + $appManager = null; |
|
738 | + } |
|
739 | + |
|
740 | + return new Checker( |
|
741 | + new EnvironmentHelper(), |
|
742 | + new FileAccessHelper(), |
|
743 | + new AppLocator(), |
|
744 | + $config, |
|
745 | + $c->getMemCacheFactory(), |
|
746 | + $appManager, |
|
747 | + $c->getTempManager() |
|
748 | + ); |
|
749 | + }); |
|
750 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
751 | + if (isset($this['urlParams'])) { |
|
752 | + $urlParams = $this['urlParams']; |
|
753 | + } else { |
|
754 | + $urlParams = []; |
|
755 | + } |
|
756 | + |
|
757 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
758 | + && in_array('fakeinput', stream_get_wrappers()) |
|
759 | + ) { |
|
760 | + $stream = 'fakeinput://data'; |
|
761 | + } else { |
|
762 | + $stream = 'php://input'; |
|
763 | + } |
|
764 | + |
|
765 | + return new Request( |
|
766 | + [ |
|
767 | + 'get' => $_GET, |
|
768 | + 'post' => $_POST, |
|
769 | + 'files' => $_FILES, |
|
770 | + 'server' => $_SERVER, |
|
771 | + 'env' => $_ENV, |
|
772 | + 'cookies' => $_COOKIE, |
|
773 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
774 | + ? $_SERVER['REQUEST_METHOD'] |
|
775 | + : null, |
|
776 | + 'urlParams' => $urlParams, |
|
777 | + ], |
|
778 | + $this->getSecureRandom(), |
|
779 | + $this->getConfig(), |
|
780 | + $this->getCsrfTokenManager(), |
|
781 | + $stream |
|
782 | + ); |
|
783 | + }); |
|
784 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
785 | + |
|
786 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
787 | + return new Mailer( |
|
788 | + $c->getConfig(), |
|
789 | + $c->getLogger(), |
|
790 | + $c->query(Defaults::class), |
|
791 | + $c->getURLGenerator(), |
|
792 | + $c->getL10N('lib') |
|
793 | + ); |
|
794 | + }); |
|
795 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
796 | + |
|
797 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
798 | + $config = $c->getConfig(); |
|
799 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
800 | + if (is_null($factoryClass)) { |
|
801 | + throw new \Exception('ldapProviderFactory not set'); |
|
802 | + } |
|
803 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
804 | + $factory = new $factoryClass($this); |
|
805 | + return $factory->getLDAPProvider(); |
|
806 | + }); |
|
807 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
808 | + $ini = $c->getIniWrapper(); |
|
809 | + $config = $c->getConfig(); |
|
810 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
811 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
812 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
813 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
814 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
815 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
816 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
817 | + } |
|
818 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
819 | + } |
|
820 | + return new NoopLockingProvider(); |
|
821 | + }); |
|
822 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
823 | + |
|
824 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
825 | + return new \OC\Files\Mount\Manager(); |
|
826 | + }); |
|
827 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
828 | + |
|
829 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
830 | + return new \OC\Files\Type\Detection( |
|
831 | + $c->getURLGenerator(), |
|
832 | + \OC::$configDir, |
|
833 | + \OC::$SERVERROOT . '/resources/config/' |
|
834 | + ); |
|
835 | + }); |
|
836 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
837 | + |
|
838 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
839 | + return new \OC\Files\Type\Loader( |
|
840 | + $c->getDatabaseConnection() |
|
841 | + ); |
|
842 | + }); |
|
843 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
844 | + $this->registerService(BundleFetcher::class, function () { |
|
845 | + return new BundleFetcher($this->getL10N('lib')); |
|
846 | + }); |
|
847 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
848 | + return new Manager( |
|
849 | + $c->query(IValidator::class) |
|
850 | + ); |
|
851 | + }); |
|
852 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
853 | + |
|
854 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
855 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
856 | + $manager->registerCapability(function () use ($c) { |
|
857 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
858 | + }); |
|
859 | + $manager->registerCapability(function () use ($c) { |
|
860 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
861 | + }); |
|
862 | + return $manager; |
|
863 | + }); |
|
864 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
865 | + |
|
866 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
867 | + $config = $c->getConfig(); |
|
868 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
869 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
870 | + $factory = new $factoryClass($this); |
|
871 | + return $factory->getManager(); |
|
872 | + }); |
|
873 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
874 | + |
|
875 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
876 | + /* |
|
877 | 877 | * Dark magic for autoloader. |
878 | 878 | * If we do a class_exists it will try to load the class which will |
879 | 879 | * make composer cache the result. Resulting in errors when enabling |
880 | 880 | * the theming app. |
881 | 881 | */ |
882 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
883 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
884 | - $classExists = true; |
|
885 | - } else { |
|
886 | - $classExists = false; |
|
887 | - } |
|
888 | - |
|
889 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
890 | - return new ThemingDefaults( |
|
891 | - $c->getConfig(), |
|
892 | - $c->getL10N('theming'), |
|
893 | - $c->getURLGenerator(), |
|
894 | - $c->getAppDataDir('theming'), |
|
895 | - $c->getMemCacheFactory(), |
|
896 | - new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
897 | - $this->getAppManager() |
|
898 | - ); |
|
899 | - } |
|
900 | - return new \OC_Defaults(); |
|
901 | - }); |
|
902 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
903 | - /** @var Factory $cacheFactory */ |
|
904 | - $cacheFactory = $c->query(Factory::class); |
|
905 | - return new SCSSCacher( |
|
906 | - $c->getLogger(), |
|
907 | - $c->query(\OC\Files\AppData\Factory::class), |
|
908 | - $c->getURLGenerator(), |
|
909 | - $c->getConfig(), |
|
910 | - $c->getThemingDefaults(), |
|
911 | - \OC::$SERVERROOT, |
|
912 | - $cacheFactory->create('SCSS') |
|
913 | - ); |
|
914 | - }); |
|
915 | - $this->registerService(EventDispatcher::class, function () { |
|
916 | - return new EventDispatcher(); |
|
917 | - }); |
|
918 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
919 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
920 | - |
|
921 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
922 | - // FIXME: Instantiiated here due to cyclic dependency |
|
923 | - $request = new Request( |
|
924 | - [ |
|
925 | - 'get' => $_GET, |
|
926 | - 'post' => $_POST, |
|
927 | - 'files' => $_FILES, |
|
928 | - 'server' => $_SERVER, |
|
929 | - 'env' => $_ENV, |
|
930 | - 'cookies' => $_COOKIE, |
|
931 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
932 | - ? $_SERVER['REQUEST_METHOD'] |
|
933 | - : null, |
|
934 | - ], |
|
935 | - $c->getSecureRandom(), |
|
936 | - $c->getConfig() |
|
937 | - ); |
|
938 | - |
|
939 | - return new CryptoWrapper( |
|
940 | - $c->getConfig(), |
|
941 | - $c->getCrypto(), |
|
942 | - $c->getSecureRandom(), |
|
943 | - $request |
|
944 | - ); |
|
945 | - }); |
|
946 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
947 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
948 | - |
|
949 | - return new CsrfTokenManager( |
|
950 | - $tokenGenerator, |
|
951 | - $c->query(SessionStorage::class) |
|
952 | - ); |
|
953 | - }); |
|
954 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
955 | - return new SessionStorage($c->getSession()); |
|
956 | - }); |
|
957 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
958 | - return new ContentSecurityPolicyManager(); |
|
959 | - }); |
|
960 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
961 | - |
|
962 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
963 | - return new ContentSecurityPolicyNonceManager( |
|
964 | - $c->getCsrfTokenManager(), |
|
965 | - $c->getRequest() |
|
966 | - ); |
|
967 | - }); |
|
968 | - |
|
969 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
970 | - $config = $c->getConfig(); |
|
971 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
972 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
973 | - $factory = new $factoryClass($this); |
|
974 | - |
|
975 | - $manager = new \OC\Share20\Manager( |
|
976 | - $c->getLogger(), |
|
977 | - $c->getConfig(), |
|
978 | - $c->getSecureRandom(), |
|
979 | - $c->getHasher(), |
|
980 | - $c->getMountManager(), |
|
981 | - $c->getGroupManager(), |
|
982 | - $c->getL10N('lib'), |
|
983 | - $c->getL10NFactory(), |
|
984 | - $factory, |
|
985 | - $c->getUserManager(), |
|
986 | - $c->getLazyRootFolder(), |
|
987 | - $c->getEventDispatcher(), |
|
988 | - $c->getMailer(), |
|
989 | - $c->getURLGenerator(), |
|
990 | - $c->getThemingDefaults() |
|
991 | - ); |
|
992 | - |
|
993 | - return $manager; |
|
994 | - }); |
|
995 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
996 | - |
|
997 | - $this->registerService('SettingsManager', function (Server $c) { |
|
998 | - $manager = new \OC\Settings\Manager( |
|
999 | - $c->getLogger(), |
|
1000 | - $c->getDatabaseConnection(), |
|
1001 | - $c->getL10N('lib'), |
|
1002 | - $c->getConfig(), |
|
1003 | - $c->getEncryptionManager(), |
|
1004 | - $c->getUserManager(), |
|
1005 | - $c->getLockingProvider(), |
|
1006 | - $c->getRequest(), |
|
1007 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
1008 | - $c->getURLGenerator(), |
|
1009 | - $c->query(AccountManager::class), |
|
1010 | - $c->getGroupManager(), |
|
1011 | - $c->getL10NFactory(), |
|
1012 | - $c->getThemingDefaults(), |
|
1013 | - $c->getAppManager() |
|
1014 | - ); |
|
1015 | - return $manager; |
|
1016 | - }); |
|
1017 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1018 | - return new \OC\Files\AppData\Factory( |
|
1019 | - $c->getRootFolder(), |
|
1020 | - $c->getSystemConfig() |
|
1021 | - ); |
|
1022 | - }); |
|
1023 | - |
|
1024 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1025 | - return new LockdownManager(function () use ($c) { |
|
1026 | - return $c->getSession(); |
|
1027 | - }); |
|
1028 | - }); |
|
1029 | - |
|
1030 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1031 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1032 | - }); |
|
1033 | - |
|
1034 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1035 | - return new CloudIdManager(); |
|
1036 | - }); |
|
1037 | - |
|
1038 | - /* To trick DI since we don't extend the DIContainer here */ |
|
1039 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
1040 | - return new CleanPreviewsBackgroundJob( |
|
1041 | - $c->getRootFolder(), |
|
1042 | - $c->getLogger(), |
|
1043 | - $c->getJobList(), |
|
1044 | - new TimeFactory() |
|
1045 | - ); |
|
1046 | - }); |
|
1047 | - |
|
1048 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1049 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1050 | - |
|
1051 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1052 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1053 | - |
|
1054 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1055 | - return new Defaults( |
|
1056 | - $c->getThemingDefaults() |
|
1057 | - ); |
|
1058 | - }); |
|
1059 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1060 | - |
|
1061 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1062 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1063 | - }); |
|
1064 | - |
|
1065 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1066 | - return new ShareHelper( |
|
1067 | - $c->query(\OCP\Share\IManager::class) |
|
1068 | - ); |
|
1069 | - }); |
|
1070 | - |
|
1071 | - $this->registerService(\OCP\Contacts\ContactsMenu\IContactsStore::class, function(Server $c) { |
|
1072 | - return new ContactsStore( |
|
1073 | - $this->getContactsManager(), |
|
1074 | - $this->getConfig(), |
|
1075 | - $this->getUserManager(), |
|
1076 | - $this->getGroupManager() |
|
1077 | - ); |
|
1078 | - }); |
|
1079 | - |
|
1080 | - |
|
1081 | - } |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * @return \OCP\Contacts\IManager |
|
1085 | - */ |
|
1086 | - public function getContactsManager() { |
|
1087 | - return $this->query('ContactsManager'); |
|
1088 | - } |
|
1089 | - |
|
1090 | - /** |
|
1091 | - * @return \OC\Encryption\Manager |
|
1092 | - */ |
|
1093 | - public function getEncryptionManager() { |
|
1094 | - return $this->query('EncryptionManager'); |
|
1095 | - } |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * @return \OC\Encryption\File |
|
1099 | - */ |
|
1100 | - public function getEncryptionFilesHelper() { |
|
1101 | - return $this->query('EncryptionFileHelper'); |
|
1102 | - } |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * @return \OCP\Encryption\Keys\IStorage |
|
1106 | - */ |
|
1107 | - public function getEncryptionKeyStorage() { |
|
1108 | - return $this->query('EncryptionKeyStorage'); |
|
1109 | - } |
|
1110 | - |
|
1111 | - /** |
|
1112 | - * The current request object holding all information about the request |
|
1113 | - * currently being processed is returned from this method. |
|
1114 | - * In case the current execution was not initiated by a web request null is returned |
|
1115 | - * |
|
1116 | - * @return \OCP\IRequest |
|
1117 | - */ |
|
1118 | - public function getRequest() { |
|
1119 | - return $this->query('Request'); |
|
1120 | - } |
|
1121 | - |
|
1122 | - /** |
|
1123 | - * Returns the preview manager which can create preview images for a given file |
|
1124 | - * |
|
1125 | - * @return \OCP\IPreview |
|
1126 | - */ |
|
1127 | - public function getPreviewManager() { |
|
1128 | - return $this->query('PreviewManager'); |
|
1129 | - } |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * Returns the tag manager which can get and set tags for different object types |
|
1133 | - * |
|
1134 | - * @see \OCP\ITagManager::load() |
|
1135 | - * @return \OCP\ITagManager |
|
1136 | - */ |
|
1137 | - public function getTagManager() { |
|
1138 | - return $this->query('TagManager'); |
|
1139 | - } |
|
1140 | - |
|
1141 | - /** |
|
1142 | - * Returns the system-tag manager |
|
1143 | - * |
|
1144 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1145 | - * |
|
1146 | - * @since 9.0.0 |
|
1147 | - */ |
|
1148 | - public function getSystemTagManager() { |
|
1149 | - return $this->query('SystemTagManager'); |
|
1150 | - } |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * Returns the system-tag object mapper |
|
1154 | - * |
|
1155 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1156 | - * |
|
1157 | - * @since 9.0.0 |
|
1158 | - */ |
|
1159 | - public function getSystemTagObjectMapper() { |
|
1160 | - return $this->query('SystemTagObjectMapper'); |
|
1161 | - } |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * Returns the avatar manager, used for avatar functionality |
|
1165 | - * |
|
1166 | - * @return \OCP\IAvatarManager |
|
1167 | - */ |
|
1168 | - public function getAvatarManager() { |
|
1169 | - return $this->query('AvatarManager'); |
|
1170 | - } |
|
1171 | - |
|
1172 | - /** |
|
1173 | - * Returns the root folder of ownCloud's data directory |
|
1174 | - * |
|
1175 | - * @return \OCP\Files\IRootFolder |
|
1176 | - */ |
|
1177 | - public function getRootFolder() { |
|
1178 | - return $this->query('LazyRootFolder'); |
|
1179 | - } |
|
1180 | - |
|
1181 | - /** |
|
1182 | - * Returns the root folder of ownCloud's data directory |
|
1183 | - * This is the lazy variant so this gets only initialized once it |
|
1184 | - * is actually used. |
|
1185 | - * |
|
1186 | - * @return \OCP\Files\IRootFolder |
|
1187 | - */ |
|
1188 | - public function getLazyRootFolder() { |
|
1189 | - return $this->query('LazyRootFolder'); |
|
1190 | - } |
|
1191 | - |
|
1192 | - /** |
|
1193 | - * Returns a view to ownCloud's files folder |
|
1194 | - * |
|
1195 | - * @param string $userId user ID |
|
1196 | - * @return \OCP\Files\Folder|null |
|
1197 | - */ |
|
1198 | - public function getUserFolder($userId = null) { |
|
1199 | - if ($userId === null) { |
|
1200 | - $user = $this->getUserSession()->getUser(); |
|
1201 | - if (!$user) { |
|
1202 | - return null; |
|
1203 | - } |
|
1204 | - $userId = $user->getUID(); |
|
1205 | - } |
|
1206 | - $root = $this->getRootFolder(); |
|
1207 | - return $root->getUserFolder($userId); |
|
1208 | - } |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * Returns an app-specific view in ownClouds data directory |
|
1212 | - * |
|
1213 | - * @return \OCP\Files\Folder |
|
1214 | - * @deprecated since 9.2.0 use IAppData |
|
1215 | - */ |
|
1216 | - public function getAppFolder() { |
|
1217 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1218 | - $root = $this->getRootFolder(); |
|
1219 | - if (!$root->nodeExists($dir)) { |
|
1220 | - $folder = $root->newFolder($dir); |
|
1221 | - } else { |
|
1222 | - $folder = $root->get($dir); |
|
1223 | - } |
|
1224 | - return $folder; |
|
1225 | - } |
|
1226 | - |
|
1227 | - /** |
|
1228 | - * @return \OC\User\Manager |
|
1229 | - */ |
|
1230 | - public function getUserManager() { |
|
1231 | - return $this->query('UserManager'); |
|
1232 | - } |
|
1233 | - |
|
1234 | - /** |
|
1235 | - * @return \OC\Group\Manager |
|
1236 | - */ |
|
1237 | - public function getGroupManager() { |
|
1238 | - return $this->query('GroupManager'); |
|
1239 | - } |
|
1240 | - |
|
1241 | - /** |
|
1242 | - * @return \OC\User\Session |
|
1243 | - */ |
|
1244 | - public function getUserSession() { |
|
1245 | - return $this->query('UserSession'); |
|
1246 | - } |
|
1247 | - |
|
1248 | - /** |
|
1249 | - * @return \OCP\ISession |
|
1250 | - */ |
|
1251 | - public function getSession() { |
|
1252 | - return $this->query('UserSession')->getSession(); |
|
1253 | - } |
|
1254 | - |
|
1255 | - /** |
|
1256 | - * @param \OCP\ISession $session |
|
1257 | - */ |
|
1258 | - public function setSession(\OCP\ISession $session) { |
|
1259 | - $this->query(SessionStorage::class)->setSession($session); |
|
1260 | - $this->query('UserSession')->setSession($session); |
|
1261 | - $this->query(Store::class)->setSession($session); |
|
1262 | - } |
|
1263 | - |
|
1264 | - /** |
|
1265 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1266 | - */ |
|
1267 | - public function getTwoFactorAuthManager() { |
|
1268 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1269 | - } |
|
1270 | - |
|
1271 | - /** |
|
1272 | - * @return \OC\NavigationManager |
|
1273 | - */ |
|
1274 | - public function getNavigationManager() { |
|
1275 | - return $this->query('NavigationManager'); |
|
1276 | - } |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * @return \OCP\IConfig |
|
1280 | - */ |
|
1281 | - public function getConfig() { |
|
1282 | - return $this->query('AllConfig'); |
|
1283 | - } |
|
1284 | - |
|
1285 | - /** |
|
1286 | - * @return \OC\SystemConfig |
|
1287 | - */ |
|
1288 | - public function getSystemConfig() { |
|
1289 | - return $this->query('SystemConfig'); |
|
1290 | - } |
|
1291 | - |
|
1292 | - /** |
|
1293 | - * Returns the app config manager |
|
1294 | - * |
|
1295 | - * @return \OCP\IAppConfig |
|
1296 | - */ |
|
1297 | - public function getAppConfig() { |
|
1298 | - return $this->query('AppConfig'); |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * @return \OCP\L10N\IFactory |
|
1303 | - */ |
|
1304 | - public function getL10NFactory() { |
|
1305 | - return $this->query('L10NFactory'); |
|
1306 | - } |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * get an L10N instance |
|
1310 | - * |
|
1311 | - * @param string $app appid |
|
1312 | - * @param string $lang |
|
1313 | - * @return IL10N |
|
1314 | - */ |
|
1315 | - public function getL10N($app, $lang = null) { |
|
1316 | - return $this->getL10NFactory()->get($app, $lang); |
|
1317 | - } |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * @return \OCP\IURLGenerator |
|
1321 | - */ |
|
1322 | - public function getURLGenerator() { |
|
1323 | - return $this->query('URLGenerator'); |
|
1324 | - } |
|
1325 | - |
|
1326 | - /** |
|
1327 | - * @return \OCP\IHelper |
|
1328 | - */ |
|
1329 | - public function getHelper() { |
|
1330 | - return $this->query('AppHelper'); |
|
1331 | - } |
|
1332 | - |
|
1333 | - /** |
|
1334 | - * @return AppFetcher |
|
1335 | - */ |
|
1336 | - public function getAppFetcher() { |
|
1337 | - return $this->query(AppFetcher::class); |
|
1338 | - } |
|
1339 | - |
|
1340 | - /** |
|
1341 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1342 | - * getMemCacheFactory() instead. |
|
1343 | - * |
|
1344 | - * @return \OCP\ICache |
|
1345 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1346 | - */ |
|
1347 | - public function getCache() { |
|
1348 | - return $this->query('UserCache'); |
|
1349 | - } |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * Returns an \OCP\CacheFactory instance |
|
1353 | - * |
|
1354 | - * @return \OCP\ICacheFactory |
|
1355 | - */ |
|
1356 | - public function getMemCacheFactory() { |
|
1357 | - return $this->query('MemCacheFactory'); |
|
1358 | - } |
|
1359 | - |
|
1360 | - /** |
|
1361 | - * Returns an \OC\RedisFactory instance |
|
1362 | - * |
|
1363 | - * @return \OC\RedisFactory |
|
1364 | - */ |
|
1365 | - public function getGetRedisFactory() { |
|
1366 | - return $this->query('RedisFactory'); |
|
1367 | - } |
|
1368 | - |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * Returns the current session |
|
1372 | - * |
|
1373 | - * @return \OCP\IDBConnection |
|
1374 | - */ |
|
1375 | - public function getDatabaseConnection() { |
|
1376 | - return $this->query('DatabaseConnection'); |
|
1377 | - } |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * Returns the activity manager |
|
1381 | - * |
|
1382 | - * @return \OCP\Activity\IManager |
|
1383 | - */ |
|
1384 | - public function getActivityManager() { |
|
1385 | - return $this->query('ActivityManager'); |
|
1386 | - } |
|
1387 | - |
|
1388 | - /** |
|
1389 | - * Returns an job list for controlling background jobs |
|
1390 | - * |
|
1391 | - * @return \OCP\BackgroundJob\IJobList |
|
1392 | - */ |
|
1393 | - public function getJobList() { |
|
1394 | - return $this->query('JobList'); |
|
1395 | - } |
|
1396 | - |
|
1397 | - /** |
|
1398 | - * Returns a logger instance |
|
1399 | - * |
|
1400 | - * @return \OCP\ILogger |
|
1401 | - */ |
|
1402 | - public function getLogger() { |
|
1403 | - return $this->query('Logger'); |
|
1404 | - } |
|
1405 | - |
|
1406 | - /** |
|
1407 | - * Returns a router for generating and matching urls |
|
1408 | - * |
|
1409 | - * @return \OCP\Route\IRouter |
|
1410 | - */ |
|
1411 | - public function getRouter() { |
|
1412 | - return $this->query('Router'); |
|
1413 | - } |
|
1414 | - |
|
1415 | - /** |
|
1416 | - * Returns a search instance |
|
1417 | - * |
|
1418 | - * @return \OCP\ISearch |
|
1419 | - */ |
|
1420 | - public function getSearch() { |
|
1421 | - return $this->query('Search'); |
|
1422 | - } |
|
1423 | - |
|
1424 | - /** |
|
1425 | - * Returns a SecureRandom instance |
|
1426 | - * |
|
1427 | - * @return \OCP\Security\ISecureRandom |
|
1428 | - */ |
|
1429 | - public function getSecureRandom() { |
|
1430 | - return $this->query('SecureRandom'); |
|
1431 | - } |
|
1432 | - |
|
1433 | - /** |
|
1434 | - * Returns a Crypto instance |
|
1435 | - * |
|
1436 | - * @return \OCP\Security\ICrypto |
|
1437 | - */ |
|
1438 | - public function getCrypto() { |
|
1439 | - return $this->query('Crypto'); |
|
1440 | - } |
|
1441 | - |
|
1442 | - /** |
|
1443 | - * Returns a Hasher instance |
|
1444 | - * |
|
1445 | - * @return \OCP\Security\IHasher |
|
1446 | - */ |
|
1447 | - public function getHasher() { |
|
1448 | - return $this->query('Hasher'); |
|
1449 | - } |
|
1450 | - |
|
1451 | - /** |
|
1452 | - * Returns a CredentialsManager instance |
|
1453 | - * |
|
1454 | - * @return \OCP\Security\ICredentialsManager |
|
1455 | - */ |
|
1456 | - public function getCredentialsManager() { |
|
1457 | - return $this->query('CredentialsManager'); |
|
1458 | - } |
|
1459 | - |
|
1460 | - /** |
|
1461 | - * Returns an instance of the HTTP helper class |
|
1462 | - * |
|
1463 | - * @deprecated Use getHTTPClientService() |
|
1464 | - * @return \OC\HTTPHelper |
|
1465 | - */ |
|
1466 | - public function getHTTPHelper() { |
|
1467 | - return $this->query('HTTPHelper'); |
|
1468 | - } |
|
1469 | - |
|
1470 | - /** |
|
1471 | - * Get the certificate manager for the user |
|
1472 | - * |
|
1473 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1474 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1475 | - */ |
|
1476 | - public function getCertificateManager($userId = '') { |
|
1477 | - if ($userId === '') { |
|
1478 | - $userSession = $this->getUserSession(); |
|
1479 | - $user = $userSession->getUser(); |
|
1480 | - if (is_null($user)) { |
|
1481 | - return null; |
|
1482 | - } |
|
1483 | - $userId = $user->getUID(); |
|
1484 | - } |
|
1485 | - return new CertificateManager( |
|
1486 | - $userId, |
|
1487 | - new View(), |
|
1488 | - $this->getConfig(), |
|
1489 | - $this->getLogger(), |
|
1490 | - $this->getSecureRandom() |
|
1491 | - ); |
|
1492 | - } |
|
1493 | - |
|
1494 | - /** |
|
1495 | - * Returns an instance of the HTTP client service |
|
1496 | - * |
|
1497 | - * @return \OCP\Http\Client\IClientService |
|
1498 | - */ |
|
1499 | - public function getHTTPClientService() { |
|
1500 | - return $this->query('HttpClientService'); |
|
1501 | - } |
|
1502 | - |
|
1503 | - /** |
|
1504 | - * Create a new event source |
|
1505 | - * |
|
1506 | - * @return \OCP\IEventSource |
|
1507 | - */ |
|
1508 | - public function createEventSource() { |
|
1509 | - return new \OC_EventSource(); |
|
1510 | - } |
|
1511 | - |
|
1512 | - /** |
|
1513 | - * Get the active event logger |
|
1514 | - * |
|
1515 | - * The returned logger only logs data when debug mode is enabled |
|
1516 | - * |
|
1517 | - * @return \OCP\Diagnostics\IEventLogger |
|
1518 | - */ |
|
1519 | - public function getEventLogger() { |
|
1520 | - return $this->query('EventLogger'); |
|
1521 | - } |
|
1522 | - |
|
1523 | - /** |
|
1524 | - * Get the active query logger |
|
1525 | - * |
|
1526 | - * The returned logger only logs data when debug mode is enabled |
|
1527 | - * |
|
1528 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1529 | - */ |
|
1530 | - public function getQueryLogger() { |
|
1531 | - return $this->query('QueryLogger'); |
|
1532 | - } |
|
1533 | - |
|
1534 | - /** |
|
1535 | - * Get the manager for temporary files and folders |
|
1536 | - * |
|
1537 | - * @return \OCP\ITempManager |
|
1538 | - */ |
|
1539 | - public function getTempManager() { |
|
1540 | - return $this->query('TempManager'); |
|
1541 | - } |
|
1542 | - |
|
1543 | - /** |
|
1544 | - * Get the app manager |
|
1545 | - * |
|
1546 | - * @return \OCP\App\IAppManager |
|
1547 | - */ |
|
1548 | - public function getAppManager() { |
|
1549 | - return $this->query('AppManager'); |
|
1550 | - } |
|
1551 | - |
|
1552 | - /** |
|
1553 | - * Creates a new mailer |
|
1554 | - * |
|
1555 | - * @return \OCP\Mail\IMailer |
|
1556 | - */ |
|
1557 | - public function getMailer() { |
|
1558 | - return $this->query('Mailer'); |
|
1559 | - } |
|
1560 | - |
|
1561 | - /** |
|
1562 | - * Get the webroot |
|
1563 | - * |
|
1564 | - * @return string |
|
1565 | - */ |
|
1566 | - public function getWebRoot() { |
|
1567 | - return $this->webRoot; |
|
1568 | - } |
|
1569 | - |
|
1570 | - /** |
|
1571 | - * @return \OC\OCSClient |
|
1572 | - */ |
|
1573 | - public function getOcsClient() { |
|
1574 | - return $this->query('OcsClient'); |
|
1575 | - } |
|
1576 | - |
|
1577 | - /** |
|
1578 | - * @return \OCP\IDateTimeZone |
|
1579 | - */ |
|
1580 | - public function getDateTimeZone() { |
|
1581 | - return $this->query('DateTimeZone'); |
|
1582 | - } |
|
1583 | - |
|
1584 | - /** |
|
1585 | - * @return \OCP\IDateTimeFormatter |
|
1586 | - */ |
|
1587 | - public function getDateTimeFormatter() { |
|
1588 | - return $this->query('DateTimeFormatter'); |
|
1589 | - } |
|
1590 | - |
|
1591 | - /** |
|
1592 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1593 | - */ |
|
1594 | - public function getMountProviderCollection() { |
|
1595 | - return $this->query('MountConfigManager'); |
|
1596 | - } |
|
1597 | - |
|
1598 | - /** |
|
1599 | - * Get the IniWrapper |
|
1600 | - * |
|
1601 | - * @return IniGetWrapper |
|
1602 | - */ |
|
1603 | - public function getIniWrapper() { |
|
1604 | - return $this->query('IniWrapper'); |
|
1605 | - } |
|
1606 | - |
|
1607 | - /** |
|
1608 | - * @return \OCP\Command\IBus |
|
1609 | - */ |
|
1610 | - public function getCommandBus() { |
|
1611 | - return $this->query('AsyncCommandBus'); |
|
1612 | - } |
|
1613 | - |
|
1614 | - /** |
|
1615 | - * Get the trusted domain helper |
|
1616 | - * |
|
1617 | - * @return TrustedDomainHelper |
|
1618 | - */ |
|
1619 | - public function getTrustedDomainHelper() { |
|
1620 | - return $this->query('TrustedDomainHelper'); |
|
1621 | - } |
|
1622 | - |
|
1623 | - /** |
|
1624 | - * Get the locking provider |
|
1625 | - * |
|
1626 | - * @return \OCP\Lock\ILockingProvider |
|
1627 | - * @since 8.1.0 |
|
1628 | - */ |
|
1629 | - public function getLockingProvider() { |
|
1630 | - return $this->query('LockingProvider'); |
|
1631 | - } |
|
1632 | - |
|
1633 | - /** |
|
1634 | - * @return \OCP\Files\Mount\IMountManager |
|
1635 | - **/ |
|
1636 | - function getMountManager() { |
|
1637 | - return $this->query('MountManager'); |
|
1638 | - } |
|
1639 | - |
|
1640 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1641 | - function getUserMountCache() { |
|
1642 | - return $this->query('UserMountCache'); |
|
1643 | - } |
|
1644 | - |
|
1645 | - /** |
|
1646 | - * Get the MimeTypeDetector |
|
1647 | - * |
|
1648 | - * @return \OCP\Files\IMimeTypeDetector |
|
1649 | - */ |
|
1650 | - public function getMimeTypeDetector() { |
|
1651 | - return $this->query('MimeTypeDetector'); |
|
1652 | - } |
|
1653 | - |
|
1654 | - /** |
|
1655 | - * Get the MimeTypeLoader |
|
1656 | - * |
|
1657 | - * @return \OCP\Files\IMimeTypeLoader |
|
1658 | - */ |
|
1659 | - public function getMimeTypeLoader() { |
|
1660 | - return $this->query('MimeTypeLoader'); |
|
1661 | - } |
|
1662 | - |
|
1663 | - /** |
|
1664 | - * Get the manager of all the capabilities |
|
1665 | - * |
|
1666 | - * @return \OC\CapabilitiesManager |
|
1667 | - */ |
|
1668 | - public function getCapabilitiesManager() { |
|
1669 | - return $this->query('CapabilitiesManager'); |
|
1670 | - } |
|
1671 | - |
|
1672 | - /** |
|
1673 | - * Get the EventDispatcher |
|
1674 | - * |
|
1675 | - * @return EventDispatcherInterface |
|
1676 | - * @since 8.2.0 |
|
1677 | - */ |
|
1678 | - public function getEventDispatcher() { |
|
1679 | - return $this->query('EventDispatcher'); |
|
1680 | - } |
|
1681 | - |
|
1682 | - /** |
|
1683 | - * Get the Notification Manager |
|
1684 | - * |
|
1685 | - * @return \OCP\Notification\IManager |
|
1686 | - * @since 8.2.0 |
|
1687 | - */ |
|
1688 | - public function getNotificationManager() { |
|
1689 | - return $this->query('NotificationManager'); |
|
1690 | - } |
|
1691 | - |
|
1692 | - /** |
|
1693 | - * @return \OCP\Comments\ICommentsManager |
|
1694 | - */ |
|
1695 | - public function getCommentsManager() { |
|
1696 | - return $this->query('CommentsManager'); |
|
1697 | - } |
|
1698 | - |
|
1699 | - /** |
|
1700 | - * @return \OCA\Theming\ThemingDefaults |
|
1701 | - */ |
|
1702 | - public function getThemingDefaults() { |
|
1703 | - return $this->query('ThemingDefaults'); |
|
1704 | - } |
|
1705 | - |
|
1706 | - /** |
|
1707 | - * @return \OC\IntegrityCheck\Checker |
|
1708 | - */ |
|
1709 | - public function getIntegrityCodeChecker() { |
|
1710 | - return $this->query('IntegrityCodeChecker'); |
|
1711 | - } |
|
1712 | - |
|
1713 | - /** |
|
1714 | - * @return \OC\Session\CryptoWrapper |
|
1715 | - */ |
|
1716 | - public function getSessionCryptoWrapper() { |
|
1717 | - return $this->query('CryptoWrapper'); |
|
1718 | - } |
|
1719 | - |
|
1720 | - /** |
|
1721 | - * @return CsrfTokenManager |
|
1722 | - */ |
|
1723 | - public function getCsrfTokenManager() { |
|
1724 | - return $this->query('CsrfTokenManager'); |
|
1725 | - } |
|
1726 | - |
|
1727 | - /** |
|
1728 | - * @return Throttler |
|
1729 | - */ |
|
1730 | - public function getBruteForceThrottler() { |
|
1731 | - return $this->query('Throttler'); |
|
1732 | - } |
|
1733 | - |
|
1734 | - /** |
|
1735 | - * @return IContentSecurityPolicyManager |
|
1736 | - */ |
|
1737 | - public function getContentSecurityPolicyManager() { |
|
1738 | - return $this->query('ContentSecurityPolicyManager'); |
|
1739 | - } |
|
1740 | - |
|
1741 | - /** |
|
1742 | - * @return ContentSecurityPolicyNonceManager |
|
1743 | - */ |
|
1744 | - public function getContentSecurityPolicyNonceManager() { |
|
1745 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1746 | - } |
|
1747 | - |
|
1748 | - /** |
|
1749 | - * Not a public API as of 8.2, wait for 9.0 |
|
1750 | - * |
|
1751 | - * @return \OCA\Files_External\Service\BackendService |
|
1752 | - */ |
|
1753 | - public function getStoragesBackendService() { |
|
1754 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1755 | - } |
|
1756 | - |
|
1757 | - /** |
|
1758 | - * Not a public API as of 8.2, wait for 9.0 |
|
1759 | - * |
|
1760 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1761 | - */ |
|
1762 | - public function getGlobalStoragesService() { |
|
1763 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1764 | - } |
|
1765 | - |
|
1766 | - /** |
|
1767 | - * Not a public API as of 8.2, wait for 9.0 |
|
1768 | - * |
|
1769 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1770 | - */ |
|
1771 | - public function getUserGlobalStoragesService() { |
|
1772 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1773 | - } |
|
1774 | - |
|
1775 | - /** |
|
1776 | - * Not a public API as of 8.2, wait for 9.0 |
|
1777 | - * |
|
1778 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1779 | - */ |
|
1780 | - public function getUserStoragesService() { |
|
1781 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1782 | - } |
|
1783 | - |
|
1784 | - /** |
|
1785 | - * @return \OCP\Share\IManager |
|
1786 | - */ |
|
1787 | - public function getShareManager() { |
|
1788 | - return $this->query('ShareManager'); |
|
1789 | - } |
|
1790 | - |
|
1791 | - /** |
|
1792 | - * Returns the LDAP Provider |
|
1793 | - * |
|
1794 | - * @return \OCP\LDAP\ILDAPProvider |
|
1795 | - */ |
|
1796 | - public function getLDAPProvider() { |
|
1797 | - return $this->query('LDAPProvider'); |
|
1798 | - } |
|
1799 | - |
|
1800 | - /** |
|
1801 | - * @return \OCP\Settings\IManager |
|
1802 | - */ |
|
1803 | - public function getSettingsManager() { |
|
1804 | - return $this->query('SettingsManager'); |
|
1805 | - } |
|
1806 | - |
|
1807 | - /** |
|
1808 | - * @return \OCP\Files\IAppData |
|
1809 | - */ |
|
1810 | - public function getAppDataDir($app) { |
|
1811 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1812 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1813 | - return $factory->get($app); |
|
1814 | - } |
|
1815 | - |
|
1816 | - /** |
|
1817 | - * @return \OCP\Lockdown\ILockdownManager |
|
1818 | - */ |
|
1819 | - public function getLockdownManager() { |
|
1820 | - return $this->query('LockdownManager'); |
|
1821 | - } |
|
1822 | - |
|
1823 | - /** |
|
1824 | - * @return \OCP\Federation\ICloudIdManager |
|
1825 | - */ |
|
1826 | - public function getCloudIdManager() { |
|
1827 | - return $this->query(ICloudIdManager::class); |
|
1828 | - } |
|
882 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
883 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
884 | + $classExists = true; |
|
885 | + } else { |
|
886 | + $classExists = false; |
|
887 | + } |
|
888 | + |
|
889 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
890 | + return new ThemingDefaults( |
|
891 | + $c->getConfig(), |
|
892 | + $c->getL10N('theming'), |
|
893 | + $c->getURLGenerator(), |
|
894 | + $c->getAppDataDir('theming'), |
|
895 | + $c->getMemCacheFactory(), |
|
896 | + new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
897 | + $this->getAppManager() |
|
898 | + ); |
|
899 | + } |
|
900 | + return new \OC_Defaults(); |
|
901 | + }); |
|
902 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
903 | + /** @var Factory $cacheFactory */ |
|
904 | + $cacheFactory = $c->query(Factory::class); |
|
905 | + return new SCSSCacher( |
|
906 | + $c->getLogger(), |
|
907 | + $c->query(\OC\Files\AppData\Factory::class), |
|
908 | + $c->getURLGenerator(), |
|
909 | + $c->getConfig(), |
|
910 | + $c->getThemingDefaults(), |
|
911 | + \OC::$SERVERROOT, |
|
912 | + $cacheFactory->create('SCSS') |
|
913 | + ); |
|
914 | + }); |
|
915 | + $this->registerService(EventDispatcher::class, function () { |
|
916 | + return new EventDispatcher(); |
|
917 | + }); |
|
918 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
919 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
920 | + |
|
921 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
922 | + // FIXME: Instantiiated here due to cyclic dependency |
|
923 | + $request = new Request( |
|
924 | + [ |
|
925 | + 'get' => $_GET, |
|
926 | + 'post' => $_POST, |
|
927 | + 'files' => $_FILES, |
|
928 | + 'server' => $_SERVER, |
|
929 | + 'env' => $_ENV, |
|
930 | + 'cookies' => $_COOKIE, |
|
931 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
932 | + ? $_SERVER['REQUEST_METHOD'] |
|
933 | + : null, |
|
934 | + ], |
|
935 | + $c->getSecureRandom(), |
|
936 | + $c->getConfig() |
|
937 | + ); |
|
938 | + |
|
939 | + return new CryptoWrapper( |
|
940 | + $c->getConfig(), |
|
941 | + $c->getCrypto(), |
|
942 | + $c->getSecureRandom(), |
|
943 | + $request |
|
944 | + ); |
|
945 | + }); |
|
946 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
947 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
948 | + |
|
949 | + return new CsrfTokenManager( |
|
950 | + $tokenGenerator, |
|
951 | + $c->query(SessionStorage::class) |
|
952 | + ); |
|
953 | + }); |
|
954 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
955 | + return new SessionStorage($c->getSession()); |
|
956 | + }); |
|
957 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
958 | + return new ContentSecurityPolicyManager(); |
|
959 | + }); |
|
960 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
961 | + |
|
962 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
963 | + return new ContentSecurityPolicyNonceManager( |
|
964 | + $c->getCsrfTokenManager(), |
|
965 | + $c->getRequest() |
|
966 | + ); |
|
967 | + }); |
|
968 | + |
|
969 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
970 | + $config = $c->getConfig(); |
|
971 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
972 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
973 | + $factory = new $factoryClass($this); |
|
974 | + |
|
975 | + $manager = new \OC\Share20\Manager( |
|
976 | + $c->getLogger(), |
|
977 | + $c->getConfig(), |
|
978 | + $c->getSecureRandom(), |
|
979 | + $c->getHasher(), |
|
980 | + $c->getMountManager(), |
|
981 | + $c->getGroupManager(), |
|
982 | + $c->getL10N('lib'), |
|
983 | + $c->getL10NFactory(), |
|
984 | + $factory, |
|
985 | + $c->getUserManager(), |
|
986 | + $c->getLazyRootFolder(), |
|
987 | + $c->getEventDispatcher(), |
|
988 | + $c->getMailer(), |
|
989 | + $c->getURLGenerator(), |
|
990 | + $c->getThemingDefaults() |
|
991 | + ); |
|
992 | + |
|
993 | + return $manager; |
|
994 | + }); |
|
995 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
996 | + |
|
997 | + $this->registerService('SettingsManager', function (Server $c) { |
|
998 | + $manager = new \OC\Settings\Manager( |
|
999 | + $c->getLogger(), |
|
1000 | + $c->getDatabaseConnection(), |
|
1001 | + $c->getL10N('lib'), |
|
1002 | + $c->getConfig(), |
|
1003 | + $c->getEncryptionManager(), |
|
1004 | + $c->getUserManager(), |
|
1005 | + $c->getLockingProvider(), |
|
1006 | + $c->getRequest(), |
|
1007 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
1008 | + $c->getURLGenerator(), |
|
1009 | + $c->query(AccountManager::class), |
|
1010 | + $c->getGroupManager(), |
|
1011 | + $c->getL10NFactory(), |
|
1012 | + $c->getThemingDefaults(), |
|
1013 | + $c->getAppManager() |
|
1014 | + ); |
|
1015 | + return $manager; |
|
1016 | + }); |
|
1017 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1018 | + return new \OC\Files\AppData\Factory( |
|
1019 | + $c->getRootFolder(), |
|
1020 | + $c->getSystemConfig() |
|
1021 | + ); |
|
1022 | + }); |
|
1023 | + |
|
1024 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1025 | + return new LockdownManager(function () use ($c) { |
|
1026 | + return $c->getSession(); |
|
1027 | + }); |
|
1028 | + }); |
|
1029 | + |
|
1030 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1031 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1032 | + }); |
|
1033 | + |
|
1034 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1035 | + return new CloudIdManager(); |
|
1036 | + }); |
|
1037 | + |
|
1038 | + /* To trick DI since we don't extend the DIContainer here */ |
|
1039 | + $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
1040 | + return new CleanPreviewsBackgroundJob( |
|
1041 | + $c->getRootFolder(), |
|
1042 | + $c->getLogger(), |
|
1043 | + $c->getJobList(), |
|
1044 | + new TimeFactory() |
|
1045 | + ); |
|
1046 | + }); |
|
1047 | + |
|
1048 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1049 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1050 | + |
|
1051 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1052 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1053 | + |
|
1054 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1055 | + return new Defaults( |
|
1056 | + $c->getThemingDefaults() |
|
1057 | + ); |
|
1058 | + }); |
|
1059 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1060 | + |
|
1061 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1062 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1063 | + }); |
|
1064 | + |
|
1065 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1066 | + return new ShareHelper( |
|
1067 | + $c->query(\OCP\Share\IManager::class) |
|
1068 | + ); |
|
1069 | + }); |
|
1070 | + |
|
1071 | + $this->registerService(\OCP\Contacts\ContactsMenu\IContactsStore::class, function(Server $c) { |
|
1072 | + return new ContactsStore( |
|
1073 | + $this->getContactsManager(), |
|
1074 | + $this->getConfig(), |
|
1075 | + $this->getUserManager(), |
|
1076 | + $this->getGroupManager() |
|
1077 | + ); |
|
1078 | + }); |
|
1079 | + |
|
1080 | + |
|
1081 | + } |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * @return \OCP\Contacts\IManager |
|
1085 | + */ |
|
1086 | + public function getContactsManager() { |
|
1087 | + return $this->query('ContactsManager'); |
|
1088 | + } |
|
1089 | + |
|
1090 | + /** |
|
1091 | + * @return \OC\Encryption\Manager |
|
1092 | + */ |
|
1093 | + public function getEncryptionManager() { |
|
1094 | + return $this->query('EncryptionManager'); |
|
1095 | + } |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * @return \OC\Encryption\File |
|
1099 | + */ |
|
1100 | + public function getEncryptionFilesHelper() { |
|
1101 | + return $this->query('EncryptionFileHelper'); |
|
1102 | + } |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * @return \OCP\Encryption\Keys\IStorage |
|
1106 | + */ |
|
1107 | + public function getEncryptionKeyStorage() { |
|
1108 | + return $this->query('EncryptionKeyStorage'); |
|
1109 | + } |
|
1110 | + |
|
1111 | + /** |
|
1112 | + * The current request object holding all information about the request |
|
1113 | + * currently being processed is returned from this method. |
|
1114 | + * In case the current execution was not initiated by a web request null is returned |
|
1115 | + * |
|
1116 | + * @return \OCP\IRequest |
|
1117 | + */ |
|
1118 | + public function getRequest() { |
|
1119 | + return $this->query('Request'); |
|
1120 | + } |
|
1121 | + |
|
1122 | + /** |
|
1123 | + * Returns the preview manager which can create preview images for a given file |
|
1124 | + * |
|
1125 | + * @return \OCP\IPreview |
|
1126 | + */ |
|
1127 | + public function getPreviewManager() { |
|
1128 | + return $this->query('PreviewManager'); |
|
1129 | + } |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * Returns the tag manager which can get and set tags for different object types |
|
1133 | + * |
|
1134 | + * @see \OCP\ITagManager::load() |
|
1135 | + * @return \OCP\ITagManager |
|
1136 | + */ |
|
1137 | + public function getTagManager() { |
|
1138 | + return $this->query('TagManager'); |
|
1139 | + } |
|
1140 | + |
|
1141 | + /** |
|
1142 | + * Returns the system-tag manager |
|
1143 | + * |
|
1144 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1145 | + * |
|
1146 | + * @since 9.0.0 |
|
1147 | + */ |
|
1148 | + public function getSystemTagManager() { |
|
1149 | + return $this->query('SystemTagManager'); |
|
1150 | + } |
|
1151 | + |
|
1152 | + /** |
|
1153 | + * Returns the system-tag object mapper |
|
1154 | + * |
|
1155 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1156 | + * |
|
1157 | + * @since 9.0.0 |
|
1158 | + */ |
|
1159 | + public function getSystemTagObjectMapper() { |
|
1160 | + return $this->query('SystemTagObjectMapper'); |
|
1161 | + } |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * Returns the avatar manager, used for avatar functionality |
|
1165 | + * |
|
1166 | + * @return \OCP\IAvatarManager |
|
1167 | + */ |
|
1168 | + public function getAvatarManager() { |
|
1169 | + return $this->query('AvatarManager'); |
|
1170 | + } |
|
1171 | + |
|
1172 | + /** |
|
1173 | + * Returns the root folder of ownCloud's data directory |
|
1174 | + * |
|
1175 | + * @return \OCP\Files\IRootFolder |
|
1176 | + */ |
|
1177 | + public function getRootFolder() { |
|
1178 | + return $this->query('LazyRootFolder'); |
|
1179 | + } |
|
1180 | + |
|
1181 | + /** |
|
1182 | + * Returns the root folder of ownCloud's data directory |
|
1183 | + * This is the lazy variant so this gets only initialized once it |
|
1184 | + * is actually used. |
|
1185 | + * |
|
1186 | + * @return \OCP\Files\IRootFolder |
|
1187 | + */ |
|
1188 | + public function getLazyRootFolder() { |
|
1189 | + return $this->query('LazyRootFolder'); |
|
1190 | + } |
|
1191 | + |
|
1192 | + /** |
|
1193 | + * Returns a view to ownCloud's files folder |
|
1194 | + * |
|
1195 | + * @param string $userId user ID |
|
1196 | + * @return \OCP\Files\Folder|null |
|
1197 | + */ |
|
1198 | + public function getUserFolder($userId = null) { |
|
1199 | + if ($userId === null) { |
|
1200 | + $user = $this->getUserSession()->getUser(); |
|
1201 | + if (!$user) { |
|
1202 | + return null; |
|
1203 | + } |
|
1204 | + $userId = $user->getUID(); |
|
1205 | + } |
|
1206 | + $root = $this->getRootFolder(); |
|
1207 | + return $root->getUserFolder($userId); |
|
1208 | + } |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * Returns an app-specific view in ownClouds data directory |
|
1212 | + * |
|
1213 | + * @return \OCP\Files\Folder |
|
1214 | + * @deprecated since 9.2.0 use IAppData |
|
1215 | + */ |
|
1216 | + public function getAppFolder() { |
|
1217 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1218 | + $root = $this->getRootFolder(); |
|
1219 | + if (!$root->nodeExists($dir)) { |
|
1220 | + $folder = $root->newFolder($dir); |
|
1221 | + } else { |
|
1222 | + $folder = $root->get($dir); |
|
1223 | + } |
|
1224 | + return $folder; |
|
1225 | + } |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * @return \OC\User\Manager |
|
1229 | + */ |
|
1230 | + public function getUserManager() { |
|
1231 | + return $this->query('UserManager'); |
|
1232 | + } |
|
1233 | + |
|
1234 | + /** |
|
1235 | + * @return \OC\Group\Manager |
|
1236 | + */ |
|
1237 | + public function getGroupManager() { |
|
1238 | + return $this->query('GroupManager'); |
|
1239 | + } |
|
1240 | + |
|
1241 | + /** |
|
1242 | + * @return \OC\User\Session |
|
1243 | + */ |
|
1244 | + public function getUserSession() { |
|
1245 | + return $this->query('UserSession'); |
|
1246 | + } |
|
1247 | + |
|
1248 | + /** |
|
1249 | + * @return \OCP\ISession |
|
1250 | + */ |
|
1251 | + public function getSession() { |
|
1252 | + return $this->query('UserSession')->getSession(); |
|
1253 | + } |
|
1254 | + |
|
1255 | + /** |
|
1256 | + * @param \OCP\ISession $session |
|
1257 | + */ |
|
1258 | + public function setSession(\OCP\ISession $session) { |
|
1259 | + $this->query(SessionStorage::class)->setSession($session); |
|
1260 | + $this->query('UserSession')->setSession($session); |
|
1261 | + $this->query(Store::class)->setSession($session); |
|
1262 | + } |
|
1263 | + |
|
1264 | + /** |
|
1265 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1266 | + */ |
|
1267 | + public function getTwoFactorAuthManager() { |
|
1268 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1269 | + } |
|
1270 | + |
|
1271 | + /** |
|
1272 | + * @return \OC\NavigationManager |
|
1273 | + */ |
|
1274 | + public function getNavigationManager() { |
|
1275 | + return $this->query('NavigationManager'); |
|
1276 | + } |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * @return \OCP\IConfig |
|
1280 | + */ |
|
1281 | + public function getConfig() { |
|
1282 | + return $this->query('AllConfig'); |
|
1283 | + } |
|
1284 | + |
|
1285 | + /** |
|
1286 | + * @return \OC\SystemConfig |
|
1287 | + */ |
|
1288 | + public function getSystemConfig() { |
|
1289 | + return $this->query('SystemConfig'); |
|
1290 | + } |
|
1291 | + |
|
1292 | + /** |
|
1293 | + * Returns the app config manager |
|
1294 | + * |
|
1295 | + * @return \OCP\IAppConfig |
|
1296 | + */ |
|
1297 | + public function getAppConfig() { |
|
1298 | + return $this->query('AppConfig'); |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * @return \OCP\L10N\IFactory |
|
1303 | + */ |
|
1304 | + public function getL10NFactory() { |
|
1305 | + return $this->query('L10NFactory'); |
|
1306 | + } |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * get an L10N instance |
|
1310 | + * |
|
1311 | + * @param string $app appid |
|
1312 | + * @param string $lang |
|
1313 | + * @return IL10N |
|
1314 | + */ |
|
1315 | + public function getL10N($app, $lang = null) { |
|
1316 | + return $this->getL10NFactory()->get($app, $lang); |
|
1317 | + } |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * @return \OCP\IURLGenerator |
|
1321 | + */ |
|
1322 | + public function getURLGenerator() { |
|
1323 | + return $this->query('URLGenerator'); |
|
1324 | + } |
|
1325 | + |
|
1326 | + /** |
|
1327 | + * @return \OCP\IHelper |
|
1328 | + */ |
|
1329 | + public function getHelper() { |
|
1330 | + return $this->query('AppHelper'); |
|
1331 | + } |
|
1332 | + |
|
1333 | + /** |
|
1334 | + * @return AppFetcher |
|
1335 | + */ |
|
1336 | + public function getAppFetcher() { |
|
1337 | + return $this->query(AppFetcher::class); |
|
1338 | + } |
|
1339 | + |
|
1340 | + /** |
|
1341 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1342 | + * getMemCacheFactory() instead. |
|
1343 | + * |
|
1344 | + * @return \OCP\ICache |
|
1345 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1346 | + */ |
|
1347 | + public function getCache() { |
|
1348 | + return $this->query('UserCache'); |
|
1349 | + } |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * Returns an \OCP\CacheFactory instance |
|
1353 | + * |
|
1354 | + * @return \OCP\ICacheFactory |
|
1355 | + */ |
|
1356 | + public function getMemCacheFactory() { |
|
1357 | + return $this->query('MemCacheFactory'); |
|
1358 | + } |
|
1359 | + |
|
1360 | + /** |
|
1361 | + * Returns an \OC\RedisFactory instance |
|
1362 | + * |
|
1363 | + * @return \OC\RedisFactory |
|
1364 | + */ |
|
1365 | + public function getGetRedisFactory() { |
|
1366 | + return $this->query('RedisFactory'); |
|
1367 | + } |
|
1368 | + |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * Returns the current session |
|
1372 | + * |
|
1373 | + * @return \OCP\IDBConnection |
|
1374 | + */ |
|
1375 | + public function getDatabaseConnection() { |
|
1376 | + return $this->query('DatabaseConnection'); |
|
1377 | + } |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * Returns the activity manager |
|
1381 | + * |
|
1382 | + * @return \OCP\Activity\IManager |
|
1383 | + */ |
|
1384 | + public function getActivityManager() { |
|
1385 | + return $this->query('ActivityManager'); |
|
1386 | + } |
|
1387 | + |
|
1388 | + /** |
|
1389 | + * Returns an job list for controlling background jobs |
|
1390 | + * |
|
1391 | + * @return \OCP\BackgroundJob\IJobList |
|
1392 | + */ |
|
1393 | + public function getJobList() { |
|
1394 | + return $this->query('JobList'); |
|
1395 | + } |
|
1396 | + |
|
1397 | + /** |
|
1398 | + * Returns a logger instance |
|
1399 | + * |
|
1400 | + * @return \OCP\ILogger |
|
1401 | + */ |
|
1402 | + public function getLogger() { |
|
1403 | + return $this->query('Logger'); |
|
1404 | + } |
|
1405 | + |
|
1406 | + /** |
|
1407 | + * Returns a router for generating and matching urls |
|
1408 | + * |
|
1409 | + * @return \OCP\Route\IRouter |
|
1410 | + */ |
|
1411 | + public function getRouter() { |
|
1412 | + return $this->query('Router'); |
|
1413 | + } |
|
1414 | + |
|
1415 | + /** |
|
1416 | + * Returns a search instance |
|
1417 | + * |
|
1418 | + * @return \OCP\ISearch |
|
1419 | + */ |
|
1420 | + public function getSearch() { |
|
1421 | + return $this->query('Search'); |
|
1422 | + } |
|
1423 | + |
|
1424 | + /** |
|
1425 | + * Returns a SecureRandom instance |
|
1426 | + * |
|
1427 | + * @return \OCP\Security\ISecureRandom |
|
1428 | + */ |
|
1429 | + public function getSecureRandom() { |
|
1430 | + return $this->query('SecureRandom'); |
|
1431 | + } |
|
1432 | + |
|
1433 | + /** |
|
1434 | + * Returns a Crypto instance |
|
1435 | + * |
|
1436 | + * @return \OCP\Security\ICrypto |
|
1437 | + */ |
|
1438 | + public function getCrypto() { |
|
1439 | + return $this->query('Crypto'); |
|
1440 | + } |
|
1441 | + |
|
1442 | + /** |
|
1443 | + * Returns a Hasher instance |
|
1444 | + * |
|
1445 | + * @return \OCP\Security\IHasher |
|
1446 | + */ |
|
1447 | + public function getHasher() { |
|
1448 | + return $this->query('Hasher'); |
|
1449 | + } |
|
1450 | + |
|
1451 | + /** |
|
1452 | + * Returns a CredentialsManager instance |
|
1453 | + * |
|
1454 | + * @return \OCP\Security\ICredentialsManager |
|
1455 | + */ |
|
1456 | + public function getCredentialsManager() { |
|
1457 | + return $this->query('CredentialsManager'); |
|
1458 | + } |
|
1459 | + |
|
1460 | + /** |
|
1461 | + * Returns an instance of the HTTP helper class |
|
1462 | + * |
|
1463 | + * @deprecated Use getHTTPClientService() |
|
1464 | + * @return \OC\HTTPHelper |
|
1465 | + */ |
|
1466 | + public function getHTTPHelper() { |
|
1467 | + return $this->query('HTTPHelper'); |
|
1468 | + } |
|
1469 | + |
|
1470 | + /** |
|
1471 | + * Get the certificate manager for the user |
|
1472 | + * |
|
1473 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1474 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1475 | + */ |
|
1476 | + public function getCertificateManager($userId = '') { |
|
1477 | + if ($userId === '') { |
|
1478 | + $userSession = $this->getUserSession(); |
|
1479 | + $user = $userSession->getUser(); |
|
1480 | + if (is_null($user)) { |
|
1481 | + return null; |
|
1482 | + } |
|
1483 | + $userId = $user->getUID(); |
|
1484 | + } |
|
1485 | + return new CertificateManager( |
|
1486 | + $userId, |
|
1487 | + new View(), |
|
1488 | + $this->getConfig(), |
|
1489 | + $this->getLogger(), |
|
1490 | + $this->getSecureRandom() |
|
1491 | + ); |
|
1492 | + } |
|
1493 | + |
|
1494 | + /** |
|
1495 | + * Returns an instance of the HTTP client service |
|
1496 | + * |
|
1497 | + * @return \OCP\Http\Client\IClientService |
|
1498 | + */ |
|
1499 | + public function getHTTPClientService() { |
|
1500 | + return $this->query('HttpClientService'); |
|
1501 | + } |
|
1502 | + |
|
1503 | + /** |
|
1504 | + * Create a new event source |
|
1505 | + * |
|
1506 | + * @return \OCP\IEventSource |
|
1507 | + */ |
|
1508 | + public function createEventSource() { |
|
1509 | + return new \OC_EventSource(); |
|
1510 | + } |
|
1511 | + |
|
1512 | + /** |
|
1513 | + * Get the active event logger |
|
1514 | + * |
|
1515 | + * The returned logger only logs data when debug mode is enabled |
|
1516 | + * |
|
1517 | + * @return \OCP\Diagnostics\IEventLogger |
|
1518 | + */ |
|
1519 | + public function getEventLogger() { |
|
1520 | + return $this->query('EventLogger'); |
|
1521 | + } |
|
1522 | + |
|
1523 | + /** |
|
1524 | + * Get the active query logger |
|
1525 | + * |
|
1526 | + * The returned logger only logs data when debug mode is enabled |
|
1527 | + * |
|
1528 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1529 | + */ |
|
1530 | + public function getQueryLogger() { |
|
1531 | + return $this->query('QueryLogger'); |
|
1532 | + } |
|
1533 | + |
|
1534 | + /** |
|
1535 | + * Get the manager for temporary files and folders |
|
1536 | + * |
|
1537 | + * @return \OCP\ITempManager |
|
1538 | + */ |
|
1539 | + public function getTempManager() { |
|
1540 | + return $this->query('TempManager'); |
|
1541 | + } |
|
1542 | + |
|
1543 | + /** |
|
1544 | + * Get the app manager |
|
1545 | + * |
|
1546 | + * @return \OCP\App\IAppManager |
|
1547 | + */ |
|
1548 | + public function getAppManager() { |
|
1549 | + return $this->query('AppManager'); |
|
1550 | + } |
|
1551 | + |
|
1552 | + /** |
|
1553 | + * Creates a new mailer |
|
1554 | + * |
|
1555 | + * @return \OCP\Mail\IMailer |
|
1556 | + */ |
|
1557 | + public function getMailer() { |
|
1558 | + return $this->query('Mailer'); |
|
1559 | + } |
|
1560 | + |
|
1561 | + /** |
|
1562 | + * Get the webroot |
|
1563 | + * |
|
1564 | + * @return string |
|
1565 | + */ |
|
1566 | + public function getWebRoot() { |
|
1567 | + return $this->webRoot; |
|
1568 | + } |
|
1569 | + |
|
1570 | + /** |
|
1571 | + * @return \OC\OCSClient |
|
1572 | + */ |
|
1573 | + public function getOcsClient() { |
|
1574 | + return $this->query('OcsClient'); |
|
1575 | + } |
|
1576 | + |
|
1577 | + /** |
|
1578 | + * @return \OCP\IDateTimeZone |
|
1579 | + */ |
|
1580 | + public function getDateTimeZone() { |
|
1581 | + return $this->query('DateTimeZone'); |
|
1582 | + } |
|
1583 | + |
|
1584 | + /** |
|
1585 | + * @return \OCP\IDateTimeFormatter |
|
1586 | + */ |
|
1587 | + public function getDateTimeFormatter() { |
|
1588 | + return $this->query('DateTimeFormatter'); |
|
1589 | + } |
|
1590 | + |
|
1591 | + /** |
|
1592 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1593 | + */ |
|
1594 | + public function getMountProviderCollection() { |
|
1595 | + return $this->query('MountConfigManager'); |
|
1596 | + } |
|
1597 | + |
|
1598 | + /** |
|
1599 | + * Get the IniWrapper |
|
1600 | + * |
|
1601 | + * @return IniGetWrapper |
|
1602 | + */ |
|
1603 | + public function getIniWrapper() { |
|
1604 | + return $this->query('IniWrapper'); |
|
1605 | + } |
|
1606 | + |
|
1607 | + /** |
|
1608 | + * @return \OCP\Command\IBus |
|
1609 | + */ |
|
1610 | + public function getCommandBus() { |
|
1611 | + return $this->query('AsyncCommandBus'); |
|
1612 | + } |
|
1613 | + |
|
1614 | + /** |
|
1615 | + * Get the trusted domain helper |
|
1616 | + * |
|
1617 | + * @return TrustedDomainHelper |
|
1618 | + */ |
|
1619 | + public function getTrustedDomainHelper() { |
|
1620 | + return $this->query('TrustedDomainHelper'); |
|
1621 | + } |
|
1622 | + |
|
1623 | + /** |
|
1624 | + * Get the locking provider |
|
1625 | + * |
|
1626 | + * @return \OCP\Lock\ILockingProvider |
|
1627 | + * @since 8.1.0 |
|
1628 | + */ |
|
1629 | + public function getLockingProvider() { |
|
1630 | + return $this->query('LockingProvider'); |
|
1631 | + } |
|
1632 | + |
|
1633 | + /** |
|
1634 | + * @return \OCP\Files\Mount\IMountManager |
|
1635 | + **/ |
|
1636 | + function getMountManager() { |
|
1637 | + return $this->query('MountManager'); |
|
1638 | + } |
|
1639 | + |
|
1640 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1641 | + function getUserMountCache() { |
|
1642 | + return $this->query('UserMountCache'); |
|
1643 | + } |
|
1644 | + |
|
1645 | + /** |
|
1646 | + * Get the MimeTypeDetector |
|
1647 | + * |
|
1648 | + * @return \OCP\Files\IMimeTypeDetector |
|
1649 | + */ |
|
1650 | + public function getMimeTypeDetector() { |
|
1651 | + return $this->query('MimeTypeDetector'); |
|
1652 | + } |
|
1653 | + |
|
1654 | + /** |
|
1655 | + * Get the MimeTypeLoader |
|
1656 | + * |
|
1657 | + * @return \OCP\Files\IMimeTypeLoader |
|
1658 | + */ |
|
1659 | + public function getMimeTypeLoader() { |
|
1660 | + return $this->query('MimeTypeLoader'); |
|
1661 | + } |
|
1662 | + |
|
1663 | + /** |
|
1664 | + * Get the manager of all the capabilities |
|
1665 | + * |
|
1666 | + * @return \OC\CapabilitiesManager |
|
1667 | + */ |
|
1668 | + public function getCapabilitiesManager() { |
|
1669 | + return $this->query('CapabilitiesManager'); |
|
1670 | + } |
|
1671 | + |
|
1672 | + /** |
|
1673 | + * Get the EventDispatcher |
|
1674 | + * |
|
1675 | + * @return EventDispatcherInterface |
|
1676 | + * @since 8.2.0 |
|
1677 | + */ |
|
1678 | + public function getEventDispatcher() { |
|
1679 | + return $this->query('EventDispatcher'); |
|
1680 | + } |
|
1681 | + |
|
1682 | + /** |
|
1683 | + * Get the Notification Manager |
|
1684 | + * |
|
1685 | + * @return \OCP\Notification\IManager |
|
1686 | + * @since 8.2.0 |
|
1687 | + */ |
|
1688 | + public function getNotificationManager() { |
|
1689 | + return $this->query('NotificationManager'); |
|
1690 | + } |
|
1691 | + |
|
1692 | + /** |
|
1693 | + * @return \OCP\Comments\ICommentsManager |
|
1694 | + */ |
|
1695 | + public function getCommentsManager() { |
|
1696 | + return $this->query('CommentsManager'); |
|
1697 | + } |
|
1698 | + |
|
1699 | + /** |
|
1700 | + * @return \OCA\Theming\ThemingDefaults |
|
1701 | + */ |
|
1702 | + public function getThemingDefaults() { |
|
1703 | + return $this->query('ThemingDefaults'); |
|
1704 | + } |
|
1705 | + |
|
1706 | + /** |
|
1707 | + * @return \OC\IntegrityCheck\Checker |
|
1708 | + */ |
|
1709 | + public function getIntegrityCodeChecker() { |
|
1710 | + return $this->query('IntegrityCodeChecker'); |
|
1711 | + } |
|
1712 | + |
|
1713 | + /** |
|
1714 | + * @return \OC\Session\CryptoWrapper |
|
1715 | + */ |
|
1716 | + public function getSessionCryptoWrapper() { |
|
1717 | + return $this->query('CryptoWrapper'); |
|
1718 | + } |
|
1719 | + |
|
1720 | + /** |
|
1721 | + * @return CsrfTokenManager |
|
1722 | + */ |
|
1723 | + public function getCsrfTokenManager() { |
|
1724 | + return $this->query('CsrfTokenManager'); |
|
1725 | + } |
|
1726 | + |
|
1727 | + /** |
|
1728 | + * @return Throttler |
|
1729 | + */ |
|
1730 | + public function getBruteForceThrottler() { |
|
1731 | + return $this->query('Throttler'); |
|
1732 | + } |
|
1733 | + |
|
1734 | + /** |
|
1735 | + * @return IContentSecurityPolicyManager |
|
1736 | + */ |
|
1737 | + public function getContentSecurityPolicyManager() { |
|
1738 | + return $this->query('ContentSecurityPolicyManager'); |
|
1739 | + } |
|
1740 | + |
|
1741 | + /** |
|
1742 | + * @return ContentSecurityPolicyNonceManager |
|
1743 | + */ |
|
1744 | + public function getContentSecurityPolicyNonceManager() { |
|
1745 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1746 | + } |
|
1747 | + |
|
1748 | + /** |
|
1749 | + * Not a public API as of 8.2, wait for 9.0 |
|
1750 | + * |
|
1751 | + * @return \OCA\Files_External\Service\BackendService |
|
1752 | + */ |
|
1753 | + public function getStoragesBackendService() { |
|
1754 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1755 | + } |
|
1756 | + |
|
1757 | + /** |
|
1758 | + * Not a public API as of 8.2, wait for 9.0 |
|
1759 | + * |
|
1760 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1761 | + */ |
|
1762 | + public function getGlobalStoragesService() { |
|
1763 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1764 | + } |
|
1765 | + |
|
1766 | + /** |
|
1767 | + * Not a public API as of 8.2, wait for 9.0 |
|
1768 | + * |
|
1769 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1770 | + */ |
|
1771 | + public function getUserGlobalStoragesService() { |
|
1772 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1773 | + } |
|
1774 | + |
|
1775 | + /** |
|
1776 | + * Not a public API as of 8.2, wait for 9.0 |
|
1777 | + * |
|
1778 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1779 | + */ |
|
1780 | + public function getUserStoragesService() { |
|
1781 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1782 | + } |
|
1783 | + |
|
1784 | + /** |
|
1785 | + * @return \OCP\Share\IManager |
|
1786 | + */ |
|
1787 | + public function getShareManager() { |
|
1788 | + return $this->query('ShareManager'); |
|
1789 | + } |
|
1790 | + |
|
1791 | + /** |
|
1792 | + * Returns the LDAP Provider |
|
1793 | + * |
|
1794 | + * @return \OCP\LDAP\ILDAPProvider |
|
1795 | + */ |
|
1796 | + public function getLDAPProvider() { |
|
1797 | + return $this->query('LDAPProvider'); |
|
1798 | + } |
|
1799 | + |
|
1800 | + /** |
|
1801 | + * @return \OCP\Settings\IManager |
|
1802 | + */ |
|
1803 | + public function getSettingsManager() { |
|
1804 | + return $this->query('SettingsManager'); |
|
1805 | + } |
|
1806 | + |
|
1807 | + /** |
|
1808 | + * @return \OCP\Files\IAppData |
|
1809 | + */ |
|
1810 | + public function getAppDataDir($app) { |
|
1811 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1812 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1813 | + return $factory->get($app); |
|
1814 | + } |
|
1815 | + |
|
1816 | + /** |
|
1817 | + * @return \OCP\Lockdown\ILockdownManager |
|
1818 | + */ |
|
1819 | + public function getLockdownManager() { |
|
1820 | + return $this->query('LockdownManager'); |
|
1821 | + } |
|
1822 | + |
|
1823 | + /** |
|
1824 | + * @return \OCP\Federation\ICloudIdManager |
|
1825 | + */ |
|
1826 | + public function getCloudIdManager() { |
|
1827 | + return $this->query(ICloudIdManager::class); |
|
1828 | + } |
|
1829 | 1829 | } |
@@ -40,166 +40,166 @@ |
||
40 | 40 | |
41 | 41 | class Application extends App { |
42 | 42 | |
43 | - /** |
|
44 | - * Application constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - parent::__construct('dav'); |
|
48 | - |
|
49 | - $container = $this->getContainer(); |
|
50 | - $server = $container->getServer(); |
|
51 | - |
|
52 | - $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
53 | - return new PhotoCache( |
|
54 | - $server->getAppDataDir('dav-photocache') |
|
55 | - ); |
|
56 | - }); |
|
57 | - |
|
58 | - /* |
|
43 | + /** |
|
44 | + * Application constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + parent::__construct('dav'); |
|
48 | + |
|
49 | + $container = $this->getContainer(); |
|
50 | + $server = $container->getServer(); |
|
51 | + |
|
52 | + $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
53 | + return new PhotoCache( |
|
54 | + $server->getAppDataDir('dav-photocache') |
|
55 | + ); |
|
56 | + }); |
|
57 | + |
|
58 | + /* |
|
59 | 59 | * Register capabilities |
60 | 60 | */ |
61 | - $container->registerCapability(Capabilities::class); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IManager $contactsManager |
|
66 | - * @param string $userID |
|
67 | - */ |
|
68 | - public function setupContactsProvider(IManager $contactsManager, $userID) { |
|
69 | - /** @var ContactsManager $cm */ |
|
70 | - $cm = $this->getContainer()->query(ContactsManager::class); |
|
71 | - $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
72 | - $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param IManager $contactsManager |
|
77 | - */ |
|
78 | - public function setupSystemContactsProvider(IManager $contactsManager) { |
|
79 | - /** @var ContactsManager $cm */ |
|
80 | - $cm = $this->getContainer()->query(ContactsManager::class); |
|
81 | - $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
82 | - $cm->setupSystemContactsProvider($contactsManager, $urlGenerator); |
|
83 | - } |
|
84 | - |
|
85 | - public function registerHooks() { |
|
86 | - /** @var HookManager $hm */ |
|
87 | - $hm = $this->getContainer()->query(HookManager::class); |
|
88 | - $hm->setup(); |
|
89 | - |
|
90 | - $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
91 | - |
|
92 | - // first time login event setup |
|
93 | - $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
94 | - if ($event instanceof GenericEvent) { |
|
95 | - $hm->firstLogin($event->getSubject()); |
|
96 | - } |
|
97 | - }); |
|
98 | - |
|
99 | - // carddav/caldav sync event setup |
|
100 | - $listener = function($event) { |
|
101 | - if ($event instanceof GenericEvent) { |
|
102 | - /** @var BirthdayService $b */ |
|
103 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
104 | - $b->onCardChanged( |
|
105 | - $event->getArgument('addressBookId'), |
|
106 | - $event->getArgument('cardUri'), |
|
107 | - $event->getArgument('cardData') |
|
108 | - ); |
|
109 | - } |
|
110 | - }; |
|
111 | - |
|
112 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
113 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
114 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
115 | - if ($event instanceof GenericEvent) { |
|
116 | - /** @var BirthdayService $b */ |
|
117 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
118 | - $b->onCardDeleted( |
|
119 | - $event->getArgument('addressBookId'), |
|
120 | - $event->getArgument('cardUri') |
|
121 | - ); |
|
122 | - } |
|
123 | - }); |
|
124 | - |
|
125 | - $clearPhotoCache = function($event) { |
|
126 | - if ($event instanceof GenericEvent) { |
|
127 | - /** @var PhotoCache $p */ |
|
128 | - $p = $this->getContainer()->query(PhotoCache::class); |
|
129 | - $p->delete( |
|
130 | - $event->getArgument('addressBookId'), |
|
131 | - $event->getArgument('cardUri') |
|
132 | - ); |
|
133 | - } |
|
134 | - }; |
|
135 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
136 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
137 | - |
|
138 | - $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
139 | - $user = $event->getSubject(); |
|
140 | - $syncService = $this->getContainer()->query(SyncService::class); |
|
141 | - $syncService->updateUser($user); |
|
142 | - }); |
|
143 | - |
|
144 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
145 | - /** @var Backend $backend */ |
|
146 | - $backend = $this->getContainer()->query(Backend::class); |
|
147 | - $backend->onCalendarAdd( |
|
148 | - $event->getArgument('calendarData') |
|
149 | - ); |
|
150 | - }); |
|
151 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
152 | - /** @var Backend $backend */ |
|
153 | - $backend = $this->getContainer()->query(Backend::class); |
|
154 | - $backend->onCalendarUpdate( |
|
155 | - $event->getArgument('calendarData'), |
|
156 | - $event->getArgument('shares'), |
|
157 | - $event->getArgument('propertyMutations') |
|
158 | - ); |
|
159 | - }); |
|
160 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
161 | - /** @var Backend $backend */ |
|
162 | - $backend = $this->getContainer()->query(Backend::class); |
|
163 | - $backend->onCalendarDelete( |
|
164 | - $event->getArgument('calendarData'), |
|
165 | - $event->getArgument('shares') |
|
166 | - ); |
|
167 | - }); |
|
168 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
169 | - /** @var Backend $backend */ |
|
170 | - $backend = $this->getContainer()->query(Backend::class); |
|
171 | - $backend->onCalendarUpdateShares( |
|
172 | - $event->getArgument('calendarData'), |
|
173 | - $event->getArgument('shares'), |
|
174 | - $event->getArgument('add'), |
|
175 | - $event->getArgument('remove') |
|
176 | - ); |
|
177 | - }); |
|
178 | - |
|
179 | - $listener = function(GenericEvent $event, $eventName) { |
|
180 | - /** @var Backend $backend */ |
|
181 | - $backend = $this->getContainer()->query(Backend::class); |
|
182 | - |
|
183 | - $subject = Event::SUBJECT_OBJECT_ADD; |
|
184 | - if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
185 | - $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
186 | - } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
187 | - $subject = Event::SUBJECT_OBJECT_DELETE; |
|
188 | - } |
|
189 | - $backend->onTouchCalendarObject( |
|
190 | - $subject, |
|
191 | - $event->getArgument('calendarData'), |
|
192 | - $event->getArgument('shares'), |
|
193 | - $event->getArgument('objectData') |
|
194 | - ); |
|
195 | - }; |
|
196 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
197 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
198 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
199 | - } |
|
200 | - |
|
201 | - public function getSyncService() { |
|
202 | - return $this->getContainer()->query(SyncService::class); |
|
203 | - } |
|
61 | + $container->registerCapability(Capabilities::class); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IManager $contactsManager |
|
66 | + * @param string $userID |
|
67 | + */ |
|
68 | + public function setupContactsProvider(IManager $contactsManager, $userID) { |
|
69 | + /** @var ContactsManager $cm */ |
|
70 | + $cm = $this->getContainer()->query(ContactsManager::class); |
|
71 | + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
72 | + $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param IManager $contactsManager |
|
77 | + */ |
|
78 | + public function setupSystemContactsProvider(IManager $contactsManager) { |
|
79 | + /** @var ContactsManager $cm */ |
|
80 | + $cm = $this->getContainer()->query(ContactsManager::class); |
|
81 | + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
82 | + $cm->setupSystemContactsProvider($contactsManager, $urlGenerator); |
|
83 | + } |
|
84 | + |
|
85 | + public function registerHooks() { |
|
86 | + /** @var HookManager $hm */ |
|
87 | + $hm = $this->getContainer()->query(HookManager::class); |
|
88 | + $hm->setup(); |
|
89 | + |
|
90 | + $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
91 | + |
|
92 | + // first time login event setup |
|
93 | + $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
94 | + if ($event instanceof GenericEvent) { |
|
95 | + $hm->firstLogin($event->getSubject()); |
|
96 | + } |
|
97 | + }); |
|
98 | + |
|
99 | + // carddav/caldav sync event setup |
|
100 | + $listener = function($event) { |
|
101 | + if ($event instanceof GenericEvent) { |
|
102 | + /** @var BirthdayService $b */ |
|
103 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
104 | + $b->onCardChanged( |
|
105 | + $event->getArgument('addressBookId'), |
|
106 | + $event->getArgument('cardUri'), |
|
107 | + $event->getArgument('cardData') |
|
108 | + ); |
|
109 | + } |
|
110 | + }; |
|
111 | + |
|
112 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
113 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
114 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
115 | + if ($event instanceof GenericEvent) { |
|
116 | + /** @var BirthdayService $b */ |
|
117 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
118 | + $b->onCardDeleted( |
|
119 | + $event->getArgument('addressBookId'), |
|
120 | + $event->getArgument('cardUri') |
|
121 | + ); |
|
122 | + } |
|
123 | + }); |
|
124 | + |
|
125 | + $clearPhotoCache = function($event) { |
|
126 | + if ($event instanceof GenericEvent) { |
|
127 | + /** @var PhotoCache $p */ |
|
128 | + $p = $this->getContainer()->query(PhotoCache::class); |
|
129 | + $p->delete( |
|
130 | + $event->getArgument('addressBookId'), |
|
131 | + $event->getArgument('cardUri') |
|
132 | + ); |
|
133 | + } |
|
134 | + }; |
|
135 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
136 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
137 | + |
|
138 | + $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
139 | + $user = $event->getSubject(); |
|
140 | + $syncService = $this->getContainer()->query(SyncService::class); |
|
141 | + $syncService->updateUser($user); |
|
142 | + }); |
|
143 | + |
|
144 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
145 | + /** @var Backend $backend */ |
|
146 | + $backend = $this->getContainer()->query(Backend::class); |
|
147 | + $backend->onCalendarAdd( |
|
148 | + $event->getArgument('calendarData') |
|
149 | + ); |
|
150 | + }); |
|
151 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
152 | + /** @var Backend $backend */ |
|
153 | + $backend = $this->getContainer()->query(Backend::class); |
|
154 | + $backend->onCalendarUpdate( |
|
155 | + $event->getArgument('calendarData'), |
|
156 | + $event->getArgument('shares'), |
|
157 | + $event->getArgument('propertyMutations') |
|
158 | + ); |
|
159 | + }); |
|
160 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
161 | + /** @var Backend $backend */ |
|
162 | + $backend = $this->getContainer()->query(Backend::class); |
|
163 | + $backend->onCalendarDelete( |
|
164 | + $event->getArgument('calendarData'), |
|
165 | + $event->getArgument('shares') |
|
166 | + ); |
|
167 | + }); |
|
168 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
169 | + /** @var Backend $backend */ |
|
170 | + $backend = $this->getContainer()->query(Backend::class); |
|
171 | + $backend->onCalendarUpdateShares( |
|
172 | + $event->getArgument('calendarData'), |
|
173 | + $event->getArgument('shares'), |
|
174 | + $event->getArgument('add'), |
|
175 | + $event->getArgument('remove') |
|
176 | + ); |
|
177 | + }); |
|
178 | + |
|
179 | + $listener = function(GenericEvent $event, $eventName) { |
|
180 | + /** @var Backend $backend */ |
|
181 | + $backend = $this->getContainer()->query(Backend::class); |
|
182 | + |
|
183 | + $subject = Event::SUBJECT_OBJECT_ADD; |
|
184 | + if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
185 | + $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
186 | + } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
187 | + $subject = Event::SUBJECT_OBJECT_DELETE; |
|
188 | + } |
|
189 | + $backend->onTouchCalendarObject( |
|
190 | + $subject, |
|
191 | + $event->getArgument('calendarData'), |
|
192 | + $event->getArgument('shares'), |
|
193 | + $event->getArgument('objectData') |
|
194 | + ); |
|
195 | + }; |
|
196 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
197 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
198 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
199 | + } |
|
200 | + |
|
201 | + public function getSyncService() { |
|
202 | + return $this->getContainer()->query(SyncService::class); |
|
203 | + } |
|
204 | 204 | |
205 | 205 | } |
@@ -29,60 +29,60 @@ |
||
29 | 29 | use OCP\IURLGenerator; |
30 | 30 | |
31 | 31 | class ContactsManager { |
32 | - /** @var CardDavBackend */ |
|
33 | - private $backend; |
|
32 | + /** @var CardDavBackend */ |
|
33 | + private $backend; |
|
34 | 34 | |
35 | - /** @var IL10N */ |
|
36 | - private $l10n; |
|
35 | + /** @var IL10N */ |
|
36 | + private $l10n; |
|
37 | 37 | |
38 | - /** |
|
39 | - * ContactsManager constructor. |
|
40 | - * |
|
41 | - * @param CardDavBackend $backend |
|
42 | - * @param IL10N $l10n |
|
43 | - */ |
|
44 | - public function __construct(CardDavBackend $backend, IL10N $l10n) { |
|
45 | - $this->backend = $backend; |
|
46 | - $this->l10n = $l10n; |
|
47 | - } |
|
38 | + /** |
|
39 | + * ContactsManager constructor. |
|
40 | + * |
|
41 | + * @param CardDavBackend $backend |
|
42 | + * @param IL10N $l10n |
|
43 | + */ |
|
44 | + public function __construct(CardDavBackend $backend, IL10N $l10n) { |
|
45 | + $this->backend = $backend; |
|
46 | + $this->l10n = $l10n; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param IManager $cm |
|
51 | - * @param string $userId |
|
52 | - * @param IURLGenerator $urlGenerator |
|
53 | - */ |
|
54 | - public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) { |
|
55 | - $addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId"); |
|
56 | - $this->register($cm, $addressBooks, $urlGenerator); |
|
57 | - $this->setupSystemContactsProvider($cm, $urlGenerator); |
|
58 | - } |
|
49 | + /** |
|
50 | + * @param IManager $cm |
|
51 | + * @param string $userId |
|
52 | + * @param IURLGenerator $urlGenerator |
|
53 | + */ |
|
54 | + public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) { |
|
55 | + $addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId"); |
|
56 | + $this->register($cm, $addressBooks, $urlGenerator); |
|
57 | + $this->setupSystemContactsProvider($cm, $urlGenerator); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param IManager $cm |
|
62 | - * @param IURLGenerator $urlGenerator |
|
63 | - */ |
|
64 | - public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) { |
|
65 | - $addressBooks = $this->backend->getAddressBooksForUser("principals/system/system"); |
|
66 | - $this->register($cm, $addressBooks, $urlGenerator); |
|
67 | - } |
|
60 | + /** |
|
61 | + * @param IManager $cm |
|
62 | + * @param IURLGenerator $urlGenerator |
|
63 | + */ |
|
64 | + public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) { |
|
65 | + $addressBooks = $this->backend->getAddressBooksForUser("principals/system/system"); |
|
66 | + $this->register($cm, $addressBooks, $urlGenerator); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param IManager $cm |
|
71 | - * @param $addressBooks |
|
72 | - * @param IURLGenerator $urlGenerator |
|
73 | - */ |
|
74 | - private function register(IManager $cm, $addressBooks, $urlGenerator) { |
|
75 | - foreach ($addressBooks as $addressBookInfo) { |
|
76 | - $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo, $this->l10n); |
|
77 | - $cm->registerAddressBook( |
|
78 | - new AddressBookImpl( |
|
79 | - $addressBook, |
|
80 | - $addressBookInfo, |
|
81 | - $this->backend, |
|
82 | - $urlGenerator |
|
83 | - ) |
|
84 | - ); |
|
85 | - } |
|
86 | - } |
|
69 | + /** |
|
70 | + * @param IManager $cm |
|
71 | + * @param $addressBooks |
|
72 | + * @param IURLGenerator $urlGenerator |
|
73 | + */ |
|
74 | + private function register(IManager $cm, $addressBooks, $urlGenerator) { |
|
75 | + foreach ($addressBooks as $addressBookInfo) { |
|
76 | + $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo, $this->l10n); |
|
77 | + $cm->registerAddressBook( |
|
78 | + new AddressBookImpl( |
|
79 | + $addressBook, |
|
80 | + $addressBookInfo, |
|
81 | + $this->backend, |
|
82 | + $urlGenerator |
|
83 | + ) |
|
84 | + ); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -30,29 +30,29 @@ |
||
30 | 30 | $app->registerHooks(); |
31 | 31 | |
32 | 32 | \OC::$server->registerService('CardDAVSyncService', function() use ($app) { |
33 | - return $app->getSyncService(); |
|
33 | + return $app->getSyncService(); |
|
34 | 34 | }); |
35 | 35 | |
36 | 36 | $eventDispatcher = \OC::$server->getEventDispatcher(); |
37 | 37 | |
38 | 38 | $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove', |
39 | - function(GenericEvent $event) use ($app) { |
|
40 | - /** @var CardDavBackend $cardDavBackend */ |
|
41 | - $cardDavBackend = $app->getContainer()->query(CardDavBackend::class); |
|
42 | - $addressBookUri = $event->getSubject(); |
|
43 | - $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri); |
|
44 | - if (!is_null($addressBook)) { |
|
45 | - $cardDavBackend->deleteAddressBook($addressBook['id']); |
|
46 | - } |
|
47 | - } |
|
39 | + function(GenericEvent $event) use ($app) { |
|
40 | + /** @var CardDavBackend $cardDavBackend */ |
|
41 | + $cardDavBackend = $app->getContainer()->query(CardDavBackend::class); |
|
42 | + $addressBookUri = $event->getSubject(); |
|
43 | + $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri); |
|
44 | + if (!is_null($addressBook)) { |
|
45 | + $cardDavBackend->deleteAddressBook($addressBook['id']); |
|
46 | + } |
|
47 | + } |
|
48 | 48 | ); |
49 | 49 | |
50 | 50 | $cm = \OC::$server->getContactsManager(); |
51 | 51 | $cm->register(function() use ($cm, $app) { |
52 | - $user = \OC::$server->getUserSession()->getUser(); |
|
53 | - if (!is_null($user)) { |
|
54 | - $app->setupContactsProvider($cm, $user->getUID()); |
|
55 | - } else { |
|
56 | - $app->setupSystemContactsProvider($cm); |
|
57 | - } |
|
52 | + $user = \OC::$server->getUserSession()->getUser(); |
|
53 | + if (!is_null($user)) { |
|
54 | + $app->setupContactsProvider($cm, $user->getUID()); |
|
55 | + } else { |
|
56 | + $app->setupSystemContactsProvider($cm); |
|
57 | + } |
|
58 | 58 | }); |
@@ -10,22 +10,22 @@ |
||
10 | 10 | interface IContactsStore { |
11 | 11 | |
12 | 12 | |
13 | - /** |
|
14 | - * @param IUser $user |
|
15 | - * @param $filter |
|
16 | - * @return IEntry[] |
|
17 | - * @since 13.0.0 |
|
18 | - */ |
|
19 | - public function getContacts(IUser $user, $filter); |
|
13 | + /** |
|
14 | + * @param IUser $user |
|
15 | + * @param $filter |
|
16 | + * @return IEntry[] |
|
17 | + * @since 13.0.0 |
|
18 | + */ |
|
19 | + public function getContacts(IUser $user, $filter); |
|
20 | 20 | |
21 | - /** |
|
22 | - * @brief finds a contact by specifying the property to search on ($shareType) and the value ($shareWith) |
|
23 | - * @param IUser $user |
|
24 | - * @param integer $shareType |
|
25 | - * @param string $shareWith |
|
26 | - * @return IEntry|null |
|
27 | - * @since 13.0.0 |
|
28 | - */ |
|
29 | - public function findOne(IUser $user, $shareType, $shareWith); |
|
21 | + /** |
|
22 | + * @brief finds a contact by specifying the property to search on ($shareType) and the value ($shareWith) |
|
23 | + * @param IUser $user |
|
24 | + * @param integer $shareType |
|
25 | + * @param string $shareWith |
|
26 | + * @return IEntry|null |
|
27 | + * @since 13.0.0 |
|
28 | + */ |
|
29 | + public function findOne(IUser $user, $shareType, $shareWith); |
|
30 | 30 | |
31 | 31 | } |