| @@ -40,354 +40,354 @@ | ||
| 40 | 40 | use OCP\RichObjectStrings\IValidator; | 
| 41 | 41 | |
| 42 | 42 |  class Manager implements IManager { | 
| 43 | - /** @var IValidator */ | |
| 44 | - protected $validator; | |
| 45 | - /** @var ILogger */ | |
| 46 | - protected $logger; | |
| 47 | - /** @var Coordinator */ | |
| 48 | - private $coordinator; | |
| 49 | - | |
| 50 | - /** @var IApp[] */ | |
| 51 | - protected $apps; | |
| 52 | - /** @var string[] */ | |
| 53 | - protected $appClasses; | |
| 54 | - | |
| 55 | - /** @var INotifier[] */ | |
| 56 | - protected $notifiers; | |
| 57 | - /** @var string[] */ | |
| 58 | - protected $notifierClasses; | |
| 59 | - | |
| 60 | - /** @var bool */ | |
| 61 | - protected $preparingPushNotification; | |
| 62 | - /** @var bool */ | |
| 63 | - protected $deferPushing; | |
| 64 | - /** @var bool */ | |
| 65 | - private $parsedRegistrationContext; | |
| 66 | - | |
| 67 | - public function __construct(IValidator $validator, | |
| 68 | - ILogger $logger, | |
| 69 | -								Coordinator $coordinator) { | |
| 70 | - $this->validator = $validator; | |
| 71 | - $this->logger = $logger; | |
| 72 | - $this->coordinator = $coordinator; | |
| 73 | - | |
| 74 | - $this->apps = []; | |
| 75 | - $this->notifiers = []; | |
| 76 | - $this->appClasses = []; | |
| 77 | - $this->notifierClasses = []; | |
| 78 | - $this->preparingPushNotification = false; | |
| 79 | - $this->deferPushing = false; | |
| 80 | - $this->parsedRegistrationContext = false; | |
| 81 | - } | |
| 82 | - /** | |
| 83 | - * @param string $appClass The service must implement IApp, otherwise a | |
| 84 | - * \InvalidArgumentException is thrown later | |
| 85 | - * @since 17.0.0 | |
| 86 | - */ | |
| 87 | -	public function registerApp(string $appClass): void { | |
| 88 | - $this->appClasses[] = $appClass; | |
| 89 | - } | |
| 90 | - | |
| 91 | - /** | |
| 92 | - * @param \Closure $service The service must implement INotifier, otherwise a | |
| 93 | - * \InvalidArgumentException is thrown later | |
| 94 | - * @param \Closure $info An array with the keys 'id' and 'name' containing | |
| 95 | - * the app id and the app name | |
| 96 | - * @deprecated 17.0.0 use registerNotifierService instead. | |
| 97 | - * @since 8.2.0 - Parameter $info was added in 9.0.0 | |
| 98 | - */ | |
| 99 | -	public function registerNotifier(\Closure $service, \Closure $info) { | |
| 100 | - $infoData = $info(); | |
| 101 | - $this->logger->logException(new \InvalidArgumentException( | |
| 102 | - 'Notifier ' . $infoData['name'] . ' (id: ' . $infoData['id'] . ') is not considered because it is using the old way to register.' | |
| 103 | - )); | |
| 104 | - } | |
| 105 | - | |
| 106 | - /** | |
| 107 | - * @param string $notifierService The service must implement INotifier, otherwise a | |
| 108 | - * \InvalidArgumentException is thrown later | |
| 109 | - * @since 17.0.0 | |
| 110 | - */ | |
| 111 | -	public function registerNotifierService(string $notifierService): void { | |
| 112 | - $this->notifierClasses[] = $notifierService; | |
| 113 | - } | |
| 114 | - | |
| 115 | - /** | |
| 116 | - * @return IApp[] | |
| 117 | - */ | |
| 118 | -	protected function getApps(): array { | |
| 119 | -		if (empty($this->appClasses)) { | |
| 120 | - return $this->apps; | |
| 121 | - } | |
| 122 | - | |
| 123 | -		foreach ($this->appClasses as $appClass) { | |
| 124 | -			try { | |
| 125 | - $app = \OC::$server->query($appClass); | |
| 126 | -			} catch (QueryException $e) { | |
| 127 | - $this->logger->logException($e, [ | |
| 128 | - 'message' => 'Failed to load notification app class: ' . $appClass, | |
| 129 | - 'app' => 'notifications', | |
| 130 | - ]); | |
| 131 | - continue; | |
| 132 | - } | |
| 133 | - | |
| 134 | -			if (!($app instanceof IApp)) { | |
| 135 | -				$this->logger->error('Notification app class ' . $appClass . ' is not implementing ' . IApp::class, [ | |
| 136 | - 'app' => 'notifications', | |
| 137 | - ]); | |
| 138 | - continue; | |
| 139 | - } | |
| 140 | - | |
| 141 | - $this->apps[] = $app; | |
| 142 | - } | |
| 143 | - | |
| 144 | - $this->appClasses = []; | |
| 145 | - | |
| 146 | - return $this->apps; | |
| 147 | - } | |
| 148 | - | |
| 149 | - /** | |
| 150 | - * @return INotifier[] | |
| 151 | - */ | |
| 152 | -	public function getNotifiers(): array { | |
| 153 | -		if (!$this->parsedRegistrationContext) { | |
| 154 | - $notifierServices = $this->coordinator->getRegistrationContext()->getNotifierServices(); | |
| 155 | -			foreach ($notifierServices as $notifierService) { | |
| 156 | -				try { | |
| 157 | - $notifier = \OC::$server->query($notifierService->getService()); | |
| 158 | -				} catch (QueryException $e) { | |
| 159 | - $this->logger->logException($e, [ | |
| 160 | - 'message' => 'Failed to load notification notifier class: ' . $notifierService->getService(), | |
| 161 | - 'app' => 'notifications', | |
| 162 | - ]); | |
| 163 | - continue; | |
| 164 | - } | |
| 165 | - | |
| 166 | -				if (!($notifier instanceof INotifier)) { | |
| 167 | -					$this->logger->error('Notification notifier class ' . $notifierService->getService() . ' is not implementing ' . INotifier::class, [ | |
| 168 | - 'app' => 'notifications', | |
| 169 | - ]); | |
| 170 | - continue; | |
| 171 | - } | |
| 172 | - | |
| 173 | - $this->notifiers[] = $notifier; | |
| 174 | - } | |
| 175 | - | |
| 176 | - $this->parsedRegistrationContext = true; | |
| 177 | - } | |
| 178 | - | |
| 179 | -		if (empty($this->notifierClasses)) { | |
| 180 | - return $this->notifiers; | |
| 181 | - } | |
| 182 | - | |
| 183 | -		foreach ($this->notifierClasses as $notifierClass) { | |
| 184 | -			try { | |
| 185 | - $notifier = \OC::$server->query($notifierClass); | |
| 186 | -			} catch (QueryException $e) { | |
| 187 | - $this->logger->logException($e, [ | |
| 188 | - 'message' => 'Failed to load notification notifier class: ' . $notifierClass, | |
| 189 | - 'app' => 'notifications', | |
| 190 | - ]); | |
| 191 | - continue; | |
| 192 | - } | |
| 193 | - | |
| 194 | -			if (!($notifier instanceof INotifier)) { | |
| 195 | -				$this->logger->error('Notification notifier class ' . $notifierClass . ' is not implementing ' . INotifier::class, [ | |
| 196 | - 'app' => 'notifications', | |
| 197 | - ]); | |
| 198 | - continue; | |
| 199 | - } | |
| 200 | - | |
| 201 | - $this->notifiers[] = $notifier; | |
| 202 | - } | |
| 203 | - | |
| 204 | - $this->notifierClasses = []; | |
| 205 | - | |
| 206 | - return $this->notifiers; | |
| 207 | - } | |
| 208 | - | |
| 209 | - /** | |
| 210 | - * @return INotification | |
| 211 | - * @since 8.2.0 | |
| 212 | - */ | |
| 213 | -	public function createNotification(): INotification { | |
| 214 | - return new Notification($this->validator); | |
| 215 | - } | |
| 216 | - | |
| 217 | - /** | |
| 218 | - * @return bool | |
| 219 | - * @since 8.2.0 | |
| 220 | - */ | |
| 221 | -	public function hasNotifiers(): bool { | |
| 222 | - return !empty($this->notifiers) || !empty($this->notifierClasses); | |
| 223 | - } | |
| 224 | - | |
| 225 | - /** | |
| 226 | - * @param bool $preparingPushNotification | |
| 227 | - * @since 14.0.0 | |
| 228 | - */ | |
| 229 | -	public function setPreparingPushNotification(bool $preparingPushNotification): void { | |
| 230 | - $this->preparingPushNotification = $preparingPushNotification; | |
| 231 | - } | |
| 232 | - | |
| 233 | - /** | |
| 234 | - * @return bool | |
| 235 | - * @since 14.0.0 | |
| 236 | - */ | |
| 237 | -	public function isPreparingPushNotification(): bool { | |
| 238 | - return $this->preparingPushNotification; | |
| 239 | - } | |
| 240 | - | |
| 241 | - /** | |
| 242 | - * The calling app should only "flush" when it got returned true on the defer call | |
| 243 | - * @return bool | |
| 244 | - * @since 20.0.0 | |
| 245 | - */ | |
| 246 | -	public function defer(): bool { | |
| 247 | - $alreadyDeferring = $this->deferPushing; | |
| 248 | - $this->deferPushing = true; | |
| 249 | - | |
| 250 | - $apps = $this->getApps(); | |
| 251 | - | |
| 252 | -		foreach ($apps as $app) { | |
| 253 | -			if ($app instanceof IDeferrableApp) { | |
| 254 | - $app->defer(); | |
| 255 | - } | |
| 256 | - } | |
| 257 | - | |
| 258 | - return !$alreadyDeferring; | |
| 259 | - } | |
| 260 | - | |
| 261 | - /** | |
| 262 | - * @since 20.0.0 | |
| 263 | - */ | |
| 264 | -	public function flush(): void { | |
| 265 | - $apps = $this->getApps(); | |
| 266 | - | |
| 267 | -		foreach ($apps as $app) { | |
| 268 | -			if (!$app instanceof IDeferrableApp) { | |
| 269 | - continue; | |
| 270 | - } | |
| 271 | - | |
| 272 | -			try { | |
| 273 | - $app->flush(); | |
| 274 | -			} catch (\InvalidArgumentException $e) { | |
| 275 | - } | |
| 276 | - } | |
| 277 | - | |
| 278 | - $this->deferPushing = false; | |
| 279 | - } | |
| 280 | - | |
| 281 | - /** | |
| 282 | - * @param INotification $notification | |
| 283 | - * @throws \InvalidArgumentException When the notification is not valid | |
| 284 | - * @since 8.2.0 | |
| 285 | - */ | |
| 286 | -	public function notify(INotification $notification): void { | |
| 287 | -		if (!$notification->isValid()) { | |
| 288 | -			throw new \InvalidArgumentException('The given notification is invalid'); | |
| 289 | - } | |
| 290 | - | |
| 291 | - $apps = $this->getApps(); | |
| 292 | - | |
| 293 | -		foreach ($apps as $app) { | |
| 294 | -			try { | |
| 295 | - $app->notify($notification); | |
| 296 | -			} catch (\InvalidArgumentException $e) { | |
| 297 | - } | |
| 298 | - } | |
| 299 | - } | |
| 300 | - | |
| 301 | - /** | |
| 302 | - * Identifier of the notifier, only use [a-z0-9_] | |
| 303 | - * | |
| 304 | - * @return string | |
| 305 | - * @since 17.0.0 | |
| 306 | - */ | |
| 307 | -	public function getID(): string { | |
| 308 | - return 'core'; | |
| 309 | - } | |
| 310 | - | |
| 311 | - /** | |
| 312 | - * Human readable name describing the notifier | |
| 313 | - * | |
| 314 | - * @return string | |
| 315 | - * @since 17.0.0 | |
| 316 | - */ | |
| 317 | -	public function getName(): string { | |
| 318 | - return 'core'; | |
| 319 | - } | |
| 320 | - | |
| 321 | - /** | |
| 322 | - * @param INotification $notification | |
| 323 | - * @param string $languageCode The code of the language that should be used to prepare the notification | |
| 324 | - * @return INotification | |
| 325 | - * @throws \InvalidArgumentException When the notification was not prepared by a notifier | |
| 326 | - * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted | |
| 327 | - * @since 8.2.0 | |
| 328 | - */ | |
| 329 | -	public function prepare(INotification $notification, string $languageCode): INotification { | |
| 330 | - $notifiers = $this->getNotifiers(); | |
| 331 | - | |
| 332 | -		foreach ($notifiers as $notifier) { | |
| 333 | -			try { | |
| 334 | - $notification = $notifier->prepare($notification, $languageCode); | |
| 335 | -			} catch (\InvalidArgumentException $e) { | |
| 336 | - continue; | |
| 337 | -			} catch (AlreadyProcessedException $e) { | |
| 338 | - $this->markProcessed($notification); | |
| 339 | -				throw new \InvalidArgumentException('The given notification has been processed'); | |
| 340 | - } | |
| 341 | - | |
| 342 | -			if (!($notification instanceof INotification) || !$notification->isValidParsed()) { | |
| 343 | -				throw new \InvalidArgumentException('The given notification has not been handled'); | |
| 344 | - } | |
| 345 | - } | |
| 346 | - | |
| 347 | -		if (!($notification instanceof INotification) || !$notification->isValidParsed()) { | |
| 348 | -			throw new \InvalidArgumentException('The given notification has not been handled'); | |
| 349 | - } | |
| 350 | - | |
| 351 | - return $notification; | |
| 352 | - } | |
| 353 | - | |
| 354 | - /** | |
| 355 | - * @param INotification $notification | |
| 356 | - */ | |
| 357 | -	public function markProcessed(INotification $notification): void { | |
| 358 | - $apps = $this->getApps(); | |
| 359 | - | |
| 360 | -		foreach ($apps as $app) { | |
| 361 | - $app->markProcessed($notification); | |
| 362 | - } | |
| 363 | - } | |
| 364 | - | |
| 365 | - /** | |
| 366 | - * @param INotification $notification | |
| 367 | - * @return int | |
| 368 | - */ | |
| 369 | -	public function getCount(INotification $notification): int { | |
| 370 | - $apps = $this->getApps(); | |
| 371 | - | |
| 372 | - $count = 0; | |
| 373 | -		foreach ($apps as $app) { | |
| 374 | - $count += $app->getCount($notification); | |
| 375 | - } | |
| 376 | - | |
| 377 | - return $count; | |
| 378 | - } | |
| 379 | - | |
| 380 | -	public function dismissNotification(INotification $notification): void { | |
| 381 | - $notifiers = $this->getNotifiers(); | |
| 382 | - | |
| 383 | -		foreach ($notifiers as $notifier) { | |
| 384 | -			if ($notifier instanceof IDismissableNotifier) { | |
| 385 | -				try { | |
| 386 | - $notifier->dismissNotification($notification); | |
| 387 | -				} catch (\InvalidArgumentException $e) { | |
| 388 | - continue; | |
| 389 | - } | |
| 390 | - } | |
| 391 | - } | |
| 392 | - } | |
| 43 | + /** @var IValidator */ | |
| 44 | + protected $validator; | |
| 45 | + /** @var ILogger */ | |
| 46 | + protected $logger; | |
| 47 | + /** @var Coordinator */ | |
| 48 | + private $coordinator; | |
| 49 | + | |
| 50 | + /** @var IApp[] */ | |
| 51 | + protected $apps; | |
| 52 | + /** @var string[] */ | |
| 53 | + protected $appClasses; | |
| 54 | + | |
| 55 | + /** @var INotifier[] */ | |
| 56 | + protected $notifiers; | |
| 57 | + /** @var string[] */ | |
| 58 | + protected $notifierClasses; | |
| 59 | + | |
| 60 | + /** @var bool */ | |
| 61 | + protected $preparingPushNotification; | |
| 62 | + /** @var bool */ | |
| 63 | + protected $deferPushing; | |
| 64 | + /** @var bool */ | |
| 65 | + private $parsedRegistrationContext; | |
| 66 | + | |
| 67 | + public function __construct(IValidator $validator, | |
| 68 | + ILogger $logger, | |
| 69 | +                                Coordinator $coordinator) { | |
| 70 | + $this->validator = $validator; | |
| 71 | + $this->logger = $logger; | |
| 72 | + $this->coordinator = $coordinator; | |
| 73 | + | |
| 74 | + $this->apps = []; | |
| 75 | + $this->notifiers = []; | |
| 76 | + $this->appClasses = []; | |
| 77 | + $this->notifierClasses = []; | |
| 78 | + $this->preparingPushNotification = false; | |
| 79 | + $this->deferPushing = false; | |
| 80 | + $this->parsedRegistrationContext = false; | |
| 81 | + } | |
| 82 | + /** | |
| 83 | + * @param string $appClass The service must implement IApp, otherwise a | |
| 84 | + * \InvalidArgumentException is thrown later | |
| 85 | + * @since 17.0.0 | |
| 86 | + */ | |
| 87 | +    public function registerApp(string $appClass): void { | |
| 88 | + $this->appClasses[] = $appClass; | |
| 89 | + } | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * @param \Closure $service The service must implement INotifier, otherwise a | |
| 93 | + * \InvalidArgumentException is thrown later | |
| 94 | + * @param \Closure $info An array with the keys 'id' and 'name' containing | |
| 95 | + * the app id and the app name | |
| 96 | + * @deprecated 17.0.0 use registerNotifierService instead. | |
| 97 | + * @since 8.2.0 - Parameter $info was added in 9.0.0 | |
| 98 | + */ | |
| 99 | +    public function registerNotifier(\Closure $service, \Closure $info) { | |
| 100 | + $infoData = $info(); | |
| 101 | + $this->logger->logException(new \InvalidArgumentException( | |
| 102 | + 'Notifier ' . $infoData['name'] . ' (id: ' . $infoData['id'] . ') is not considered because it is using the old way to register.' | |
| 103 | + )); | |
| 104 | + } | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * @param string $notifierService The service must implement INotifier, otherwise a | |
| 108 | + * \InvalidArgumentException is thrown later | |
| 109 | + * @since 17.0.0 | |
| 110 | + */ | |
| 111 | +    public function registerNotifierService(string $notifierService): void { | |
| 112 | + $this->notifierClasses[] = $notifierService; | |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * @return IApp[] | |
| 117 | + */ | |
| 118 | +    protected function getApps(): array { | |
| 119 | +        if (empty($this->appClasses)) { | |
| 120 | + return $this->apps; | |
| 121 | + } | |
| 122 | + | |
| 123 | +        foreach ($this->appClasses as $appClass) { | |
| 124 | +            try { | |
| 125 | + $app = \OC::$server->query($appClass); | |
| 126 | +            } catch (QueryException $e) { | |
| 127 | + $this->logger->logException($e, [ | |
| 128 | + 'message' => 'Failed to load notification app class: ' . $appClass, | |
| 129 | + 'app' => 'notifications', | |
| 130 | + ]); | |
| 131 | + continue; | |
| 132 | + } | |
| 133 | + | |
| 134 | +            if (!($app instanceof IApp)) { | |
| 135 | +                $this->logger->error('Notification app class ' . $appClass . ' is not implementing ' . IApp::class, [ | |
| 136 | + 'app' => 'notifications', | |
| 137 | + ]); | |
| 138 | + continue; | |
| 139 | + } | |
| 140 | + | |
| 141 | + $this->apps[] = $app; | |
| 142 | + } | |
| 143 | + | |
| 144 | + $this->appClasses = []; | |
| 145 | + | |
| 146 | + return $this->apps; | |
| 147 | + } | |
| 148 | + | |
| 149 | + /** | |
| 150 | + * @return INotifier[] | |
| 151 | + */ | |
| 152 | +    public function getNotifiers(): array { | |
| 153 | +        if (!$this->parsedRegistrationContext) { | |
| 154 | + $notifierServices = $this->coordinator->getRegistrationContext()->getNotifierServices(); | |
| 155 | +            foreach ($notifierServices as $notifierService) { | |
| 156 | +                try { | |
| 157 | + $notifier = \OC::$server->query($notifierService->getService()); | |
| 158 | +                } catch (QueryException $e) { | |
| 159 | + $this->logger->logException($e, [ | |
| 160 | + 'message' => 'Failed to load notification notifier class: ' . $notifierService->getService(), | |
| 161 | + 'app' => 'notifications', | |
| 162 | + ]); | |
| 163 | + continue; | |
| 164 | + } | |
| 165 | + | |
| 166 | +                if (!($notifier instanceof INotifier)) { | |
| 167 | +                    $this->logger->error('Notification notifier class ' . $notifierService->getService() . ' is not implementing ' . INotifier::class, [ | |
| 168 | + 'app' => 'notifications', | |
| 169 | + ]); | |
| 170 | + continue; | |
| 171 | + } | |
| 172 | + | |
| 173 | + $this->notifiers[] = $notifier; | |
| 174 | + } | |
| 175 | + | |
| 176 | + $this->parsedRegistrationContext = true; | |
| 177 | + } | |
| 178 | + | |
| 179 | +        if (empty($this->notifierClasses)) { | |
| 180 | + return $this->notifiers; | |
| 181 | + } | |
| 182 | + | |
| 183 | +        foreach ($this->notifierClasses as $notifierClass) { | |
| 184 | +            try { | |
| 185 | + $notifier = \OC::$server->query($notifierClass); | |
| 186 | +            } catch (QueryException $e) { | |
| 187 | + $this->logger->logException($e, [ | |
| 188 | + 'message' => 'Failed to load notification notifier class: ' . $notifierClass, | |
| 189 | + 'app' => 'notifications', | |
| 190 | + ]); | |
| 191 | + continue; | |
| 192 | + } | |
| 193 | + | |
| 194 | +            if (!($notifier instanceof INotifier)) { | |
| 195 | +                $this->logger->error('Notification notifier class ' . $notifierClass . ' is not implementing ' . INotifier::class, [ | |
| 196 | + 'app' => 'notifications', | |
| 197 | + ]); | |
| 198 | + continue; | |
| 199 | + } | |
| 200 | + | |
| 201 | + $this->notifiers[] = $notifier; | |
| 202 | + } | |
| 203 | + | |
| 204 | + $this->notifierClasses = []; | |
| 205 | + | |
| 206 | + return $this->notifiers; | |
| 207 | + } | |
| 208 | + | |
| 209 | + /** | |
| 210 | + * @return INotification | |
| 211 | + * @since 8.2.0 | |
| 212 | + */ | |
| 213 | +    public function createNotification(): INotification { | |
| 214 | + return new Notification($this->validator); | |
| 215 | + } | |
| 216 | + | |
| 217 | + /** | |
| 218 | + * @return bool | |
| 219 | + * @since 8.2.0 | |
| 220 | + */ | |
| 221 | +    public function hasNotifiers(): bool { | |
| 222 | + return !empty($this->notifiers) || !empty($this->notifierClasses); | |
| 223 | + } | |
| 224 | + | |
| 225 | + /** | |
| 226 | + * @param bool $preparingPushNotification | |
| 227 | + * @since 14.0.0 | |
| 228 | + */ | |
| 229 | +    public function setPreparingPushNotification(bool $preparingPushNotification): void { | |
| 230 | + $this->preparingPushNotification = $preparingPushNotification; | |
| 231 | + } | |
| 232 | + | |
| 233 | + /** | |
| 234 | + * @return bool | |
| 235 | + * @since 14.0.0 | |
| 236 | + */ | |
| 237 | +    public function isPreparingPushNotification(): bool { | |
| 238 | + return $this->preparingPushNotification; | |
| 239 | + } | |
| 240 | + | |
| 241 | + /** | |
| 242 | + * The calling app should only "flush" when it got returned true on the defer call | |
| 243 | + * @return bool | |
| 244 | + * @since 20.0.0 | |
| 245 | + */ | |
| 246 | +    public function defer(): bool { | |
| 247 | + $alreadyDeferring = $this->deferPushing; | |
| 248 | + $this->deferPushing = true; | |
| 249 | + | |
| 250 | + $apps = $this->getApps(); | |
| 251 | + | |
| 252 | +        foreach ($apps as $app) { | |
| 253 | +            if ($app instanceof IDeferrableApp) { | |
| 254 | + $app->defer(); | |
| 255 | + } | |
| 256 | + } | |
| 257 | + | |
| 258 | + return !$alreadyDeferring; | |
| 259 | + } | |
| 260 | + | |
| 261 | + /** | |
| 262 | + * @since 20.0.0 | |
| 263 | + */ | |
| 264 | +    public function flush(): void { | |
| 265 | + $apps = $this->getApps(); | |
| 266 | + | |
| 267 | +        foreach ($apps as $app) { | |
| 268 | +            if (!$app instanceof IDeferrableApp) { | |
| 269 | + continue; | |
| 270 | + } | |
| 271 | + | |
| 272 | +            try { | |
| 273 | + $app->flush(); | |
| 274 | +            } catch (\InvalidArgumentException $e) { | |
| 275 | + } | |
| 276 | + } | |
| 277 | + | |
| 278 | + $this->deferPushing = false; | |
| 279 | + } | |
| 280 | + | |
| 281 | + /** | |
| 282 | + * @param INotification $notification | |
| 283 | + * @throws \InvalidArgumentException When the notification is not valid | |
| 284 | + * @since 8.2.0 | |
| 285 | + */ | |
| 286 | +    public function notify(INotification $notification): void { | |
| 287 | +        if (!$notification->isValid()) { | |
| 288 | +            throw new \InvalidArgumentException('The given notification is invalid'); | |
| 289 | + } | |
| 290 | + | |
| 291 | + $apps = $this->getApps(); | |
| 292 | + | |
| 293 | +        foreach ($apps as $app) { | |
| 294 | +            try { | |
| 295 | + $app->notify($notification); | |
| 296 | +            } catch (\InvalidArgumentException $e) { | |
| 297 | + } | |
| 298 | + } | |
| 299 | + } | |
| 300 | + | |
| 301 | + /** | |
| 302 | + * Identifier of the notifier, only use [a-z0-9_] | |
| 303 | + * | |
| 304 | + * @return string | |
| 305 | + * @since 17.0.0 | |
| 306 | + */ | |
| 307 | +    public function getID(): string { | |
| 308 | + return 'core'; | |
| 309 | + } | |
| 310 | + | |
| 311 | + /** | |
| 312 | + * Human readable name describing the notifier | |
| 313 | + * | |
| 314 | + * @return string | |
| 315 | + * @since 17.0.0 | |
| 316 | + */ | |
| 317 | +    public function getName(): string { | |
| 318 | + return 'core'; | |
| 319 | + } | |
| 320 | + | |
| 321 | + /** | |
| 322 | + * @param INotification $notification | |
| 323 | + * @param string $languageCode The code of the language that should be used to prepare the notification | |
| 324 | + * @return INotification | |
| 325 | + * @throws \InvalidArgumentException When the notification was not prepared by a notifier | |
| 326 | + * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted | |
| 327 | + * @since 8.2.0 | |
| 328 | + */ | |
| 329 | +    public function prepare(INotification $notification, string $languageCode): INotification { | |
| 330 | + $notifiers = $this->getNotifiers(); | |
| 331 | + | |
| 332 | +        foreach ($notifiers as $notifier) { | |
| 333 | +            try { | |
| 334 | + $notification = $notifier->prepare($notification, $languageCode); | |
| 335 | +            } catch (\InvalidArgumentException $e) { | |
| 336 | + continue; | |
| 337 | +            } catch (AlreadyProcessedException $e) { | |
| 338 | + $this->markProcessed($notification); | |
| 339 | +                throw new \InvalidArgumentException('The given notification has been processed'); | |
| 340 | + } | |
| 341 | + | |
| 342 | +            if (!($notification instanceof INotification) || !$notification->isValidParsed()) { | |
| 343 | +                throw new \InvalidArgumentException('The given notification has not been handled'); | |
| 344 | + } | |
| 345 | + } | |
| 346 | + | |
| 347 | +        if (!($notification instanceof INotification) || !$notification->isValidParsed()) { | |
| 348 | +            throw new \InvalidArgumentException('The given notification has not been handled'); | |
| 349 | + } | |
| 350 | + | |
| 351 | + return $notification; | |
| 352 | + } | |
| 353 | + | |
| 354 | + /** | |
| 355 | + * @param INotification $notification | |
| 356 | + */ | |
| 357 | +    public function markProcessed(INotification $notification): void { | |
| 358 | + $apps = $this->getApps(); | |
| 359 | + | |
| 360 | +        foreach ($apps as $app) { | |
| 361 | + $app->markProcessed($notification); | |
| 362 | + } | |
| 363 | + } | |
| 364 | + | |
| 365 | + /** | |
| 366 | + * @param INotification $notification | |
| 367 | + * @return int | |
| 368 | + */ | |
| 369 | +    public function getCount(INotification $notification): int { | |
| 370 | + $apps = $this->getApps(); | |
| 371 | + | |
| 372 | + $count = 0; | |
| 373 | +        foreach ($apps as $app) { | |
| 374 | + $count += $app->getCount($notification); | |
| 375 | + } | |
| 376 | + | |
| 377 | + return $count; | |
| 378 | + } | |
| 379 | + | |
| 380 | +    public function dismissNotification(INotification $notification): void { | |
| 381 | + $notifiers = $this->getNotifiers(); | |
| 382 | + | |
| 383 | +        foreach ($notifiers as $notifier) { | |
| 384 | +            if ($notifier instanceof IDismissableNotifier) { | |
| 385 | +                try { | |
| 386 | + $notifier->dismissNotification($notification); | |
| 387 | +                } catch (\InvalidArgumentException $e) { | |
| 388 | + continue; | |
| 389 | + } | |
| 390 | + } | |
| 391 | + } | |
| 392 | + } | |
| 393 | 393 | } | 
| @@ -99,7 +99,7 @@ discard block | ||
| 99 | 99 |  	public function registerNotifier(\Closure $service, \Closure $info) { | 
| 100 | 100 | $infoData = $info(); | 
| 101 | 101 | $this->logger->logException(new \InvalidArgumentException( | 
| 102 | - 'Notifier ' . $infoData['name'] . ' (id: ' . $infoData['id'] . ') is not considered because it is using the old way to register.' | |
| 102 | + 'Notifier '.$infoData['name'].' (id: '.$infoData['id'].') is not considered because it is using the old way to register.' | |
| 103 | 103 | )); | 
| 104 | 104 | } | 
| 105 | 105 | |
| @@ -125,14 +125,14 @@ discard block | ||
| 125 | 125 | $app = \OC::$server->query($appClass); | 
| 126 | 126 |  			} catch (QueryException $e) { | 
| 127 | 127 | $this->logger->logException($e, [ | 
| 128 | - 'message' => 'Failed to load notification app class: ' . $appClass, | |
| 128 | + 'message' => 'Failed to load notification app class: '.$appClass, | |
| 129 | 129 | 'app' => 'notifications', | 
| 130 | 130 | ]); | 
| 131 | 131 | continue; | 
| 132 | 132 | } | 
| 133 | 133 | |
| 134 | 134 |  			if (!($app instanceof IApp)) { | 
| 135 | -				$this->logger->error('Notification app class ' . $appClass . ' is not implementing ' . IApp::class, [ | |
| 135 | +				$this->logger->error('Notification app class '.$appClass.' is not implementing '.IApp::class, [ | |
| 136 | 136 | 'app' => 'notifications', | 
| 137 | 137 | ]); | 
| 138 | 138 | continue; | 
| @@ -157,14 +157,14 @@ discard block | ||
| 157 | 157 | $notifier = \OC::$server->query($notifierService->getService()); | 
| 158 | 158 |  				} catch (QueryException $e) { | 
| 159 | 159 | $this->logger->logException($e, [ | 
| 160 | - 'message' => 'Failed to load notification notifier class: ' . $notifierService->getService(), | |
| 160 | + 'message' => 'Failed to load notification notifier class: '.$notifierService->getService(), | |
| 161 | 161 | 'app' => 'notifications', | 
| 162 | 162 | ]); | 
| 163 | 163 | continue; | 
| 164 | 164 | } | 
| 165 | 165 | |
| 166 | 166 |  				if (!($notifier instanceof INotifier)) { | 
| 167 | -					$this->logger->error('Notification notifier class ' . $notifierService->getService() . ' is not implementing ' . INotifier::class, [ | |
| 167 | +					$this->logger->error('Notification notifier class '.$notifierService->getService().' is not implementing '.INotifier::class, [ | |
| 168 | 168 | 'app' => 'notifications', | 
| 169 | 169 | ]); | 
| 170 | 170 | continue; | 
| @@ -185,14 +185,14 @@ discard block | ||
| 185 | 185 | $notifier = \OC::$server->query($notifierClass); | 
| 186 | 186 |  			} catch (QueryException $e) { | 
| 187 | 187 | $this->logger->logException($e, [ | 
| 188 | - 'message' => 'Failed to load notification notifier class: ' . $notifierClass, | |
| 188 | + 'message' => 'Failed to load notification notifier class: '.$notifierClass, | |
| 189 | 189 | 'app' => 'notifications', | 
| 190 | 190 | ]); | 
| 191 | 191 | continue; | 
| 192 | 192 | } | 
| 193 | 193 | |
| 194 | 194 |  			if (!($notifier instanceof INotifier)) { | 
| 195 | -				$this->logger->error('Notification notifier class ' . $notifierClass . ' is not implementing ' . INotifier::class, [ | |
| 195 | +				$this->logger->error('Notification notifier class '.$notifierClass.' is not implementing '.INotifier::class, [ | |
| 196 | 196 | 'app' => 'notifications', | 
| 197 | 197 | ]); | 
| 198 | 198 | continue; | 
| @@ -52,431 +52,431 @@ | ||
| 52 | 52 | |
| 53 | 53 |  class RegistrationContext { | 
| 54 | 54 | |
| 55 | - /** @var ServiceRegistration<ICapability>[] */ | |
| 56 | - private $capabilities = []; | |
| 57 | - | |
| 58 | - /** @var ServiceRegistration<IReporter>[] */ | |
| 59 | - private $crashReporters = []; | |
| 60 | - | |
| 61 | - /** @var ServiceRegistration<IWidget>[] */ | |
| 62 | - private $dashboardPanels = []; | |
| 63 | - | |
| 64 | - /** @var ServiceFactoryRegistration[] */ | |
| 65 | - private $services = []; | |
| 66 | - | |
| 67 | - /** @var ServiceAliasRegistration[] */ | |
| 68 | - private $aliases = []; | |
| 69 | - | |
| 70 | - /** @var ParameterRegistration[] */ | |
| 71 | - private $parameters = []; | |
| 72 | - | |
| 73 | - /** @var EventListenerRegistration[] */ | |
| 74 | - private $eventListeners = []; | |
| 75 | - | |
| 76 | - /** @var ServiceRegistration<Middleware>[] */ | |
| 77 | - private $middlewares = []; | |
| 78 | - | |
| 79 | - /** @var ServiceRegistration<IProvider>[] */ | |
| 80 | - private $searchProviders = []; | |
| 81 | - | |
| 82 | - /** @var ServiceRegistration<IAlternativeLogin>[] */ | |
| 83 | - private $alternativeLogins = []; | |
| 84 | - | |
| 85 | - /** @var ServiceRegistration<InitialStateProvider>[] */ | |
| 86 | - private $initialStates = []; | |
| 87 | - | |
| 88 | - /** @var ServiceRegistration<IHandler>[] */ | |
| 89 | - private $wellKnownHandlers = []; | |
| 90 | - | |
| 91 | - /** @var ServiceRegistration<ICustomTemplateProvider>[] */ | |
| 92 | - private $templateProviders = []; | |
| 93 | - | |
| 94 | - /** @var ServiceRegistration<INotifier>[] */ | |
| 95 | - private $notifierServices; | |
| 96 | - | |
| 97 | - /** @var ILogger */ | |
| 98 | - private $logger; | |
| 99 | - | |
| 100 | -	public function __construct(ILogger $logger) { | |
| 101 | - $this->logger = $logger; | |
| 102 | - } | |
| 103 | - | |
| 104 | -	public function for(string $appId): IRegistrationContext { | |
| 105 | -		return new class($appId, $this) implements IRegistrationContext { | |
| 106 | - /** @var string */ | |
| 107 | - private $appId; | |
| 108 | - | |
| 109 | - /** @var RegistrationContext */ | |
| 110 | - private $context; | |
| 111 | - | |
| 112 | -			public function __construct(string $appId, RegistrationContext $context) { | |
| 113 | - $this->appId = $appId; | |
| 114 | - $this->context = $context; | |
| 115 | - } | |
| 116 | - | |
| 117 | -			public function registerCapability(string $capability): void { | |
| 118 | - $this->context->registerCapability( | |
| 119 | - $this->appId, | |
| 120 | - $capability | |
| 121 | - ); | |
| 122 | - } | |
| 123 | - | |
| 124 | -			public function registerCrashReporter(string $reporterClass): void { | |
| 125 | - $this->context->registerCrashReporter( | |
| 126 | - $this->appId, | |
| 127 | - $reporterClass | |
| 128 | - ); | |
| 129 | - } | |
| 130 | - | |
| 131 | -			public function registerDashboardWidget(string $widgetClass): void { | |
| 132 | - $this->context->registerDashboardPanel( | |
| 133 | - $this->appId, | |
| 134 | - $widgetClass | |
| 135 | - ); | |
| 136 | - } | |
| 137 | - | |
| 138 | -			public function registerService(string $name, callable $factory, bool $shared = true): void { | |
| 139 | - $this->context->registerService( | |
| 140 | - $this->appId, | |
| 141 | - $name, | |
| 142 | - $factory, | |
| 143 | - $shared | |
| 144 | - ); | |
| 145 | - } | |
| 146 | - | |
| 147 | -			public function registerServiceAlias(string $alias, string $target): void { | |
| 148 | - $this->context->registerServiceAlias( | |
| 149 | - $this->appId, | |
| 150 | - $alias, | |
| 151 | - $target | |
| 152 | - ); | |
| 153 | - } | |
| 154 | - | |
| 155 | -			public function registerParameter(string $name, $value): void { | |
| 156 | - $this->context->registerParameter( | |
| 157 | - $this->appId, | |
| 158 | - $name, | |
| 159 | - $value | |
| 160 | - ); | |
| 161 | - } | |
| 162 | - | |
| 163 | -			public function registerEventListener(string $event, string $listener, int $priority = 0): void { | |
| 164 | - $this->context->registerEventListener( | |
| 165 | - $this->appId, | |
| 166 | - $event, | |
| 167 | - $listener, | |
| 168 | - $priority | |
| 169 | - ); | |
| 170 | - } | |
| 171 | - | |
| 172 | -			public function registerMiddleware(string $class): void { | |
| 173 | - $this->context->registerMiddleware( | |
| 174 | - $this->appId, | |
| 175 | - $class | |
| 176 | - ); | |
| 177 | - } | |
| 178 | - | |
| 179 | -			public function registerSearchProvider(string $class): void { | |
| 180 | - $this->context->registerSearchProvider( | |
| 181 | - $this->appId, | |
| 182 | - $class | |
| 183 | - ); | |
| 184 | - } | |
| 185 | - | |
| 186 | -			public function registerAlternativeLogin(string $class): void { | |
| 187 | - $this->context->registerAlternativeLogin( | |
| 188 | - $this->appId, | |
| 189 | - $class | |
| 190 | - ); | |
| 191 | - } | |
| 192 | - | |
| 193 | -			public function registerInitialStateProvider(string $class): void { | |
| 194 | - $this->context->registerInitialState( | |
| 195 | - $this->appId, | |
| 196 | - $class | |
| 197 | - ); | |
| 198 | - } | |
| 199 | - | |
| 200 | -			public function registerWellKnownHandler(string $class): void { | |
| 201 | - $this->context->registerWellKnown( | |
| 202 | - $this->appId, | |
| 203 | - $class | |
| 204 | - ); | |
| 205 | - } | |
| 206 | - | |
| 207 | -			public function registerTemplateProvider(string $providerClass): void { | |
| 208 | - $this->context->registerTemplateProvider( | |
| 209 | - $this->appId, | |
| 210 | - $providerClass | |
| 211 | - ); | |
| 212 | - } | |
| 213 | - | |
| 214 | -			public function registerNotifierService(string $notifierClass): void { | |
| 215 | - $this->context->registerNotifierService( | |
| 216 | - $this->appId, | |
| 217 | - $notifierClass | |
| 218 | - ); | |
| 219 | - } | |
| 220 | - }; | |
| 221 | - } | |
| 222 | - | |
| 223 | - /** | |
| 224 | - * @psalm-param class-string<ICapability> $capability | |
| 225 | - */ | |
| 226 | -	public function registerCapability(string $appId, string $capability): void { | |
| 227 | - $this->capabilities[] = new ServiceRegistration($appId, $capability); | |
| 228 | - } | |
| 229 | - | |
| 230 | - /** | |
| 231 | - * @psalm-param class-string<IReporter> $capability | |
| 232 | - */ | |
| 233 | -	public function registerCrashReporter(string $appId, string $reporterClass): void { | |
| 234 | - $this->crashReporters[] = new ServiceRegistration($appId, $reporterClass); | |
| 235 | - } | |
| 236 | - | |
| 237 | - /** | |
| 238 | - * @psalm-param class-string<IWidget> $capability | |
| 239 | - */ | |
| 240 | -	public function registerDashboardPanel(string $appId, string $panelClass): void { | |
| 241 | - $this->dashboardPanels[] = new ServiceRegistration($appId, $panelClass); | |
| 242 | - } | |
| 243 | - | |
| 244 | -	public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { | |
| 245 | - $this->services[] = new ServiceFactoryRegistration($appId, $name, $factory, $shared); | |
| 246 | - } | |
| 247 | - | |
| 248 | -	public function registerServiceAlias(string $appId, string $alias, string $target): void { | |
| 249 | - $this->aliases[] = new ServiceAliasRegistration($appId, $alias, $target); | |
| 250 | - } | |
| 251 | - | |
| 252 | -	public function registerParameter(string $appId, string $name, $value): void { | |
| 253 | - $this->parameters[] = new ParameterRegistration($appId, $name, $value); | |
| 254 | - } | |
| 255 | - | |
| 256 | -	public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void { | |
| 257 | - $this->eventListeners[] = new EventListenerRegistration($appId, $event, $listener, $priority); | |
| 258 | - } | |
| 259 | - | |
| 260 | - /** | |
| 261 | - * @psalm-param class-string<Middleware> $class | |
| 262 | - */ | |
| 263 | -	public function registerMiddleware(string $appId, string $class): void { | |
| 264 | - $this->middlewares[] = new ServiceRegistration($appId, $class); | |
| 265 | - } | |
| 266 | - | |
| 267 | -	public function registerSearchProvider(string $appId, string $class) { | |
| 268 | - $this->searchProviders[] = new ServiceRegistration($appId, $class); | |
| 269 | - } | |
| 270 | - | |
| 271 | -	public function registerAlternativeLogin(string $appId, string $class): void { | |
| 272 | - $this->alternativeLogins[] = new ServiceRegistration($appId, $class); | |
| 273 | - } | |
| 274 | - | |
| 275 | -	public function registerInitialState(string $appId, string $class): void { | |
| 276 | - $this->initialStates[] = new ServiceRegistration($appId, $class); | |
| 277 | - } | |
| 278 | - | |
| 279 | -	public function registerWellKnown(string $appId, string $class): void { | |
| 280 | - $this->wellKnownHandlers[] = new ServiceRegistration($appId, $class); | |
| 281 | - } | |
| 282 | - | |
| 283 | -	public function registerTemplateProvider(string $appId, string $class): void { | |
| 284 | - $this->templateProviders[] = new ServiceRegistration($appId, $class); | |
| 285 | - } | |
| 286 | - | |
| 287 | -	public function registerNotifierService(string $appId, string $class): void { | |
| 288 | - $this->notifierServices[] = new ServiceRegistration($appId, $class); | |
| 289 | - } | |
| 290 | - | |
| 291 | - /** | |
| 292 | - * @param App[] $apps | |
| 293 | - */ | |
| 294 | -	public function delegateCapabilityRegistrations(array $apps): void { | |
| 295 | -		while (($registration = array_shift($this->capabilities)) !== null) { | |
| 296 | -			try { | |
| 297 | - $apps[$registration->getAppId()] | |
| 298 | - ->getContainer() | |
| 299 | - ->registerCapability($registration->getService()); | |
| 300 | -			} catch (Throwable $e) { | |
| 301 | - $appId = $registration->getAppId(); | |
| 302 | - $this->logger->logException($e, [ | |
| 303 | - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), | |
| 304 | - 'level' => ILogger::ERROR, | |
| 305 | - ]); | |
| 306 | - } | |
| 307 | - } | |
| 308 | - } | |
| 309 | - | |
| 310 | - /** | |
| 311 | - * @param App[] $apps | |
| 312 | - */ | |
| 313 | -	public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { | |
| 314 | -		while (($registration = array_shift($this->crashReporters)) !== null) { | |
| 315 | -			try { | |
| 316 | - $registry->registerLazy($registration->getService()); | |
| 317 | -			} catch (Throwable $e) { | |
| 318 | - $appId = $registration->getAppId(); | |
| 319 | - $this->logger->logException($e, [ | |
| 320 | - 'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(), | |
| 321 | - 'level' => ILogger::ERROR, | |
| 322 | - ]); | |
| 323 | - } | |
| 324 | - } | |
| 325 | - } | |
| 326 | - | |
| 327 | - /** | |
| 328 | - * @param App[] $apps | |
| 329 | - */ | |
| 330 | -	public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void { | |
| 331 | -		while (($panel = array_shift($this->dashboardPanels)) !== null) { | |
| 332 | -			try { | |
| 333 | - $dashboardManager->lazyRegisterWidget($panel->getService()); | |
| 334 | -			} catch (Throwable $e) { | |
| 335 | - $appId = $panel->getAppId(); | |
| 336 | - $this->logger->logException($e, [ | |
| 337 | - 'message' => "Error during dashboard registration of $appId: " . $e->getMessage(), | |
| 338 | - 'level' => ILogger::ERROR, | |
| 339 | - ]); | |
| 340 | - } | |
| 341 | - } | |
| 342 | - } | |
| 343 | - | |
| 344 | -	public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { | |
| 345 | -		while (($registration = array_shift($this->eventListeners)) !== null) { | |
| 346 | -			try { | |
| 347 | - $eventDispatcher->addServiceListener( | |
| 348 | - $registration->getEvent(), | |
| 349 | - $registration->getService(), | |
| 350 | - $registration->getPriority() | |
| 351 | - ); | |
| 352 | -			} catch (Throwable $e) { | |
| 353 | - $appId = $registration->getAppId(); | |
| 354 | - $this->logger->logException($e, [ | |
| 355 | - 'message' => "Error during event listener registration of $appId: " . $e->getMessage(), | |
| 356 | - 'level' => ILogger::ERROR, | |
| 357 | - ]); | |
| 358 | - } | |
| 359 | - } | |
| 360 | - } | |
| 361 | - | |
| 362 | - /** | |
| 363 | - * @param App[] $apps | |
| 364 | - */ | |
| 365 | -	public function delegateContainerRegistrations(array $apps): void { | |
| 366 | -		while (($registration = array_shift($this->services)) !== null) { | |
| 367 | -			try { | |
| 368 | - /** | |
| 369 | - * Register the service and convert the callable into a \Closure if necessary | |
| 370 | - */ | |
| 371 | - $apps[$registration->getAppId()] | |
| 372 | - ->getContainer() | |
| 373 | - ->registerService( | |
| 374 | - $registration->getName(), | |
| 375 | - Closure::fromCallable($registration->getFactory()), | |
| 376 | - $registration->isShared() | |
| 377 | - ); | |
| 378 | -			} catch (Throwable $e) { | |
| 379 | - $appId = $registration->getAppId(); | |
| 380 | - $this->logger->logException($e, [ | |
| 381 | - 'message' => "Error during service registration of $appId: " . $e->getMessage(), | |
| 382 | - 'level' => ILogger::ERROR, | |
| 383 | - ]); | |
| 384 | - } | |
| 385 | - } | |
| 386 | - | |
| 387 | -		while (($registration = array_shift($this->aliases)) !== null) { | |
| 388 | -			try { | |
| 389 | - $apps[$registration->getAppId()] | |
| 390 | - ->getContainer() | |
| 391 | - ->registerAlias( | |
| 392 | - $registration->getAlias(), | |
| 393 | - $registration->getTarget() | |
| 394 | - ); | |
| 395 | -			} catch (Throwable $e) { | |
| 396 | - $appId = $registration->getAppId(); | |
| 397 | - $this->logger->logException($e, [ | |
| 398 | - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), | |
| 399 | - 'level' => ILogger::ERROR, | |
| 400 | - ]); | |
| 401 | - } | |
| 402 | - } | |
| 403 | - | |
| 404 | -		while (($registration = array_shift($this->parameters)) !== null) { | |
| 405 | -			try { | |
| 406 | - $apps[$registration->getAppId()] | |
| 407 | - ->getContainer() | |
| 408 | - ->registerParameter( | |
| 409 | - $registration->getName(), | |
| 410 | - $registration->getValue() | |
| 411 | - ); | |
| 412 | -			} catch (Throwable $e) { | |
| 413 | - $appId = $registration->getAppId(); | |
| 414 | - $this->logger->logException($e, [ | |
| 415 | - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), | |
| 416 | - 'level' => ILogger::ERROR, | |
| 417 | - ]); | |
| 418 | - } | |
| 419 | - } | |
| 420 | - } | |
| 421 | - | |
| 422 | - /** | |
| 423 | - * @param App[] $apps | |
| 424 | - */ | |
| 425 | -	public function delegateMiddlewareRegistrations(array $apps): void { | |
| 426 | -		while (($middleware = array_shift($this->middlewares)) !== null) { | |
| 427 | -			try { | |
| 428 | - $apps[$middleware->getAppId()] | |
| 429 | - ->getContainer() | |
| 430 | - ->registerMiddleWare($middleware->getService()); | |
| 431 | -			} catch (Throwable $e) { | |
| 432 | - $appId = $middleware->getAppId(); | |
| 433 | - $this->logger->logException($e, [ | |
| 434 | - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), | |
| 435 | - 'level' => ILogger::ERROR, | |
| 436 | - ]); | |
| 437 | - } | |
| 438 | - } | |
| 439 | - } | |
| 440 | - | |
| 441 | - /** | |
| 442 | - * @return ServiceRegistration<IProvider>[] | |
| 443 | - */ | |
| 444 | -	public function getSearchProviders(): array { | |
| 445 | - return $this->searchProviders; | |
| 446 | - } | |
| 447 | - | |
| 448 | - /** | |
| 449 | - * @return ServiceRegistration<IAlternativeLogin>[] | |
| 450 | - */ | |
| 451 | -	public function getAlternativeLogins(): array { | |
| 452 | - return $this->alternativeLogins; | |
| 453 | - } | |
| 454 | - | |
| 455 | - /** | |
| 456 | - * @return ServiceRegistration<InitialStateProvider>[] | |
| 457 | - */ | |
| 458 | -	public function getInitialStates(): array { | |
| 459 | - return $this->initialStates; | |
| 460 | - } | |
| 461 | - | |
| 462 | - /** | |
| 463 | - * @return ServiceRegistration<IHandler>[] | |
| 464 | - */ | |
| 465 | -	public function getWellKnownHandlers(): array { | |
| 466 | - return $this->wellKnownHandlers; | |
| 467 | - } | |
| 468 | - | |
| 469 | - /** | |
| 470 | - * @return ServiceRegistration<ICustomTemplateProvider>[] | |
| 471 | - */ | |
| 472 | -	public function getTemplateProviders(): array { | |
| 473 | - return $this->templateProviders; | |
| 474 | - } | |
| 475 | - | |
| 476 | - /** | |
| 477 | - * @return ServiceRegistration<INotifier>[] | |
| 478 | - */ | |
| 479 | -	public function getNotifierServices(): array { | |
| 480 | - return $this->notifierServices; | |
| 481 | - } | |
| 55 | + /** @var ServiceRegistration<ICapability>[] */ | |
| 56 | + private $capabilities = []; | |
| 57 | + | |
| 58 | + /** @var ServiceRegistration<IReporter>[] */ | |
| 59 | + private $crashReporters = []; | |
| 60 | + | |
| 61 | + /** @var ServiceRegistration<IWidget>[] */ | |
| 62 | + private $dashboardPanels = []; | |
| 63 | + | |
| 64 | + /** @var ServiceFactoryRegistration[] */ | |
| 65 | + private $services = []; | |
| 66 | + | |
| 67 | + /** @var ServiceAliasRegistration[] */ | |
| 68 | + private $aliases = []; | |
| 69 | + | |
| 70 | + /** @var ParameterRegistration[] */ | |
| 71 | + private $parameters = []; | |
| 72 | + | |
| 73 | + /** @var EventListenerRegistration[] */ | |
| 74 | + private $eventListeners = []; | |
| 75 | + | |
| 76 | + /** @var ServiceRegistration<Middleware>[] */ | |
| 77 | + private $middlewares = []; | |
| 78 | + | |
| 79 | + /** @var ServiceRegistration<IProvider>[] */ | |
| 80 | + private $searchProviders = []; | |
| 81 | + | |
| 82 | + /** @var ServiceRegistration<IAlternativeLogin>[] */ | |
| 83 | + private $alternativeLogins = []; | |
| 84 | + | |
| 85 | + /** @var ServiceRegistration<InitialStateProvider>[] */ | |
| 86 | + private $initialStates = []; | |
| 87 | + | |
| 88 | + /** @var ServiceRegistration<IHandler>[] */ | |
| 89 | + private $wellKnownHandlers = []; | |
| 90 | + | |
| 91 | + /** @var ServiceRegistration<ICustomTemplateProvider>[] */ | |
| 92 | + private $templateProviders = []; | |
| 93 | + | |
| 94 | + /** @var ServiceRegistration<INotifier>[] */ | |
| 95 | + private $notifierServices; | |
| 96 | + | |
| 97 | + /** @var ILogger */ | |
| 98 | + private $logger; | |
| 99 | + | |
| 100 | +    public function __construct(ILogger $logger) { | |
| 101 | + $this->logger = $logger; | |
| 102 | + } | |
| 103 | + | |
| 104 | +    public function for(string $appId): IRegistrationContext { | |
| 105 | +        return new class($appId, $this) implements IRegistrationContext { | |
| 106 | + /** @var string */ | |
| 107 | + private $appId; | |
| 108 | + | |
| 109 | + /** @var RegistrationContext */ | |
| 110 | + private $context; | |
| 111 | + | |
| 112 | +            public function __construct(string $appId, RegistrationContext $context) { | |
| 113 | + $this->appId = $appId; | |
| 114 | + $this->context = $context; | |
| 115 | + } | |
| 116 | + | |
| 117 | +            public function registerCapability(string $capability): void { | |
| 118 | + $this->context->registerCapability( | |
| 119 | + $this->appId, | |
| 120 | + $capability | |
| 121 | + ); | |
| 122 | + } | |
| 123 | + | |
| 124 | +            public function registerCrashReporter(string $reporterClass): void { | |
| 125 | + $this->context->registerCrashReporter( | |
| 126 | + $this->appId, | |
| 127 | + $reporterClass | |
| 128 | + ); | |
| 129 | + } | |
| 130 | + | |
| 131 | +            public function registerDashboardWidget(string $widgetClass): void { | |
| 132 | + $this->context->registerDashboardPanel( | |
| 133 | + $this->appId, | |
| 134 | + $widgetClass | |
| 135 | + ); | |
| 136 | + } | |
| 137 | + | |
| 138 | +            public function registerService(string $name, callable $factory, bool $shared = true): void { | |
| 139 | + $this->context->registerService( | |
| 140 | + $this->appId, | |
| 141 | + $name, | |
| 142 | + $factory, | |
| 143 | + $shared | |
| 144 | + ); | |
| 145 | + } | |
| 146 | + | |
| 147 | +            public function registerServiceAlias(string $alias, string $target): void { | |
| 148 | + $this->context->registerServiceAlias( | |
| 149 | + $this->appId, | |
| 150 | + $alias, | |
| 151 | + $target | |
| 152 | + ); | |
| 153 | + } | |
| 154 | + | |
| 155 | +            public function registerParameter(string $name, $value): void { | |
| 156 | + $this->context->registerParameter( | |
| 157 | + $this->appId, | |
| 158 | + $name, | |
| 159 | + $value | |
| 160 | + ); | |
| 161 | + } | |
| 162 | + | |
| 163 | +            public function registerEventListener(string $event, string $listener, int $priority = 0): void { | |
| 164 | + $this->context->registerEventListener( | |
| 165 | + $this->appId, | |
| 166 | + $event, | |
| 167 | + $listener, | |
| 168 | + $priority | |
| 169 | + ); | |
| 170 | + } | |
| 171 | + | |
| 172 | +            public function registerMiddleware(string $class): void { | |
| 173 | + $this->context->registerMiddleware( | |
| 174 | + $this->appId, | |
| 175 | + $class | |
| 176 | + ); | |
| 177 | + } | |
| 178 | + | |
| 179 | +            public function registerSearchProvider(string $class): void { | |
| 180 | + $this->context->registerSearchProvider( | |
| 181 | + $this->appId, | |
| 182 | + $class | |
| 183 | + ); | |
| 184 | + } | |
| 185 | + | |
| 186 | +            public function registerAlternativeLogin(string $class): void { | |
| 187 | + $this->context->registerAlternativeLogin( | |
| 188 | + $this->appId, | |
| 189 | + $class | |
| 190 | + ); | |
| 191 | + } | |
| 192 | + | |
| 193 | +            public function registerInitialStateProvider(string $class): void { | |
| 194 | + $this->context->registerInitialState( | |
| 195 | + $this->appId, | |
| 196 | + $class | |
| 197 | + ); | |
| 198 | + } | |
| 199 | + | |
| 200 | +            public function registerWellKnownHandler(string $class): void { | |
| 201 | + $this->context->registerWellKnown( | |
| 202 | + $this->appId, | |
| 203 | + $class | |
| 204 | + ); | |
| 205 | + } | |
| 206 | + | |
| 207 | +            public function registerTemplateProvider(string $providerClass): void { | |
| 208 | + $this->context->registerTemplateProvider( | |
| 209 | + $this->appId, | |
| 210 | + $providerClass | |
| 211 | + ); | |
| 212 | + } | |
| 213 | + | |
| 214 | +            public function registerNotifierService(string $notifierClass): void { | |
| 215 | + $this->context->registerNotifierService( | |
| 216 | + $this->appId, | |
| 217 | + $notifierClass | |
| 218 | + ); | |
| 219 | + } | |
| 220 | + }; | |
| 221 | + } | |
| 222 | + | |
| 223 | + /** | |
| 224 | + * @psalm-param class-string<ICapability> $capability | |
| 225 | + */ | |
| 226 | +    public function registerCapability(string $appId, string $capability): void { | |
| 227 | + $this->capabilities[] = new ServiceRegistration($appId, $capability); | |
| 228 | + } | |
| 229 | + | |
| 230 | + /** | |
| 231 | + * @psalm-param class-string<IReporter> $capability | |
| 232 | + */ | |
| 233 | +    public function registerCrashReporter(string $appId, string $reporterClass): void { | |
| 234 | + $this->crashReporters[] = new ServiceRegistration($appId, $reporterClass); | |
| 235 | + } | |
| 236 | + | |
| 237 | + /** | |
| 238 | + * @psalm-param class-string<IWidget> $capability | |
| 239 | + */ | |
| 240 | +    public function registerDashboardPanel(string $appId, string $panelClass): void { | |
| 241 | + $this->dashboardPanels[] = new ServiceRegistration($appId, $panelClass); | |
| 242 | + } | |
| 243 | + | |
| 244 | +    public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { | |
| 245 | + $this->services[] = new ServiceFactoryRegistration($appId, $name, $factory, $shared); | |
| 246 | + } | |
| 247 | + | |
| 248 | +    public function registerServiceAlias(string $appId, string $alias, string $target): void { | |
| 249 | + $this->aliases[] = new ServiceAliasRegistration($appId, $alias, $target); | |
| 250 | + } | |
| 251 | + | |
| 252 | +    public function registerParameter(string $appId, string $name, $value): void { | |
| 253 | + $this->parameters[] = new ParameterRegistration($appId, $name, $value); | |
| 254 | + } | |
| 255 | + | |
| 256 | +    public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void { | |
| 257 | + $this->eventListeners[] = new EventListenerRegistration($appId, $event, $listener, $priority); | |
| 258 | + } | |
| 259 | + | |
| 260 | + /** | |
| 261 | + * @psalm-param class-string<Middleware> $class | |
| 262 | + */ | |
| 263 | +    public function registerMiddleware(string $appId, string $class): void { | |
| 264 | + $this->middlewares[] = new ServiceRegistration($appId, $class); | |
| 265 | + } | |
| 266 | + | |
| 267 | +    public function registerSearchProvider(string $appId, string $class) { | |
| 268 | + $this->searchProviders[] = new ServiceRegistration($appId, $class); | |
| 269 | + } | |
| 270 | + | |
| 271 | +    public function registerAlternativeLogin(string $appId, string $class): void { | |
| 272 | + $this->alternativeLogins[] = new ServiceRegistration($appId, $class); | |
| 273 | + } | |
| 274 | + | |
| 275 | +    public function registerInitialState(string $appId, string $class): void { | |
| 276 | + $this->initialStates[] = new ServiceRegistration($appId, $class); | |
| 277 | + } | |
| 278 | + | |
| 279 | +    public function registerWellKnown(string $appId, string $class): void { | |
| 280 | + $this->wellKnownHandlers[] = new ServiceRegistration($appId, $class); | |
| 281 | + } | |
| 282 | + | |
| 283 | +    public function registerTemplateProvider(string $appId, string $class): void { | |
| 284 | + $this->templateProviders[] = new ServiceRegistration($appId, $class); | |
| 285 | + } | |
| 286 | + | |
| 287 | +    public function registerNotifierService(string $appId, string $class): void { | |
| 288 | + $this->notifierServices[] = new ServiceRegistration($appId, $class); | |
| 289 | + } | |
| 290 | + | |
| 291 | + /** | |
| 292 | + * @param App[] $apps | |
| 293 | + */ | |
| 294 | +    public function delegateCapabilityRegistrations(array $apps): void { | |
| 295 | +        while (($registration = array_shift($this->capabilities)) !== null) { | |
| 296 | +            try { | |
| 297 | + $apps[$registration->getAppId()] | |
| 298 | + ->getContainer() | |
| 299 | + ->registerCapability($registration->getService()); | |
| 300 | +            } catch (Throwable $e) { | |
| 301 | + $appId = $registration->getAppId(); | |
| 302 | + $this->logger->logException($e, [ | |
| 303 | + 'message' => "Error during capability registration of $appId: " . $e->getMessage(), | |
| 304 | + 'level' => ILogger::ERROR, | |
| 305 | + ]); | |
| 306 | + } | |
| 307 | + } | |
| 308 | + } | |
| 309 | + | |
| 310 | + /** | |
| 311 | + * @param App[] $apps | |
| 312 | + */ | |
| 313 | +    public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { | |
| 314 | +        while (($registration = array_shift($this->crashReporters)) !== null) { | |
| 315 | +            try { | |
| 316 | + $registry->registerLazy($registration->getService()); | |
| 317 | +            } catch (Throwable $e) { | |
| 318 | + $appId = $registration->getAppId(); | |
| 319 | + $this->logger->logException($e, [ | |
| 320 | + 'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(), | |
| 321 | + 'level' => ILogger::ERROR, | |
| 322 | + ]); | |
| 323 | + } | |
| 324 | + } | |
| 325 | + } | |
| 326 | + | |
| 327 | + /** | |
| 328 | + * @param App[] $apps | |
| 329 | + */ | |
| 330 | +    public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void { | |
| 331 | +        while (($panel = array_shift($this->dashboardPanels)) !== null) { | |
| 332 | +            try { | |
| 333 | + $dashboardManager->lazyRegisterWidget($panel->getService()); | |
| 334 | +            } catch (Throwable $e) { | |
| 335 | + $appId = $panel->getAppId(); | |
| 336 | + $this->logger->logException($e, [ | |
| 337 | + 'message' => "Error during dashboard registration of $appId: " . $e->getMessage(), | |
| 338 | + 'level' => ILogger::ERROR, | |
| 339 | + ]); | |
| 340 | + } | |
| 341 | + } | |
| 342 | + } | |
| 343 | + | |
| 344 | +    public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { | |
| 345 | +        while (($registration = array_shift($this->eventListeners)) !== null) { | |
| 346 | +            try { | |
| 347 | + $eventDispatcher->addServiceListener( | |
| 348 | + $registration->getEvent(), | |
| 349 | + $registration->getService(), | |
| 350 | + $registration->getPriority() | |
| 351 | + ); | |
| 352 | +            } catch (Throwable $e) { | |
| 353 | + $appId = $registration->getAppId(); | |
| 354 | + $this->logger->logException($e, [ | |
| 355 | + 'message' => "Error during event listener registration of $appId: " . $e->getMessage(), | |
| 356 | + 'level' => ILogger::ERROR, | |
| 357 | + ]); | |
| 358 | + } | |
| 359 | + } | |
| 360 | + } | |
| 361 | + | |
| 362 | + /** | |
| 363 | + * @param App[] $apps | |
| 364 | + */ | |
| 365 | +    public function delegateContainerRegistrations(array $apps): void { | |
| 366 | +        while (($registration = array_shift($this->services)) !== null) { | |
| 367 | +            try { | |
| 368 | + /** | |
| 369 | + * Register the service and convert the callable into a \Closure if necessary | |
| 370 | + */ | |
| 371 | + $apps[$registration->getAppId()] | |
| 372 | + ->getContainer() | |
| 373 | + ->registerService( | |
| 374 | + $registration->getName(), | |
| 375 | + Closure::fromCallable($registration->getFactory()), | |
| 376 | + $registration->isShared() | |
| 377 | + ); | |
| 378 | +            } catch (Throwable $e) { | |
| 379 | + $appId = $registration->getAppId(); | |
| 380 | + $this->logger->logException($e, [ | |
| 381 | + 'message' => "Error during service registration of $appId: " . $e->getMessage(), | |
| 382 | + 'level' => ILogger::ERROR, | |
| 383 | + ]); | |
| 384 | + } | |
| 385 | + } | |
| 386 | + | |
| 387 | +        while (($registration = array_shift($this->aliases)) !== null) { | |
| 388 | +            try { | |
| 389 | + $apps[$registration->getAppId()] | |
| 390 | + ->getContainer() | |
| 391 | + ->registerAlias( | |
| 392 | + $registration->getAlias(), | |
| 393 | + $registration->getTarget() | |
| 394 | + ); | |
| 395 | +            } catch (Throwable $e) { | |
| 396 | + $appId = $registration->getAppId(); | |
| 397 | + $this->logger->logException($e, [ | |
| 398 | + 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), | |
| 399 | + 'level' => ILogger::ERROR, | |
| 400 | + ]); | |
| 401 | + } | |
| 402 | + } | |
| 403 | + | |
| 404 | +        while (($registration = array_shift($this->parameters)) !== null) { | |
| 405 | +            try { | |
| 406 | + $apps[$registration->getAppId()] | |
| 407 | + ->getContainer() | |
| 408 | + ->registerParameter( | |
| 409 | + $registration->getName(), | |
| 410 | + $registration->getValue() | |
| 411 | + ); | |
| 412 | +            } catch (Throwable $e) { | |
| 413 | + $appId = $registration->getAppId(); | |
| 414 | + $this->logger->logException($e, [ | |
| 415 | + 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), | |
| 416 | + 'level' => ILogger::ERROR, | |
| 417 | + ]); | |
| 418 | + } | |
| 419 | + } | |
| 420 | + } | |
| 421 | + | |
| 422 | + /** | |
| 423 | + * @param App[] $apps | |
| 424 | + */ | |
| 425 | +    public function delegateMiddlewareRegistrations(array $apps): void { | |
| 426 | +        while (($middleware = array_shift($this->middlewares)) !== null) { | |
| 427 | +            try { | |
| 428 | + $apps[$middleware->getAppId()] | |
| 429 | + ->getContainer() | |
| 430 | + ->registerMiddleWare($middleware->getService()); | |
| 431 | +            } catch (Throwable $e) { | |
| 432 | + $appId = $middleware->getAppId(); | |
| 433 | + $this->logger->logException($e, [ | |
| 434 | + 'message' => "Error during capability registration of $appId: " . $e->getMessage(), | |
| 435 | + 'level' => ILogger::ERROR, | |
| 436 | + ]); | |
| 437 | + } | |
| 438 | + } | |
| 439 | + } | |
| 440 | + | |
| 441 | + /** | |
| 442 | + * @return ServiceRegistration<IProvider>[] | |
| 443 | + */ | |
| 444 | +    public function getSearchProviders(): array { | |
| 445 | + return $this->searchProviders; | |
| 446 | + } | |
| 447 | + | |
| 448 | + /** | |
| 449 | + * @return ServiceRegistration<IAlternativeLogin>[] | |
| 450 | + */ | |
| 451 | +    public function getAlternativeLogins(): array { | |
| 452 | + return $this->alternativeLogins; | |
| 453 | + } | |
| 454 | + | |
| 455 | + /** | |
| 456 | + * @return ServiceRegistration<InitialStateProvider>[] | |
| 457 | + */ | |
| 458 | +    public function getInitialStates(): array { | |
| 459 | + return $this->initialStates; | |
| 460 | + } | |
| 461 | + | |
| 462 | + /** | |
| 463 | + * @return ServiceRegistration<IHandler>[] | |
| 464 | + */ | |
| 465 | +    public function getWellKnownHandlers(): array { | |
| 466 | + return $this->wellKnownHandlers; | |
| 467 | + } | |
| 468 | + | |
| 469 | + /** | |
| 470 | + * @return ServiceRegistration<ICustomTemplateProvider>[] | |
| 471 | + */ | |
| 472 | +    public function getTemplateProviders(): array { | |
| 473 | + return $this->templateProviders; | |
| 474 | + } | |
| 475 | + | |
| 476 | + /** | |
| 477 | + * @return ServiceRegistration<INotifier>[] | |
| 478 | + */ | |
| 479 | +    public function getNotifierServices(): array { | |
| 480 | + return $this->notifierServices; | |
| 481 | + } | |
| 482 | 482 | } | 
| @@ -32,80 +32,80 @@ | ||
| 32 | 32 | * @since 9.0.0 | 
| 33 | 33 | */ | 
| 34 | 34 |  interface IManager extends IApp, INotifier { | 
| 35 | - /** | |
| 36 | - * @param string $appClass The service must implement IApp, otherwise a | |
| 37 | - * \InvalidArgumentException is thrown later | |
| 38 | - * @since 17.0.0 | |
| 39 | - */ | |
| 40 | - public function registerApp(string $appClass): void; | |
| 35 | + /** | |
| 36 | + * @param string $appClass The service must implement IApp, otherwise a | |
| 37 | + * \InvalidArgumentException is thrown later | |
| 38 | + * @since 17.0.0 | |
| 39 | + */ | |
| 40 | + public function registerApp(string $appClass): void; | |
| 41 | 41 | |
| 42 | - /** | |
| 43 | - * @param \Closure $service The service must implement INotifier, otherwise a | |
| 44 | - * \InvalidArgumentException is thrown later | |
| 45 | - * @param \Closure $info An array with the keys 'id' and 'name' containing | |
| 46 | - * the app id and the app name | |
| 47 | - * @deprecated 17.0.0 use registerNotifierService instead. | |
| 48 | - * @since 8.2.0 - Parameter $info was added in 9.0.0 | |
| 49 | - */ | |
| 50 | - public function registerNotifier(\Closure $service, \Closure $info); | |
| 42 | + /** | |
| 43 | + * @param \Closure $service The service must implement INotifier, otherwise a | |
| 44 | + * \InvalidArgumentException is thrown later | |
| 45 | + * @param \Closure $info An array with the keys 'id' and 'name' containing | |
| 46 | + * the app id and the app name | |
| 47 | + * @deprecated 17.0.0 use registerNotifierService instead. | |
| 48 | + * @since 8.2.0 - Parameter $info was added in 9.0.0 | |
| 49 | + */ | |
| 50 | + public function registerNotifier(\Closure $service, \Closure $info); | |
| 51 | 51 | |
| 52 | - /** | |
| 53 | - * @param string $notifierService The service must implement INotifier, otherwise a | |
| 54 | - * \InvalidArgumentException is thrown later | |
| 55 | - * @since 17.0.0 | |
| 56 | - * @depreacted 22.0.0 use the IBootStrap registration context | |
| 57 | - */ | |
| 58 | - public function registerNotifierService(string $notifierService): void; | |
| 52 | + /** | |
| 53 | + * @param string $notifierService The service must implement INotifier, otherwise a | |
| 54 | + * \InvalidArgumentException is thrown later | |
| 55 | + * @since 17.0.0 | |
| 56 | + * @depreacted 22.0.0 use the IBootStrap registration context | |
| 57 | + */ | |
| 58 | + public function registerNotifierService(string $notifierService): void; | |
| 59 | 59 | |
| 60 | - /** | |
| 61 | - * @return INotifier[] | |
| 62 | - * @since 9.0.0 | |
| 63 | - */ | |
| 64 | - public function getNotifiers(): array; | |
| 60 | + /** | |
| 61 | + * @return INotifier[] | |
| 62 | + * @since 9.0.0 | |
| 63 | + */ | |
| 64 | + public function getNotifiers(): array; | |
| 65 | 65 | |
| 66 | - /** | |
| 67 | - * @return INotification | |
| 68 | - * @since 9.0.0 | |
| 69 | - */ | |
| 70 | - public function createNotification(): INotification; | |
| 66 | + /** | |
| 67 | + * @return INotification | |
| 68 | + * @since 9.0.0 | |
| 69 | + */ | |
| 70 | + public function createNotification(): INotification; | |
| 71 | 71 | |
| 72 | - /** | |
| 73 | - * @return bool | |
| 74 | - * @since 9.0.0 | |
| 75 | - */ | |
| 76 | - public function hasNotifiers(): bool; | |
| 72 | + /** | |
| 73 | + * @return bool | |
| 74 | + * @since 9.0.0 | |
| 75 | + */ | |
| 76 | + public function hasNotifiers(): bool; | |
| 77 | 77 | |
| 78 | - /** | |
| 79 | - * @param bool $preparingPushNotification | |
| 80 | - * @since 14.0.0 | |
| 81 | - */ | |
| 82 | - public function setPreparingPushNotification(bool $preparingPushNotification): void; | |
| 78 | + /** | |
| 79 | + * @param bool $preparingPushNotification | |
| 80 | + * @since 14.0.0 | |
| 81 | + */ | |
| 82 | + public function setPreparingPushNotification(bool $preparingPushNotification): void; | |
| 83 | 83 | |
| 84 | - /** | |
| 85 | - * @return bool | |
| 86 | - * @since 14.0.0 | |
| 87 | - */ | |
| 88 | - public function isPreparingPushNotification(): bool; | |
| 84 | + /** | |
| 85 | + * @return bool | |
| 86 | + * @since 14.0.0 | |
| 87 | + */ | |
| 88 | + public function isPreparingPushNotification(): bool; | |
| 89 | 89 | |
| 90 | - /** | |
| 91 | - * @since 18.0.0 | |
| 92 | - */ | |
| 93 | - public function dismissNotification(INotification $notification): void; | |
| 90 | + /** | |
| 91 | + * @since 18.0.0 | |
| 92 | + */ | |
| 93 | + public function dismissNotification(INotification $notification): void; | |
| 94 | 94 | |
| 95 | - /** | |
| 96 | - * Start deferring notifications until `flush()` is called | |
| 97 | - * | |
| 98 | - * The calling app should only "flush" when it got returned true on the defer call, | |
| 99 | - * otherwise another app is deferring the sending already. | |
| 100 | - * @return bool | |
| 101 | - * @since 20.0.0 | |
| 102 | - */ | |
| 103 | - public function defer(): bool; | |
| 95 | + /** | |
| 96 | + * Start deferring notifications until `flush()` is called | |
| 97 | + * | |
| 98 | + * The calling app should only "flush" when it got returned true on the defer call, | |
| 99 | + * otherwise another app is deferring the sending already. | |
| 100 | + * @return bool | |
| 101 | + * @since 20.0.0 | |
| 102 | + */ | |
| 103 | + public function defer(): bool; | |
| 104 | 104 | |
| 105 | - /** | |
| 106 | - * Send all deferred notifications that have been stored since `defer()` was called | |
| 107 | - * | |
| 108 | - * @since 20.0.0 | |
| 109 | - */ | |
| 110 | - public function flush(): void; | |
| 105 | + /** | |
| 106 | + * Send all deferred notifications that have been stored since `defer()` was called | |
| 107 | + * | |
| 108 | + * @since 20.0.0 | |
| 109 | + */ | |
| 110 | + public function flush(): void; | |
| 111 | 111 | } | 
| @@ -44,179 +44,179 @@ | ||
| 44 | 44 | */ | 
| 45 | 45 |  interface IRegistrationContext { | 
| 46 | 46 | |
| 47 | - /** | |
| 48 | - * @param string $capability | |
| 49 | - * @psalm-param class-string<ICapability> $capability | |
| 50 | - * @see IAppContainer::registerCapability | |
| 51 | - * | |
| 52 | - * @since 20.0.0 | |
| 53 | - */ | |
| 54 | - public function registerCapability(string $capability): void; | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * Register an implementation of \OCP\Support\CrashReport\IReporter that | |
| 58 | - * will receive unhandled exceptions and throwables | |
| 59 | - * | |
| 60 | - * @param string $reporterClass | |
| 61 | - * @psalm-param class-string<\OCP\Support\CrashReport\IReporter> $reporterClass | |
| 62 | - * @return void | |
| 63 | - * @since 20.0.0 | |
| 64 | - */ | |
| 65 | - public function registerCrashReporter(string $reporterClass): void; | |
| 66 | - | |
| 67 | - /** | |
| 68 | - * Register an implementation of \OCP\Dashboard\IWidget that | |
| 69 | - * will handle the implementation of a dashboard widget | |
| 70 | - * | |
| 71 | - * @param string $widgetClass | |
| 72 | - * @psalm-param class-string<\OCP\Dashboard\IWidget> $widgetClass | |
| 73 | - * @return void | |
| 74 | - * @since 20.0.0 | |
| 75 | - */ | |
| 76 | - public function registerDashboardWidget(string $widgetClass): void; | |
| 77 | - /** | |
| 78 | - * Register a service | |
| 79 | - * | |
| 80 | - * @param string $name | |
| 81 | - * @param callable $factory | |
| 82 | - * @psalm-param callable(\Psr\Container\ContainerInterface): mixed $factory | |
| 83 | - * @param bool $shared | |
| 84 | - * | |
| 85 | - * @return void | |
| 86 | - * @see IContainer::registerService() | |
| 87 | - * | |
| 88 | - * @since 20.0.0 | |
| 89 | - */ | |
| 90 | - public function registerService(string $name, callable $factory, bool $shared = true): void; | |
| 91 | - | |
| 92 | - /** | |
| 93 | - * @param string $alias | |
| 94 | - * @psalm-param string|class-string $alias | |
| 95 | - * @param string $target | |
| 96 | - * @psalm-param string|class-string $target | |
| 97 | - * | |
| 98 | - * @return void | |
| 99 | - * @see IContainer::registerAlias() | |
| 100 | - * | |
| 101 | - * @since 20.0.0 | |
| 102 | - */ | |
| 103 | - public function registerServiceAlias(string $alias, string $target): void; | |
| 104 | - | |
| 105 | - /** | |
| 106 | - * @param string $name | |
| 107 | - * @param mixed $value | |
| 108 | - * | |
| 109 | - * @return void | |
| 110 | - * @see IContainer::registerParameter() | |
| 111 | - * | |
| 112 | - * @since 20.0.0 | |
| 113 | - */ | |
| 114 | - public function registerParameter(string $name, $value): void; | |
| 115 | - | |
| 116 | - /** | |
| 117 | - * Register a service listener | |
| 118 | - * | |
| 119 | - * This is equivalent to calling IEventDispatcher::addServiceListener | |
| 120 | - * | |
| 121 | - * @template T of \OCP\EventDispatcher\Event | |
| 122 | - * @param string $event preferably the fully-qualified class name of the Event sub class to listen for | |
| 123 | - * @psalm-param string|class-string<T> $event preferably the fully-qualified class name of the Event sub class to listen for | |
| 124 | - * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container | |
| 125 | - * @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $listener fully qualified class name that can be built by the DI container | |
| 126 | - * @param int $priority The higher this value, the earlier an event | |
| 127 | - * listener will be triggered in the chain (defaults to 0) | |
| 128 | - * | |
| 129 | - * @see IEventDispatcher::addServiceListener() | |
| 130 | - * | |
| 131 | - * @since 20.0.0 | |
| 132 | - */ | |
| 133 | - public function registerEventListener(string $event, string $listener, int $priority = 0): void; | |
| 134 | - | |
| 135 | - /** | |
| 136 | - * @param string $class | |
| 137 | - * @psalm-param class-string<\OCP\AppFramework\Middleware> $class | |
| 138 | - * | |
| 139 | - * @return void | |
| 140 | - * @see IAppContainer::registerMiddleWare() | |
| 141 | - * | |
| 142 | - * @since 20.0.0 | |
| 143 | - */ | |
| 144 | - public function registerMiddleware(string $class): void; | |
| 145 | - | |
| 146 | - /** | |
| 147 | - * Register a search provider for the unified search | |
| 148 | - * | |
| 149 | - * It is allowed to register more than one provider per app as the search | |
| 150 | - * results can go into distinct sections, e.g. "Files" and "Files shared | |
| 151 | - * with you" in the Files app. | |
| 152 | - * | |
| 153 | - * @param string $class | |
| 154 | - * @psalm-param class-string<\OCP\Search\IProvider> $class | |
| 155 | - * | |
| 156 | - * @return void | |
| 157 | - * | |
| 158 | - * @since 20.0.0 | |
| 159 | - */ | |
| 160 | - public function registerSearchProvider(string $class): void; | |
| 161 | - | |
| 162 | - /** | |
| 163 | - * Register an alternative login option | |
| 164 | - * | |
| 165 | - * It is allowed to register more than one option per app. | |
| 166 | - * | |
| 167 | - * @param string $class | |
| 168 | - * @psalm-param class-string<\OCP\Authentication\IAlternativeLogin> $class | |
| 169 | - * | |
| 170 | - * @return void | |
| 171 | - * | |
| 172 | - * @since 20.0.0 | |
| 173 | - */ | |
| 174 | - public function registerAlternativeLogin(string $class): void; | |
| 175 | - | |
| 176 | - /** | |
| 177 | - * Register an initialstate provider | |
| 178 | - * | |
| 179 | - * It is allowed to register more than one provider per app. | |
| 180 | - * | |
| 181 | - * @param string $class | |
| 182 | - * @psalm-param class-string<\OCP\AppFramework\Services\InitialStateProvider> $class | |
| 183 | - * | |
| 184 | - * @return void | |
| 185 | - * | |
| 186 | - * @since 21.0.0 | |
| 187 | - */ | |
| 188 | - public function registerInitialStateProvider(string $class): void; | |
| 189 | - | |
| 190 | - /** | |
| 191 | - * Register a well known protocol handler | |
| 192 | - * | |
| 193 | - * It is allowed to register more than one handler per app. | |
| 194 | - * | |
| 195 | - * @param string $class | |
| 196 | - * @psalm-param class-string<\OCP\Http\WellKnown\IHandler> $class | |
| 197 | - * | |
| 198 | - * @return void | |
| 199 | - * | |
| 200 | - * @since 21.0.0 | |
| 201 | - */ | |
| 202 | - public function registerWellKnownHandler(string $class): void; | |
| 203 | - | |
| 204 | - /** | |
| 205 | - * Register a custom template provider class that is able to inject custom templates | |
| 206 | - * in addition to the user defined ones | |
| 207 | - * | |
| 208 | - * @param string $providerClass | |
| 209 | - * @psalm-param class-string<ICustomTemplateProvider> $providerClass | |
| 210 | - * @since 21.0.0 | |
| 211 | - */ | |
| 212 | - public function registerTemplateProvider(string $providerClass): void; | |
| 213 | - | |
| 214 | - /** | |
| 215 | - * Register an INotifier class | |
| 216 | - * | |
| 217 | - * @param string $notifierClass | |
| 218 | - * @psalm-param class-string<INotifier> $notifierClass | |
| 219 | - * @since 22.0.0 | |
| 220 | - */ | |
| 221 | - public function registerNotifierService(string $notifierClass): void; | |
| 47 | + /** | |
| 48 | + * @param string $capability | |
| 49 | + * @psalm-param class-string<ICapability> $capability | |
| 50 | + * @see IAppContainer::registerCapability | |
| 51 | + * | |
| 52 | + * @since 20.0.0 | |
| 53 | + */ | |
| 54 | + public function registerCapability(string $capability): void; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Register an implementation of \OCP\Support\CrashReport\IReporter that | |
| 58 | + * will receive unhandled exceptions and throwables | |
| 59 | + * | |
| 60 | + * @param string $reporterClass | |
| 61 | + * @psalm-param class-string<\OCP\Support\CrashReport\IReporter> $reporterClass | |
| 62 | + * @return void | |
| 63 | + * @since 20.0.0 | |
| 64 | + */ | |
| 65 | + public function registerCrashReporter(string $reporterClass): void; | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * Register an implementation of \OCP\Dashboard\IWidget that | |
| 69 | + * will handle the implementation of a dashboard widget | |
| 70 | + * | |
| 71 | + * @param string $widgetClass | |
| 72 | + * @psalm-param class-string<\OCP\Dashboard\IWidget> $widgetClass | |
| 73 | + * @return void | |
| 74 | + * @since 20.0.0 | |
| 75 | + */ | |
| 76 | + public function registerDashboardWidget(string $widgetClass): void; | |
| 77 | + /** | |
| 78 | + * Register a service | |
| 79 | + * | |
| 80 | + * @param string $name | |
| 81 | + * @param callable $factory | |
| 82 | + * @psalm-param callable(\Psr\Container\ContainerInterface): mixed $factory | |
| 83 | + * @param bool $shared | |
| 84 | + * | |
| 85 | + * @return void | |
| 86 | + * @see IContainer::registerService() | |
| 87 | + * | |
| 88 | + * @since 20.0.0 | |
| 89 | + */ | |
| 90 | + public function registerService(string $name, callable $factory, bool $shared = true): void; | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * @param string $alias | |
| 94 | + * @psalm-param string|class-string $alias | |
| 95 | + * @param string $target | |
| 96 | + * @psalm-param string|class-string $target | |
| 97 | + * | |
| 98 | + * @return void | |
| 99 | + * @see IContainer::registerAlias() | |
| 100 | + * | |
| 101 | + * @since 20.0.0 | |
| 102 | + */ | |
| 103 | + public function registerServiceAlias(string $alias, string $target): void; | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * @param string $name | |
| 107 | + * @param mixed $value | |
| 108 | + * | |
| 109 | + * @return void | |
| 110 | + * @see IContainer::registerParameter() | |
| 111 | + * | |
| 112 | + * @since 20.0.0 | |
| 113 | + */ | |
| 114 | + public function registerParameter(string $name, $value): void; | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * Register a service listener | |
| 118 | + * | |
| 119 | + * This is equivalent to calling IEventDispatcher::addServiceListener | |
| 120 | + * | |
| 121 | + * @template T of \OCP\EventDispatcher\Event | |
| 122 | + * @param string $event preferably the fully-qualified class name of the Event sub class to listen for | |
| 123 | + * @psalm-param string|class-string<T> $event preferably the fully-qualified class name of the Event sub class to listen for | |
| 124 | + * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container | |
| 125 | + * @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $listener fully qualified class name that can be built by the DI container | |
| 126 | + * @param int $priority The higher this value, the earlier an event | |
| 127 | + * listener will be triggered in the chain (defaults to 0) | |
| 128 | + * | |
| 129 | + * @see IEventDispatcher::addServiceListener() | |
| 130 | + * | |
| 131 | + * @since 20.0.0 | |
| 132 | + */ | |
| 133 | + public function registerEventListener(string $event, string $listener, int $priority = 0): void; | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * @param string $class | |
| 137 | + * @psalm-param class-string<\OCP\AppFramework\Middleware> $class | |
| 138 | + * | |
| 139 | + * @return void | |
| 140 | + * @see IAppContainer::registerMiddleWare() | |
| 141 | + * | |
| 142 | + * @since 20.0.0 | |
| 143 | + */ | |
| 144 | + public function registerMiddleware(string $class): void; | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * Register a search provider for the unified search | |
| 148 | + * | |
| 149 | + * It is allowed to register more than one provider per app as the search | |
| 150 | + * results can go into distinct sections, e.g. "Files" and "Files shared | |
| 151 | + * with you" in the Files app. | |
| 152 | + * | |
| 153 | + * @param string $class | |
| 154 | + * @psalm-param class-string<\OCP\Search\IProvider> $class | |
| 155 | + * | |
| 156 | + * @return void | |
| 157 | + * | |
| 158 | + * @since 20.0.0 | |
| 159 | + */ | |
| 160 | + public function registerSearchProvider(string $class): void; | |
| 161 | + | |
| 162 | + /** | |
| 163 | + * Register an alternative login option | |
| 164 | + * | |
| 165 | + * It is allowed to register more than one option per app. | |
| 166 | + * | |
| 167 | + * @param string $class | |
| 168 | + * @psalm-param class-string<\OCP\Authentication\IAlternativeLogin> $class | |
| 169 | + * | |
| 170 | + * @return void | |
| 171 | + * | |
| 172 | + * @since 20.0.0 | |
| 173 | + */ | |
| 174 | + public function registerAlternativeLogin(string $class): void; | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * Register an initialstate provider | |
| 178 | + * | |
| 179 | + * It is allowed to register more than one provider per app. | |
| 180 | + * | |
| 181 | + * @param string $class | |
| 182 | + * @psalm-param class-string<\OCP\AppFramework\Services\InitialStateProvider> $class | |
| 183 | + * | |
| 184 | + * @return void | |
| 185 | + * | |
| 186 | + * @since 21.0.0 | |
| 187 | + */ | |
| 188 | + public function registerInitialStateProvider(string $class): void; | |
| 189 | + | |
| 190 | + /** | |
| 191 | + * Register a well known protocol handler | |
| 192 | + * | |
| 193 | + * It is allowed to register more than one handler per app. | |
| 194 | + * | |
| 195 | + * @param string $class | |
| 196 | + * @psalm-param class-string<\OCP\Http\WellKnown\IHandler> $class | |
| 197 | + * | |
| 198 | + * @return void | |
| 199 | + * | |
| 200 | + * @since 21.0.0 | |
| 201 | + */ | |
| 202 | + public function registerWellKnownHandler(string $class): void; | |
| 203 | + | |
| 204 | + /** | |
| 205 | + * Register a custom template provider class that is able to inject custom templates | |
| 206 | + * in addition to the user defined ones | |
| 207 | + * | |
| 208 | + * @param string $providerClass | |
| 209 | + * @psalm-param class-string<ICustomTemplateProvider> $providerClass | |
| 210 | + * @since 21.0.0 | |
| 211 | + */ | |
| 212 | + public function registerTemplateProvider(string $providerClass): void; | |
| 213 | + | |
| 214 | + /** | |
| 215 | + * Register an INotifier class | |
| 216 | + * | |
| 217 | + * @param string $notifierClass | |
| 218 | + * @psalm-param class-string<INotifier> $notifierClass | |
| 219 | + * @since 22.0.0 | |
| 220 | + */ | |
| 221 | + public function registerNotifierService(string $notifierClass): void; | |
| 222 | 222 | } | 
| @@ -49,45 +49,45 @@ | ||
| 49 | 49 | use OCP\IServerContainer; | 
| 50 | 50 | |
| 51 | 51 |  class Application extends App implements IBootstrap { | 
| 52 | - public const APP_ID = 'comments'; | |
| 52 | + public const APP_ID = 'comments'; | |
| 53 | 53 | |
| 54 | -	public function __construct(array $urlParams = []) { | |
| 55 | - parent::__construct(self::APP_ID, $urlParams); | |
| 56 | - } | |
| 54 | +    public function __construct(array $urlParams = []) { | |
| 55 | + parent::__construct(self::APP_ID, $urlParams); | |
| 56 | + } | |
| 57 | 57 | |
| 58 | -	public function register(IRegistrationContext $context): void { | |
| 59 | - $context->registerCapability(Capabilities::class); | |
| 58 | +    public function register(IRegistrationContext $context): void { | |
| 59 | + $context->registerCapability(Capabilities::class); | |
| 60 | 60 | |
| 61 | -		$context->registerServiceAlias('NotificationsController', Notifications::class); | |
| 61 | +        $context->registerServiceAlias('NotificationsController', Notifications::class); | |
| 62 | 62 | |
| 63 | - $context->registerEventListener( | |
| 64 | - LoadAdditionalScriptsEvent::class, | |
| 65 | - LoadAdditionalScripts::class | |
| 66 | - ); | |
| 67 | - $context->registerEventListener( | |
| 68 | - LoadSidebar::class, | |
| 69 | - LoadSidebarScripts::class | |
| 70 | - ); | |
| 71 | - $context->registerEventListener( | |
| 72 | - CommentsEntityEvent::EVENT_ENTITY, | |
| 73 | - CommentsEntityEventListener::class | |
| 74 | - ); | |
| 75 | - $context->registerSearchProvider(CommentsSearchProvider::class); | |
| 63 | + $context->registerEventListener( | |
| 64 | + LoadAdditionalScriptsEvent::class, | |
| 65 | + LoadAdditionalScripts::class | |
| 66 | + ); | |
| 67 | + $context->registerEventListener( | |
| 68 | + LoadSidebar::class, | |
| 69 | + LoadSidebarScripts::class | |
| 70 | + ); | |
| 71 | + $context->registerEventListener( | |
| 72 | + CommentsEntityEvent::EVENT_ENTITY, | |
| 73 | + CommentsEntityEventListener::class | |
| 74 | + ); | |
| 75 | + $context->registerSearchProvider(CommentsSearchProvider::class); | |
| 76 | 76 | |
| 77 | - $context->registerInitialStateProvider(MaxAutoCompleteResultsInitialState::class); | |
| 77 | + $context->registerInitialStateProvider(MaxAutoCompleteResultsInitialState::class); | |
| 78 | 78 | |
| 79 | - $context->registerNotifierService(Notifier::class); | |
| 80 | - } | |
| 79 | + $context->registerNotifierService(Notifier::class); | |
| 80 | + } | |
| 81 | 81 | |
| 82 | -	public function boot(IBootContext $context): void { | |
| 83 | - $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler'])); | |
| 82 | +    public function boot(IBootContext $context): void { | |
| 83 | + $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler'])); | |
| 84 | 84 | |
| 85 | - $context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]); | |
| 86 | - } | |
| 85 | + $context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]); | |
| 86 | + } | |
| 87 | 87 | |
| 88 | -	protected function registerCommentsEventHandler(IServerContainer $container) { | |
| 89 | -		$container->getCommentsManager()->registerEventHandler(function () { | |
| 90 | - return $this->getContainer()->query(EventHandler::class); | |
| 91 | - }); | |
| 92 | - } | |
| 88 | +    protected function registerCommentsEventHandler(IServerContainer $container) { | |
| 89 | +        $container->getCommentsManager()->registerEventHandler(function () { | |
| 90 | + return $this->getContainer()->query(EventHandler::class); | |
| 91 | + }); | |
| 92 | + } | |
| 93 | 93 | } | 
| @@ -66,117 +66,117 @@ | ||
| 66 | 66 | use Psr\Container\ContainerInterface; | 
| 67 | 67 | |
| 68 | 68 |  class Application extends App implements IBootstrap { | 
| 69 | - public const APP_ID = 'files'; | |
| 70 | - | |
| 71 | -	public function __construct(array $urlParams = []) { | |
| 72 | - parent::__construct(self::APP_ID, $urlParams); | |
| 73 | - } | |
| 74 | - | |
| 75 | -	public function register(IRegistrationContext $context): void { | |
| 76 | - /** | |
| 77 | - * Controllers | |
| 78 | - */ | |
| 79 | -		$context->registerService('APIController', function (ContainerInterface $c) { | |
| 80 | - /** @var IServerContainer $server */ | |
| 81 | - $server = $c->get(IServerContainer::class); | |
| 82 | - | |
| 83 | - return new ApiController( | |
| 84 | -				$c->get('AppName'), | |
| 85 | - $c->get(IRequest::class), | |
| 86 | - $c->get(IUserSession::class), | |
| 87 | - $c->get(TagService::class), | |
| 88 | - $c->get(IPreview::class), | |
| 89 | - $c->get(IShareManager::class), | |
| 90 | - $c->get(IConfig::class), | |
| 91 | - $server->getUserFolder() | |
| 92 | - ); | |
| 93 | - }); | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * Services | |
| 97 | - */ | |
| 98 | -		$context->registerService(TagService::class, function (ContainerInterface $c) { | |
| 99 | - /** @var IServerContainer $server */ | |
| 100 | - $server = $c->get(IServerContainer::class); | |
| 101 | - | |
| 102 | - return new TagService( | |
| 103 | - $c->get(IUserSession::class), | |
| 104 | - $c->get(IActivityManager::class), | |
| 105 | - $c->get(ITagManager::class)->load(self::APP_ID), | |
| 106 | - $server->getUserFolder(), | |
| 107 | - $server->getEventDispatcher() | |
| 108 | - ); | |
| 109 | - }); | |
| 110 | - | |
| 111 | - /* | |
| 69 | + public const APP_ID = 'files'; | |
| 70 | + | |
| 71 | +    public function __construct(array $urlParams = []) { | |
| 72 | + parent::__construct(self::APP_ID, $urlParams); | |
| 73 | + } | |
| 74 | + | |
| 75 | +    public function register(IRegistrationContext $context): void { | |
| 76 | + /** | |
| 77 | + * Controllers | |
| 78 | + */ | |
| 79 | +        $context->registerService('APIController', function (ContainerInterface $c) { | |
| 80 | + /** @var IServerContainer $server */ | |
| 81 | + $server = $c->get(IServerContainer::class); | |
| 82 | + | |
| 83 | + return new ApiController( | |
| 84 | +                $c->get('AppName'), | |
| 85 | + $c->get(IRequest::class), | |
| 86 | + $c->get(IUserSession::class), | |
| 87 | + $c->get(TagService::class), | |
| 88 | + $c->get(IPreview::class), | |
| 89 | + $c->get(IShareManager::class), | |
| 90 | + $c->get(IConfig::class), | |
| 91 | + $server->getUserFolder() | |
| 92 | + ); | |
| 93 | + }); | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Services | |
| 97 | + */ | |
| 98 | +        $context->registerService(TagService::class, function (ContainerInterface $c) { | |
| 99 | + /** @var IServerContainer $server */ | |
| 100 | + $server = $c->get(IServerContainer::class); | |
| 101 | + | |
| 102 | + return new TagService( | |
| 103 | + $c->get(IUserSession::class), | |
| 104 | + $c->get(IActivityManager::class), | |
| 105 | + $c->get(ITagManager::class)->load(self::APP_ID), | |
| 106 | + $server->getUserFolder(), | |
| 107 | + $server->getEventDispatcher() | |
| 108 | + ); | |
| 109 | + }); | |
| 110 | + | |
| 111 | + /* | |
| 112 | 112 | * Register capabilities | 
| 113 | 113 | */ | 
| 114 | - $context->registerCapability(Capabilities::class); | |
| 115 | - | |
| 116 | - $context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class); | |
| 117 | - $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class); | |
| 118 | - | |
| 119 | - $context->registerSearchProvider(FilesSearchProvider::class); | |
| 120 | - | |
| 121 | - $context->registerNotifierService(Notifier::class); | |
| 122 | - } | |
| 123 | - | |
| 124 | -	public function boot(IBootContext $context): void { | |
| 125 | - $context->injectFn(Closure::fromCallable([$this, 'registerCollaboration'])); | |
| 126 | - $context->injectFn([Listener::class, 'register']); | |
| 127 | - $context->injectFn(Closure::fromCallable([$this, 'registerSearchProvider'])); | |
| 128 | - $this->registerTemplates(); | |
| 129 | - $context->injectFn(Closure::fromCallable([$this, 'registerNavigation'])); | |
| 130 | - $this->registerHooks(); | |
| 131 | - } | |
| 132 | - | |
| 133 | -	private function registerCollaboration(IProviderManager $providerManager): void { | |
| 134 | - $providerManager->registerResourceProvider(ResourceProvider::class); | |
| 135 | - } | |
| 136 | - | |
| 137 | -	private function registerSearchProvider(ISearch $search): void { | |
| 138 | - $search->registerProvider(File::class, ['apps' => ['files']]); | |
| 139 | - } | |
| 140 | - | |
| 141 | -	private function registerTemplates(): void { | |
| 142 | - $templateManager = \OC_Helper::getFileTemplateManager(); | |
| 143 | -		$templateManager->registerTemplate('application/vnd.oasis.opendocument.presentation', 'core/templates/filetemplates/template.odp'); | |
| 144 | -		$templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt'); | |
| 145 | -		$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods'); | |
| 146 | - } | |
| 147 | - | |
| 148 | -	private function registerNavigation(IL10N $l10n): void { | |
| 149 | -		\OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { | |
| 150 | - return [ | |
| 151 | - 'id' => 'files', | |
| 152 | - 'appname' => 'files', | |
| 153 | - 'script' => 'list.php', | |
| 154 | - 'order' => 0, | |
| 155 | -				'name' => $l10n->t('All files') | |
| 156 | - ]; | |
| 157 | - }); | |
| 158 | -		\OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { | |
| 159 | - return [ | |
| 160 | - 'id' => 'recent', | |
| 161 | - 'appname' => 'files', | |
| 162 | - 'script' => 'recentlist.php', | |
| 163 | - 'order' => 2, | |
| 164 | -				'name' => $l10n->t('Recent') | |
| 165 | - ]; | |
| 166 | - }); | |
| 167 | -		\OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { | |
| 168 | - return [ | |
| 169 | - 'id' => 'favorites', | |
| 170 | - 'appname' => 'files', | |
| 171 | - 'script' => 'simplelist.php', | |
| 172 | - 'order' => 5, | |
| 173 | -				'name' => $l10n->t('Favorites'), | |
| 174 | - 'expandedState' => 'show_Quick_Access' | |
| 175 | - ]; | |
| 176 | - }); | |
| 177 | - } | |
| 178 | - | |
| 179 | -	private function registerHooks(): void { | |
| 180 | -		Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig'); | |
| 181 | - } | |
| 114 | + $context->registerCapability(Capabilities::class); | |
| 115 | + | |
| 116 | + $context->registerEventListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class); | |
| 117 | + $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class); | |
| 118 | + | |
| 119 | + $context->registerSearchProvider(FilesSearchProvider::class); | |
| 120 | + | |
| 121 | + $context->registerNotifierService(Notifier::class); | |
| 122 | + } | |
| 123 | + | |
| 124 | +    public function boot(IBootContext $context): void { | |
| 125 | + $context->injectFn(Closure::fromCallable([$this, 'registerCollaboration'])); | |
| 126 | + $context->injectFn([Listener::class, 'register']); | |
| 127 | + $context->injectFn(Closure::fromCallable([$this, 'registerSearchProvider'])); | |
| 128 | + $this->registerTemplates(); | |
| 129 | + $context->injectFn(Closure::fromCallable([$this, 'registerNavigation'])); | |
| 130 | + $this->registerHooks(); | |
| 131 | + } | |
| 132 | + | |
| 133 | +    private function registerCollaboration(IProviderManager $providerManager): void { | |
| 134 | + $providerManager->registerResourceProvider(ResourceProvider::class); | |
| 135 | + } | |
| 136 | + | |
| 137 | +    private function registerSearchProvider(ISearch $search): void { | |
| 138 | + $search->registerProvider(File::class, ['apps' => ['files']]); | |
| 139 | + } | |
| 140 | + | |
| 141 | +    private function registerTemplates(): void { | |
| 142 | + $templateManager = \OC_Helper::getFileTemplateManager(); | |
| 143 | +        $templateManager->registerTemplate('application/vnd.oasis.opendocument.presentation', 'core/templates/filetemplates/template.odp'); | |
| 144 | +        $templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt'); | |
| 145 | +        $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods'); | |
| 146 | + } | |
| 147 | + | |
| 148 | +    private function registerNavigation(IL10N $l10n): void { | |
| 149 | +        \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { | |
| 150 | + return [ | |
| 151 | + 'id' => 'files', | |
| 152 | + 'appname' => 'files', | |
| 153 | + 'script' => 'list.php', | |
| 154 | + 'order' => 0, | |
| 155 | +                'name' => $l10n->t('All files') | |
| 156 | + ]; | |
| 157 | + }); | |
| 158 | +        \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { | |
| 159 | + return [ | |
| 160 | + 'id' => 'recent', | |
| 161 | + 'appname' => 'files', | |
| 162 | + 'script' => 'recentlist.php', | |
| 163 | + 'order' => 2, | |
| 164 | +                'name' => $l10n->t('Recent') | |
| 165 | + ]; | |
| 166 | + }); | |
| 167 | +        \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { | |
| 168 | + return [ | |
| 169 | + 'id' => 'favorites', | |
| 170 | + 'appname' => 'files', | |
| 171 | + 'script' => 'simplelist.php', | |
| 172 | + 'order' => 5, | |
| 173 | +                'name' => $l10n->t('Favorites'), | |
| 174 | + 'expandedState' => 'show_Quick_Access' | |
| 175 | + ]; | |
| 176 | + }); | |
| 177 | + } | |
| 178 | + | |
| 179 | +    private function registerHooks(): void { | |
| 180 | +        Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig'); | |
| 181 | + } | |
| 182 | 182 | } | 
| @@ -80,330 +80,330 @@ | ||
| 80 | 80 | use function strpos; | 
| 81 | 81 | |
| 82 | 82 |  class Application extends App implements IBootstrap { | 
| 83 | - public const APP_ID = 'dav'; | |
| 83 | + public const APP_ID = 'dav'; | |
| 84 | 84 | |
| 85 | -	public function __construct() { | |
| 86 | - parent::__construct(self::APP_ID); | |
| 87 | - } | |
| 85 | +    public function __construct() { | |
| 86 | + parent::__construct(self::APP_ID); | |
| 87 | + } | |
| 88 | 88 | |
| 89 | -	public function register(IRegistrationContext $context): void { | |
| 90 | -		$context->registerServiceAlias('CardDAVSyncService', SyncService::class); | |
| 91 | -		$context->registerService(PhotoCache::class, function (ContainerInterface $c) { | |
| 92 | - /** @var IServerContainer $server */ | |
| 93 | - $server = $c->get(IServerContainer::class); | |
| 89 | +    public function register(IRegistrationContext $context): void { | |
| 90 | +        $context->registerServiceAlias('CardDAVSyncService', SyncService::class); | |
| 91 | +        $context->registerService(PhotoCache::class, function (ContainerInterface $c) { | |
| 92 | + /** @var IServerContainer $server */ | |
| 93 | + $server = $c->get(IServerContainer::class); | |
| 94 | 94 | |
| 95 | - return new PhotoCache( | |
| 96 | -				$server->getAppDataDir('dav-photocache'), | |
| 97 | - $c->get(ILogger::class) | |
| 98 | - ); | |
| 99 | - }); | |
| 95 | + return new PhotoCache( | |
| 96 | +                $server->getAppDataDir('dav-photocache'), | |
| 97 | + $c->get(ILogger::class) | |
| 98 | + ); | |
| 99 | + }); | |
| 100 | 100 | |
| 101 | - /* | |
| 101 | + /* | |
| 102 | 102 | * Register capabilities | 
| 103 | 103 | */ | 
| 104 | - $context->registerCapability(Capabilities::class); | |
| 104 | + $context->registerCapability(Capabilities::class); | |
| 105 | 105 | |
| 106 | - /* | |
| 106 | + /* | |
| 107 | 107 | * Register Search Providers | 
| 108 | 108 | */ | 
| 109 | - $context->registerSearchProvider(ContactsSearchProvider::class); | |
| 110 | - $context->registerSearchProvider(EventsSearchProvider::class); | |
| 111 | - $context->registerSearchProvider(TasksSearchProvider::class); | |
| 112 | - | |
| 113 | - /** | |
| 114 | - * Register event listeners | |
| 115 | - */ | |
| 116 | - $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarContactInteractionListener::class); | |
| 117 | - $context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarContactInteractionListener::class); | |
| 118 | - $context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarContactInteractionListener::class); | |
| 119 | - | |
| 120 | - $context->registerNotifierService(Notifier::class); | |
| 121 | - } | |
| 122 | - | |
| 123 | -	public function boot(IBootContext $context): void { | |
| 124 | - // Load all dav apps | |
| 125 | - \OC_App::loadApps(['dav']); | |
| 126 | - | |
| 127 | - $context->injectFn([$this, 'registerHooks']); | |
| 128 | - $context->injectFn([$this, 'registerContactsManager']); | |
| 129 | - $context->injectFn([$this, 'registerCalendarManager']); | |
| 130 | - $context->injectFn([$this, 'registerCalendarReminders']); | |
| 131 | - } | |
| 132 | - | |
| 133 | - public function registerHooks(HookManager $hm, | |
| 134 | - EventDispatcherInterface $dispatcher, | |
| 135 | - IAppContainer $container, | |
| 136 | -								   IServerContainer $serverContainer) { | |
| 137 | - $hm->setup(); | |
| 138 | - | |
| 139 | - // first time login event setup | |
| 140 | -		$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { | |
| 141 | -			if ($event instanceof GenericEvent) { | |
| 142 | - $hm->firstLogin($event->getSubject()); | |
| 143 | - } | |
| 144 | - }); | |
| 145 | - | |
| 146 | -		$birthdayListener = function ($event) use ($container): void { | |
| 147 | -			if ($event instanceof GenericEvent) { | |
| 148 | - /** @var BirthdayService $b */ | |
| 149 | - $b = $container->query(BirthdayService::class); | |
| 150 | - $b->onCardChanged( | |
| 151 | -					(int) $event->getArgument('addressBookId'), | |
| 152 | -					(string) $event->getArgument('cardUri'), | |
| 153 | -					(string) $event->getArgument('cardData') | |
| 154 | - ); | |
| 155 | - } | |
| 156 | - }; | |
| 157 | - | |
| 158 | -		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener); | |
| 159 | -		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener); | |
| 160 | -		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) use ($container) { | |
| 161 | -			if ($event instanceof GenericEvent) { | |
| 162 | - /** @var BirthdayService $b */ | |
| 163 | - $b = $container->query(BirthdayService::class); | |
| 164 | - $b->onCardDeleted( | |
| 165 | -					(int) $event->getArgument('addressBookId'), | |
| 166 | -					(string) $event->getArgument('cardUri') | |
| 167 | - ); | |
| 168 | - } | |
| 169 | - }); | |
| 170 | - | |
| 171 | -		$clearPhotoCache = function ($event) use ($container): void { | |
| 172 | -			if ($event instanceof GenericEvent) { | |
| 173 | - /** @var PhotoCache $p */ | |
| 174 | - $p = $container->query(PhotoCache::class); | |
| 175 | - $p->delete( | |
| 176 | -					$event->getArgument('addressBookId'), | |
| 177 | -					$event->getArgument('cardUri') | |
| 178 | - ); | |
| 179 | - } | |
| 180 | - }; | |
| 181 | -		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); | |
| 182 | -		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); | |
| 183 | - | |
| 184 | -		$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($container) { | |
| 185 | - $user = $event->getSubject(); | |
| 186 | - /** @var SyncService $syncService */ | |
| 187 | - $syncService = $container->query(SyncService::class); | |
| 188 | - $syncService->updateUser($user); | |
| 189 | - }); | |
| 190 | - | |
| 191 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) use ($container) { | |
| 192 | - /** @var Backend $backend */ | |
| 193 | - $backend = $container->query(Backend::class); | |
| 194 | - $backend->onCalendarAdd( | |
| 195 | -				$event->getArgument('calendarData') | |
| 196 | - ); | |
| 197 | - }); | |
| 198 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) use ($container) { | |
| 199 | - /** @var Backend $backend */ | |
| 200 | - $backend = $container->query(Backend::class); | |
| 201 | - $backend->onCalendarUpdate( | |
| 202 | -				$event->getArgument('calendarData'), | |
| 203 | -				$event->getArgument('shares'), | |
| 204 | -				$event->getArgument('propertyMutations') | |
| 205 | - ); | |
| 206 | - }); | |
| 207 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) use ($container) { | |
| 208 | - /** @var Backend $backend */ | |
| 209 | - $backend = $container->query(Backend::class); | |
| 210 | - $backend->onCalendarDelete( | |
| 211 | -				$event->getArgument('calendarData'), | |
| 212 | -				$event->getArgument('shares') | |
| 213 | - ); | |
| 214 | - | |
| 215 | - /** @var ReminderBackend $reminderBackend */ | |
| 216 | - $reminderBackend = $container->query(ReminderBackend::class); | |
| 217 | - $reminderBackend->cleanRemindersForCalendar( | |
| 218 | -				(int) $event->getArgument('calendarId') | |
| 219 | - ); | |
| 220 | - }); | |
| 221 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) use ($container) { | |
| 222 | - /** @var Backend $backend */ | |
| 223 | - $backend = $container->query(Backend::class); | |
| 224 | - $backend->onCalendarUpdateShares( | |
| 225 | -				$event->getArgument('calendarData'), | |
| 226 | -				$event->getArgument('shares'), | |
| 227 | -				$event->getArgument('add'), | |
| 228 | -				$event->getArgument('remove') | |
| 229 | - ); | |
| 230 | - | |
| 231 | - // Here we should recalculate if reminders should be sent to new or old sharees | |
| 232 | - }); | |
| 233 | - | |
| 234 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) use ($container) { | |
| 235 | - /** @var Backend $backend */ | |
| 236 | - $backend = $container->query(Backend::class); | |
| 237 | - $backend->onCalendarPublication( | |
| 238 | -				$event->getArgument('calendarData'), | |
| 239 | -				$event->getArgument('public') | |
| 240 | - ); | |
| 241 | - }); | |
| 242 | - | |
| 243 | -		$listener = function (GenericEvent $event, $eventName) use ($container): void { | |
| 244 | - /** @var Backend $backend */ | |
| 245 | - $backend = $container->query(Backend::class); | |
| 246 | - | |
| 247 | - $subject = Event::SUBJECT_OBJECT_ADD; | |
| 248 | -			if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { | |
| 249 | - $subject = Event::SUBJECT_OBJECT_UPDATE; | |
| 250 | -			} elseif ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { | |
| 251 | - $subject = Event::SUBJECT_OBJECT_DELETE; | |
| 252 | - } | |
| 253 | - $backend->onTouchCalendarObject( | |
| 254 | - $subject, | |
| 255 | -				$event->getArgument('calendarData'), | |
| 256 | -				$event->getArgument('shares'), | |
| 257 | -				$event->getArgument('objectData') | |
| 258 | - ); | |
| 259 | - | |
| 260 | - /** @var ReminderService $reminderBackend */ | |
| 261 | - $reminderService = $container->query(ReminderService::class); | |
| 262 | - | |
| 263 | - $reminderService->onTouchCalendarObject( | |
| 264 | - $eventName, | |
| 265 | -				$event->getArgument('objectData') | |
| 266 | - ); | |
| 267 | - }; | |
| 268 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); | |
| 269 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); | |
| 270 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); | |
| 271 | - | |
| 272 | - /** | |
| 273 | - * In case the user has set their default calendar to this one | |
| 274 | - */ | |
| 275 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) use ($serverContainer) { | |
| 276 | - /** @var IConfig $config */ | |
| 277 | - $config = $serverContainer->getConfig(); | |
| 278 | -			$principalUri = $event->getArgument('calendarData')['principaluri']; | |
| 279 | -			if (strpos($principalUri, 'principals/users') === 0) { | |
| 280 | - [, $UID] = \Sabre\Uri\split($principalUri); | |
| 281 | -				$uri = $event->getArgument('calendarData')['uri']; | |
| 282 | -				if ($config->getUserValue($UID, 'dav', 'defaultCalendar') === $uri) { | |
| 283 | - $config->deleteUserValue($UID, 'dav', 'defaultCalendar'); | |
| 284 | - } | |
| 285 | - } | |
| 286 | - }); | |
| 287 | - | |
| 288 | -		$dispatcher->addListener('OCP\Federation\TrustedServerEvent::remove', | |
| 289 | -			function (GenericEvent $event) { | |
| 290 | - /** @var CardDavBackend $cardDavBackend */ | |
| 291 | - $cardDavBackend = \OC::$server->query(CardDavBackend::class); | |
| 292 | - $addressBookUri = $event->getSubject(); | |
| 293 | -				$addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri); | |
| 294 | -				if (!is_null($addressBook)) { | |
| 295 | - $cardDavBackend->deleteAddressBook($addressBook['id']); | |
| 296 | - } | |
| 297 | - } | |
| 298 | - ); | |
| 299 | - | |
| 300 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createSubscription', | |
| 301 | -			function (GenericEvent $event) use ($container, $serverContainer) { | |
| 302 | - $jobList = $serverContainer->getJobList(); | |
| 303 | -				$subscriptionData = $event->getArgument('subscriptionData'); | |
| 304 | - | |
| 305 | - /** | |
| 306 | - * Initial subscription refetch | |
| 307 | - * | |
| 308 | - * @var RefreshWebcalService $refreshWebcalService | |
| 309 | - */ | |
| 310 | - $refreshWebcalService = $container->query(RefreshWebcalService::class); | |
| 311 | - $refreshWebcalService->refreshSubscription( | |
| 312 | - (string) $subscriptionData['principaluri'], | |
| 313 | - (string) $subscriptionData['uri'] | |
| 314 | - ); | |
| 315 | - | |
| 316 | - $jobList->add(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [ | |
| 317 | - 'principaluri' => $subscriptionData['principaluri'], | |
| 318 | - 'uri' => $subscriptionData['uri'] | |
| 319 | - ]); | |
| 320 | - } | |
| 321 | - ); | |
| 322 | - | |
| 323 | -		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription', | |
| 324 | -			function (GenericEvent $event) use ($container, $serverContainer) { | |
| 325 | - $jobList = $serverContainer->getJobList(); | |
| 326 | -				$subscriptionData = $event->getArgument('subscriptionData'); | |
| 327 | - | |
| 328 | - $jobList->remove(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [ | |
| 329 | - 'principaluri' => $subscriptionData['principaluri'], | |
| 330 | - 'uri' => $subscriptionData['uri'] | |
| 331 | - ]); | |
| 332 | - | |
| 333 | - /** @var CalDavBackend $calDavBackend */ | |
| 334 | - $calDavBackend = $container->query(CalDavBackend::class); | |
| 335 | - $calDavBackend->purgeAllCachedEventsForSubscription($subscriptionData['id']); | |
| 336 | - } | |
| 337 | - ); | |
| 338 | - | |
| 339 | -		$eventHandler = function () use ($container, $serverContainer): void { | |
| 340 | -			try { | |
| 341 | - /** @var UpdateCalendarResourcesRoomsBackgroundJob $job */ | |
| 342 | - $job = $container->query(UpdateCalendarResourcesRoomsBackgroundJob::class); | |
| 343 | - $job->run([]); | |
| 344 | - $serverContainer->getJobList()->setLastRun($job); | |
| 345 | -			} catch (Exception $ex) { | |
| 346 | - $serverContainer->getLogger()->logException($ex); | |
| 347 | - } | |
| 348 | - }; | |
| 349 | - | |
| 350 | -		$dispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler); | |
| 351 | -		$dispatcher->addListener('\OCP\Calendar\Room\ForceRefreshEvent', $eventHandler); | |
| 352 | - } | |
| 353 | - | |
| 354 | -	public function registerContactsManager(IContactsManager $cm, IAppContainer $container): void { | |
| 355 | -		$cm->register(function () use ($container, $cm): void { | |
| 356 | - $user = \OC::$server->getUserSession()->getUser(); | |
| 357 | -			if (!is_null($user)) { | |
| 358 | - $this->setupContactsProvider($cm, $container, $user->getUID()); | |
| 359 | -			} else { | |
| 360 | - $this->setupSystemContactsProvider($cm, $container); | |
| 361 | - } | |
| 362 | - }); | |
| 363 | - } | |
| 364 | - | |
| 365 | - private function setupContactsProvider(IContactsManager $contactsManager, | |
| 366 | - IAppContainer $container, | |
| 367 | -										   string $userID): void { | |
| 368 | - /** @var ContactsManager $cm */ | |
| 369 | - $cm = $container->query(ContactsManager::class); | |
| 370 | - $urlGenerator = $container->getServer()->getURLGenerator(); | |
| 371 | - $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); | |
| 372 | - } | |
| 373 | - | |
| 374 | - private function setupSystemContactsProvider(IContactsManager $contactsManager, | |
| 375 | -												 IAppContainer $container): void { | |
| 376 | - /** @var ContactsManager $cm */ | |
| 377 | - $cm = $container->query(ContactsManager::class); | |
| 378 | - $urlGenerator = $container->getServer()->getURLGenerator(); | |
| 379 | - $cm->setupSystemContactsProvider($contactsManager, $urlGenerator); | |
| 380 | - } | |
| 381 | - | |
| 382 | - public function registerCalendarManager(ICalendarManager $calendarManager, | |
| 383 | -											 IAppContainer $container): void { | |
| 384 | -		$calendarManager->register(function () use ($container, $calendarManager) { | |
| 385 | - $user = \OC::$server->getUserSession()->getUser(); | |
| 386 | -			if ($user !== null) { | |
| 387 | - $this->setupCalendarProvider($calendarManager, $container, $user->getUID()); | |
| 388 | - } | |
| 389 | - }); | |
| 390 | - } | |
| 391 | - | |
| 392 | - private function setupCalendarProvider(ICalendarManager $calendarManager, | |
| 393 | - IAppContainer $container, | |
| 394 | -										   $userId) { | |
| 395 | - $cm = $container->query(CalendarManager::class); | |
| 396 | - $cm->setupCalendarProvider($calendarManager, $userId); | |
| 397 | - } | |
| 398 | - | |
| 399 | - public function registerCalendarReminders(NotificationProviderManager $manager, | |
| 400 | -											   ILogger $logger): void { | |
| 401 | -		try { | |
| 402 | - $manager->registerProvider(AudioProvider::class); | |
| 403 | - $manager->registerProvider(EmailProvider::class); | |
| 404 | - $manager->registerProvider(PushProvider::class); | |
| 405 | -		} catch (Throwable $ex) { | |
| 406 | - $logger->logException($ex); | |
| 407 | - } | |
| 408 | - } | |
| 109 | + $context->registerSearchProvider(ContactsSearchProvider::class); | |
| 110 | + $context->registerSearchProvider(EventsSearchProvider::class); | |
| 111 | + $context->registerSearchProvider(TasksSearchProvider::class); | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * Register event listeners | |
| 115 | + */ | |
| 116 | + $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarContactInteractionListener::class); | |
| 117 | + $context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarContactInteractionListener::class); | |
| 118 | + $context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarContactInteractionListener::class); | |
| 119 | + | |
| 120 | + $context->registerNotifierService(Notifier::class); | |
| 121 | + } | |
| 122 | + | |
| 123 | +    public function boot(IBootContext $context): void { | |
| 124 | + // Load all dav apps | |
| 125 | + \OC_App::loadApps(['dav']); | |
| 126 | + | |
| 127 | + $context->injectFn([$this, 'registerHooks']); | |
| 128 | + $context->injectFn([$this, 'registerContactsManager']); | |
| 129 | + $context->injectFn([$this, 'registerCalendarManager']); | |
| 130 | + $context->injectFn([$this, 'registerCalendarReminders']); | |
| 131 | + } | |
| 132 | + | |
| 133 | + public function registerHooks(HookManager $hm, | |
| 134 | + EventDispatcherInterface $dispatcher, | |
| 135 | + IAppContainer $container, | |
| 136 | +                                    IServerContainer $serverContainer) { | |
| 137 | + $hm->setup(); | |
| 138 | + | |
| 139 | + // first time login event setup | |
| 140 | +        $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { | |
| 141 | +            if ($event instanceof GenericEvent) { | |
| 142 | + $hm->firstLogin($event->getSubject()); | |
| 143 | + } | |
| 144 | + }); | |
| 145 | + | |
| 146 | +        $birthdayListener = function ($event) use ($container): void { | |
| 147 | +            if ($event instanceof GenericEvent) { | |
| 148 | + /** @var BirthdayService $b */ | |
| 149 | + $b = $container->query(BirthdayService::class); | |
| 150 | + $b->onCardChanged( | |
| 151 | +                    (int) $event->getArgument('addressBookId'), | |
| 152 | +                    (string) $event->getArgument('cardUri'), | |
| 153 | +                    (string) $event->getArgument('cardData') | |
| 154 | + ); | |
| 155 | + } | |
| 156 | + }; | |
| 157 | + | |
| 158 | +        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener); | |
| 159 | +        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener); | |
| 160 | +        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) use ($container) { | |
| 161 | +            if ($event instanceof GenericEvent) { | |
| 162 | + /** @var BirthdayService $b */ | |
| 163 | + $b = $container->query(BirthdayService::class); | |
| 164 | + $b->onCardDeleted( | |
| 165 | +                    (int) $event->getArgument('addressBookId'), | |
| 166 | +                    (string) $event->getArgument('cardUri') | |
| 167 | + ); | |
| 168 | + } | |
| 169 | + }); | |
| 170 | + | |
| 171 | +        $clearPhotoCache = function ($event) use ($container): void { | |
| 172 | +            if ($event instanceof GenericEvent) { | |
| 173 | + /** @var PhotoCache $p */ | |
| 174 | + $p = $container->query(PhotoCache::class); | |
| 175 | + $p->delete( | |
| 176 | +                    $event->getArgument('addressBookId'), | |
| 177 | +                    $event->getArgument('cardUri') | |
| 178 | + ); | |
| 179 | + } | |
| 180 | + }; | |
| 181 | +        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); | |
| 182 | +        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); | |
| 183 | + | |
| 184 | +        $dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($container) { | |
| 185 | + $user = $event->getSubject(); | |
| 186 | + /** @var SyncService $syncService */ | |
| 187 | + $syncService = $container->query(SyncService::class); | |
| 188 | + $syncService->updateUser($user); | |
| 189 | + }); | |
| 190 | + | |
| 191 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) use ($container) { | |
| 192 | + /** @var Backend $backend */ | |
| 193 | + $backend = $container->query(Backend::class); | |
| 194 | + $backend->onCalendarAdd( | |
| 195 | +                $event->getArgument('calendarData') | |
| 196 | + ); | |
| 197 | + }); | |
| 198 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) use ($container) { | |
| 199 | + /** @var Backend $backend */ | |
| 200 | + $backend = $container->query(Backend::class); | |
| 201 | + $backend->onCalendarUpdate( | |
| 202 | +                $event->getArgument('calendarData'), | |
| 203 | +                $event->getArgument('shares'), | |
| 204 | +                $event->getArgument('propertyMutations') | |
| 205 | + ); | |
| 206 | + }); | |
| 207 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) use ($container) { | |
| 208 | + /** @var Backend $backend */ | |
| 209 | + $backend = $container->query(Backend::class); | |
| 210 | + $backend->onCalendarDelete( | |
| 211 | +                $event->getArgument('calendarData'), | |
| 212 | +                $event->getArgument('shares') | |
| 213 | + ); | |
| 214 | + | |
| 215 | + /** @var ReminderBackend $reminderBackend */ | |
| 216 | + $reminderBackend = $container->query(ReminderBackend::class); | |
| 217 | + $reminderBackend->cleanRemindersForCalendar( | |
| 218 | +                (int) $event->getArgument('calendarId') | |
| 219 | + ); | |
| 220 | + }); | |
| 221 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) use ($container) { | |
| 222 | + /** @var Backend $backend */ | |
| 223 | + $backend = $container->query(Backend::class); | |
| 224 | + $backend->onCalendarUpdateShares( | |
| 225 | +                $event->getArgument('calendarData'), | |
| 226 | +                $event->getArgument('shares'), | |
| 227 | +                $event->getArgument('add'), | |
| 228 | +                $event->getArgument('remove') | |
| 229 | + ); | |
| 230 | + | |
| 231 | + // Here we should recalculate if reminders should be sent to new or old sharees | |
| 232 | + }); | |
| 233 | + | |
| 234 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) use ($container) { | |
| 235 | + /** @var Backend $backend */ | |
| 236 | + $backend = $container->query(Backend::class); | |
| 237 | + $backend->onCalendarPublication( | |
| 238 | +                $event->getArgument('calendarData'), | |
| 239 | +                $event->getArgument('public') | |
| 240 | + ); | |
| 241 | + }); | |
| 242 | + | |
| 243 | +        $listener = function (GenericEvent $event, $eventName) use ($container): void { | |
| 244 | + /** @var Backend $backend */ | |
| 245 | + $backend = $container->query(Backend::class); | |
| 246 | + | |
| 247 | + $subject = Event::SUBJECT_OBJECT_ADD; | |
| 248 | +            if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { | |
| 249 | + $subject = Event::SUBJECT_OBJECT_UPDATE; | |
| 250 | +            } elseif ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { | |
| 251 | + $subject = Event::SUBJECT_OBJECT_DELETE; | |
| 252 | + } | |
| 253 | + $backend->onTouchCalendarObject( | |
| 254 | + $subject, | |
| 255 | +                $event->getArgument('calendarData'), | |
| 256 | +                $event->getArgument('shares'), | |
| 257 | +                $event->getArgument('objectData') | |
| 258 | + ); | |
| 259 | + | |
| 260 | + /** @var ReminderService $reminderBackend */ | |
| 261 | + $reminderService = $container->query(ReminderService::class); | |
| 262 | + | |
| 263 | + $reminderService->onTouchCalendarObject( | |
| 264 | + $eventName, | |
| 265 | +                $event->getArgument('objectData') | |
| 266 | + ); | |
| 267 | + }; | |
| 268 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); | |
| 269 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); | |
| 270 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); | |
| 271 | + | |
| 272 | + /** | |
| 273 | + * In case the user has set their default calendar to this one | |
| 274 | + */ | |
| 275 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) use ($serverContainer) { | |
| 276 | + /** @var IConfig $config */ | |
| 277 | + $config = $serverContainer->getConfig(); | |
| 278 | +            $principalUri = $event->getArgument('calendarData')['principaluri']; | |
| 279 | +            if (strpos($principalUri, 'principals/users') === 0) { | |
| 280 | + [, $UID] = \Sabre\Uri\split($principalUri); | |
| 281 | +                $uri = $event->getArgument('calendarData')['uri']; | |
| 282 | +                if ($config->getUserValue($UID, 'dav', 'defaultCalendar') === $uri) { | |
| 283 | + $config->deleteUserValue($UID, 'dav', 'defaultCalendar'); | |
| 284 | + } | |
| 285 | + } | |
| 286 | + }); | |
| 287 | + | |
| 288 | +        $dispatcher->addListener('OCP\Federation\TrustedServerEvent::remove', | |
| 289 | +            function (GenericEvent $event) { | |
| 290 | + /** @var CardDavBackend $cardDavBackend */ | |
| 291 | + $cardDavBackend = \OC::$server->query(CardDavBackend::class); | |
| 292 | + $addressBookUri = $event->getSubject(); | |
| 293 | +                $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri); | |
| 294 | +                if (!is_null($addressBook)) { | |
| 295 | + $cardDavBackend->deleteAddressBook($addressBook['id']); | |
| 296 | + } | |
| 297 | + } | |
| 298 | + ); | |
| 299 | + | |
| 300 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createSubscription', | |
| 301 | +            function (GenericEvent $event) use ($container, $serverContainer) { | |
| 302 | + $jobList = $serverContainer->getJobList(); | |
| 303 | +                $subscriptionData = $event->getArgument('subscriptionData'); | |
| 304 | + | |
| 305 | + /** | |
| 306 | + * Initial subscription refetch | |
| 307 | + * | |
| 308 | + * @var RefreshWebcalService $refreshWebcalService | |
| 309 | + */ | |
| 310 | + $refreshWebcalService = $container->query(RefreshWebcalService::class); | |
| 311 | + $refreshWebcalService->refreshSubscription( | |
| 312 | + (string) $subscriptionData['principaluri'], | |
| 313 | + (string) $subscriptionData['uri'] | |
| 314 | + ); | |
| 315 | + | |
| 316 | + $jobList->add(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [ | |
| 317 | + 'principaluri' => $subscriptionData['principaluri'], | |
| 318 | + 'uri' => $subscriptionData['uri'] | |
| 319 | + ]); | |
| 320 | + } | |
| 321 | + ); | |
| 322 | + | |
| 323 | +        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription', | |
| 324 | +            function (GenericEvent $event) use ($container, $serverContainer) { | |
| 325 | + $jobList = $serverContainer->getJobList(); | |
| 326 | +                $subscriptionData = $event->getArgument('subscriptionData'); | |
| 327 | + | |
| 328 | + $jobList->remove(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [ | |
| 329 | + 'principaluri' => $subscriptionData['principaluri'], | |
| 330 | + 'uri' => $subscriptionData['uri'] | |
| 331 | + ]); | |
| 332 | + | |
| 333 | + /** @var CalDavBackend $calDavBackend */ | |
| 334 | + $calDavBackend = $container->query(CalDavBackend::class); | |
| 335 | + $calDavBackend->purgeAllCachedEventsForSubscription($subscriptionData['id']); | |
| 336 | + } | |
| 337 | + ); | |
| 338 | + | |
| 339 | +        $eventHandler = function () use ($container, $serverContainer): void { | |
| 340 | +            try { | |
| 341 | + /** @var UpdateCalendarResourcesRoomsBackgroundJob $job */ | |
| 342 | + $job = $container->query(UpdateCalendarResourcesRoomsBackgroundJob::class); | |
| 343 | + $job->run([]); | |
| 344 | + $serverContainer->getJobList()->setLastRun($job); | |
| 345 | +            } catch (Exception $ex) { | |
| 346 | + $serverContainer->getLogger()->logException($ex); | |
| 347 | + } | |
| 348 | + }; | |
| 349 | + | |
| 350 | +        $dispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler); | |
| 351 | +        $dispatcher->addListener('\OCP\Calendar\Room\ForceRefreshEvent', $eventHandler); | |
| 352 | + } | |
| 353 | + | |
| 354 | +    public function registerContactsManager(IContactsManager $cm, IAppContainer $container): void { | |
| 355 | +        $cm->register(function () use ($container, $cm): void { | |
| 356 | + $user = \OC::$server->getUserSession()->getUser(); | |
| 357 | +            if (!is_null($user)) { | |
| 358 | + $this->setupContactsProvider($cm, $container, $user->getUID()); | |
| 359 | +            } else { | |
| 360 | + $this->setupSystemContactsProvider($cm, $container); | |
| 361 | + } | |
| 362 | + }); | |
| 363 | + } | |
| 364 | + | |
| 365 | + private function setupContactsProvider(IContactsManager $contactsManager, | |
| 366 | + IAppContainer $container, | |
| 367 | +                                            string $userID): void { | |
| 368 | + /** @var ContactsManager $cm */ | |
| 369 | + $cm = $container->query(ContactsManager::class); | |
| 370 | + $urlGenerator = $container->getServer()->getURLGenerator(); | |
| 371 | + $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); | |
| 372 | + } | |
| 373 | + | |
| 374 | + private function setupSystemContactsProvider(IContactsManager $contactsManager, | |
| 375 | +                                                    IAppContainer $container): void { | |
| 376 | + /** @var ContactsManager $cm */ | |
| 377 | + $cm = $container->query(ContactsManager::class); | |
| 378 | + $urlGenerator = $container->getServer()->getURLGenerator(); | |
| 379 | + $cm->setupSystemContactsProvider($contactsManager, $urlGenerator); | |
| 380 | + } | |
| 381 | + | |
| 382 | + public function registerCalendarManager(ICalendarManager $calendarManager, | |
| 383 | +                                                IAppContainer $container): void { | |
| 384 | +        $calendarManager->register(function () use ($container, $calendarManager) { | |
| 385 | + $user = \OC::$server->getUserSession()->getUser(); | |
| 386 | +            if ($user !== null) { | |
| 387 | + $this->setupCalendarProvider($calendarManager, $container, $user->getUID()); | |
| 388 | + } | |
| 389 | + }); | |
| 390 | + } | |
| 391 | + | |
| 392 | + private function setupCalendarProvider(ICalendarManager $calendarManager, | |
| 393 | + IAppContainer $container, | |
| 394 | +                                            $userId) { | |
| 395 | + $cm = $container->query(CalendarManager::class); | |
| 396 | + $cm->setupCalendarProvider($calendarManager, $userId); | |
| 397 | + } | |
| 398 | + | |
| 399 | + public function registerCalendarReminders(NotificationProviderManager $manager, | |
| 400 | +                                                ILogger $logger): void { | |
| 401 | +        try { | |
| 402 | + $manager->registerProvider(AudioProvider::class); | |
| 403 | + $manager->registerProvider(EmailProvider::class); | |
| 404 | + $manager->registerProvider(PushProvider::class); | |
| 405 | +        } catch (Throwable $ex) { | |
| 406 | + $logger->logException($ex); | |
| 407 | + } | |
| 408 | + } | |
| 409 | 409 | } | 
| @@ -40,25 +40,25 @@ | ||
| 40 | 40 | use OCP\Federation\ICloudFederationProviderManager; | 
| 41 | 41 | |
| 42 | 42 |  class Application extends App implements IBootstrap { | 
| 43 | -	public function __construct() { | |
| 44 | -		parent::__construct('federatedfilesharing'); | |
| 45 | - } | |
| 43 | +    public function __construct() { | |
| 44 | +        parent::__construct('federatedfilesharing'); | |
| 45 | + } | |
| 46 | 46 | |
| 47 | -	public function register(IRegistrationContext $context): void { | |
| 48 | - $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class); | |
| 49 | - $context->registerNotifierService(Notifier::class); | |
| 50 | - } | |
| 47 | +    public function register(IRegistrationContext $context): void { | |
| 48 | + $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class); | |
| 49 | + $context->registerNotifierService(Notifier::class); | |
| 50 | + } | |
| 51 | 51 | |
| 52 | -	public function boot(IBootContext $context): void { | |
| 53 | - $context->injectFn(Closure::fromCallable([$this, 'registerCloudFederationProvider'])); | |
| 54 | - } | |
| 52 | +    public function boot(IBootContext $context): void { | |
| 53 | + $context->injectFn(Closure::fromCallable([$this, 'registerCloudFederationProvider'])); | |
| 54 | + } | |
| 55 | 55 | |
| 56 | - private function registerCloudFederationProvider(ICloudFederationProviderManager $manager, | |
| 57 | -													 IAppContainer $appContainer): void { | |
| 58 | -		$manager->addCloudFederationProvider('file', | |
| 59 | - 'Federated Files Sharing', | |
| 60 | -			function () use ($appContainer): CloudFederationProviderFiles { | |
| 61 | - return $appContainer->get(CloudFederationProviderFiles::class); | |
| 62 | - }); | |
| 63 | - } | |
| 56 | + private function registerCloudFederationProvider(ICloudFederationProviderManager $manager, | |
| 57 | +                                                        IAppContainer $appContainer): void { | |
| 58 | +        $manager->addCloudFederationProvider('file', | |
| 59 | + 'Federated Files Sharing', | |
| 60 | +            function () use ($appContainer): CloudFederationProviderFiles { | |
| 61 | + return $appContainer->get(CloudFederationProviderFiles::class); | |
| 62 | + }); | |
| 63 | + } | |
| 64 | 64 | } | 
| @@ -57,7 +57,7 @@ | ||
| 57 | 57 |  													 IAppContainer $appContainer): void { | 
| 58 | 58 |  		$manager->addCloudFederationProvider('file', | 
| 59 | 59 | 'Federated Files Sharing', | 
| 60 | -			function () use ($appContainer): CloudFederationProviderFiles { | |
| 60 | +			function() use ($appContainer): CloudFederationProviderFiles { | |
| 61 | 61 | return $appContainer->get(CloudFederationProviderFiles::class); | 
| 62 | 62 | }); | 
| 63 | 63 | } | 
| @@ -46,46 +46,46 @@ | ||
| 46 | 46 | use OCP\Util; | 
| 47 | 47 | |
| 48 | 48 |  class Application extends App implements IBootstrap { | 
| 49 | -	public function __construct() { | |
| 50 | -		parent::__construct('updatenotification', []); | |
| 51 | - } | |
| 49 | +    public function __construct() { | |
| 50 | +        parent::__construct('updatenotification', []); | |
| 51 | + } | |
| 52 | 52 | |
| 53 | -	public function register(IRegistrationContext $context): void { | |
| 54 | - $context->registerNotifierService(Notifier::class); | |
| 55 | - } | |
| 53 | +    public function register(IRegistrationContext $context): void { | |
| 54 | + $context->registerNotifierService(Notifier::class); | |
| 55 | + } | |
| 56 | 56 | |
| 57 | -	public function boot(IBootContext $context): void { | |
| 58 | - $context->injectFn(function (IConfig $config, | |
| 59 | - IUserSession $userSession, | |
| 60 | - IAppManager $appManager, | |
| 61 | - IGroupManager $groupManager, | |
| 62 | - IAppContainer $appContainer, | |
| 63 | -									 ILogger $logger) { | |
| 64 | -			if ($config->getSystemValue('updatechecker', true) !== true) { | |
| 65 | - // Updater check is disabled | |
| 66 | - return; | |
| 67 | - } | |
| 57 | +    public function boot(IBootContext $context): void { | |
| 58 | + $context->injectFn(function (IConfig $config, | |
| 59 | + IUserSession $userSession, | |
| 60 | + IAppManager $appManager, | |
| 61 | + IGroupManager $groupManager, | |
| 62 | + IAppContainer $appContainer, | |
| 63 | +                                        ILogger $logger) { | |
| 64 | +            if ($config->getSystemValue('updatechecker', true) !== true) { | |
| 65 | + // Updater check is disabled | |
| 66 | + return; | |
| 67 | + } | |
| 68 | 68 | |
| 69 | - $user = $userSession->getUser(); | |
| 70 | -			if (!$user instanceof IUser) { | |
| 71 | - // Nothing to do for guests | |
| 72 | - return; | |
| 73 | - } | |
| 69 | + $user = $userSession->getUser(); | |
| 70 | +            if (!$user instanceof IUser) { | |
| 71 | + // Nothing to do for guests | |
| 72 | + return; | |
| 73 | + } | |
| 74 | 74 | |
| 75 | -			if (!$appManager->isEnabledForUser('notifications') && | |
| 76 | -				$groupManager->isAdmin($user->getUID())) { | |
| 77 | -				try { | |
| 78 | - $updateChecker = $appContainer->get(UpdateChecker::class); | |
| 79 | -				} catch (QueryException $e) { | |
| 80 | - $logger->logException($e); | |
| 81 | - return; | |
| 82 | - } | |
| 75 | +            if (!$appManager->isEnabledForUser('notifications') && | |
| 76 | +                $groupManager->isAdmin($user->getUID())) { | |
| 77 | +                try { | |
| 78 | + $updateChecker = $appContainer->get(UpdateChecker::class); | |
| 79 | +                } catch (QueryException $e) { | |
| 80 | + $logger->logException($e); | |
| 81 | + return; | |
| 82 | + } | |
| 83 | 83 | |
| 84 | -				if ($updateChecker->getUpdateState() !== []) { | |
| 85 | -					Util::addScript('updatenotification', 'legacy-notification'); | |
| 86 | -					\OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); | |
| 87 | - } | |
| 88 | - } | |
| 89 | - }); | |
| 90 | - } | |
| 84 | +                if ($updateChecker->getUpdateState() !== []) { | |
| 85 | +                    Util::addScript('updatenotification', 'legacy-notification'); | |
| 86 | +                    \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + }); | |
| 90 | + } | |
| 91 | 91 | } | 
| @@ -55,7 +55,7 @@ | ||
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | 57 |  	public function boot(IBootContext $context): void { | 
| 58 | - $context->injectFn(function (IConfig $config, | |
| 58 | + $context->injectFn(function(IConfig $config, | |
| 59 | 59 | IUserSession $userSession, | 
| 60 | 60 | IAppManager $appManager, | 
| 61 | 61 | IGroupManager $groupManager, |