11<?php
2+
23/**
34 * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
45 * SPDX-License-Identifier: AGPL-3.0-or-later
89
910use Exception ;
1011use OC \Files \Filesystem ;
11- use OC \Files \Storage \Wrapper \Wrapper ;
1212use OCA \Registration \Events \PassedFormEvent ;
1313use OCA \Registration \Events \ShowFormEvent ;
1414use OCA \Registration \Events \ValidateFormEvent ;
15- use OCA \TermsOfService \PublicCapabilities ;
1615use OCA \TermsOfService \Checker ;
1716use OCA \TermsOfService \Dav \CheckPlugin ;
1817use OCA \TermsOfService \Filesystem \StorageWrapper ;
1918use OCA \TermsOfService \Listener \RegistrationIntegration ;
2019use OCA \TermsOfService \Listener \UserDeletedListener ;
2120use OCA \TermsOfService \Notifications \Notifier ;
21+ use OCA \TermsOfService \PublicCapabilities ;
2222use OCP \AppFramework \App ;
2323use OCP \AppFramework \Bootstrap \IBootContext ;
2424use OCP \AppFramework \Bootstrap \IBootstrap ;
2525use OCP \AppFramework \Bootstrap \IRegistrationContext ;
26+ use OCP \AppFramework \Services \IAppConfig ;
2627use OCP \EventDispatcher \IEventDispatcher ;
2728use OCP \Files \Storage \IStorage ;
28- use OCP \IConfig ;
2929use OCP \IRequest ;
3030use OCP \IUser ;
3131use OCP \IUserSession ;
3434use OCP \User \Events \UserDeletedEvent ;
3535use OCP \User \Events \UserFirstTimeLoggedInEvent ;
3636use OCP \Util ;
37- use Psr \Log \LoggerInterface ;
3837use Psr \Container \ContainerExceptionInterface ;
38+ use Psr \Log \LoggerInterface ;
3939
4040include_once __DIR__ . '/../../vendor/autoload.php ' ;
4141
@@ -46,7 +46,7 @@ class Application extends App implements IBootstrap {
4646
4747
4848 public function __construct () {
49- parent ::__construct (' terms_of_service ' );
49+ parent ::__construct (self :: APPNAME );
5050 }
5151
5252 public function register (IRegistrationContext $ context ): void {
@@ -61,7 +61,7 @@ public function boot(IBootContext $context): void {
6161 Util::connectHook ('OC_Filesystem ' , 'preSetup ' , $ this , 'addStorageWrapper ' );
6262
6363 $ eventDispatcher = $ context ->getServerContainer ()->get (IEventDispatcher::class);
64- $ eventDispatcher ->addListener ('OCA\DAV\Connector\Sabre::addPlugin ' , function (SabrePluginEvent $ event ) use ($ context ) {
64+ $ eventDispatcher ->addListener ('OCA\DAV\Connector\Sabre::addPlugin ' , function (SabrePluginEvent $ event ) use ($ context ): void {
6565 $ eventServer = $ event ->getServer ();
6666
6767 if ($ eventServer !== null ) {
@@ -78,7 +78,7 @@ public function boot(IBootContext $context): void {
7878 $ context ->injectFn ([$ this , 'registerFrontend ' ]);
7979 }
8080
81- public function registerFrontend (IRequest $ request , IConfig $ config , IUserSession $ userSession ): void {
81+ public function registerFrontend (IRequest $ request , IAppConfig $ appConfig , IUserSession $ userSession ): void {
8282 // Ignore CLI
8383 /** @psalm-suppress UndefinedClass */
8484 if (\OC ::$ CLI ) {
@@ -105,14 +105,14 @@ public function registerFrontend(IRequest $request, IConfig $config, IUserSessio
105105 // registration
106106 '#^/apps/registration(?:$|/)# ' ,
107107 ];
108- if (array_filter ($ skipPatterns , fn ( $ pattern ) => preg_match ($ pattern , $ request ->getPathInfo ()))) {
108+ if (array_filter ($ skipPatterns , fn ( string $ pattern ): int | false => preg_match ($ pattern , $ request ->getPathInfo ()))) {
109109 return ;
110110 }
111111
112112 if ($ userSession ->getUser () instanceof IUser) {
113113 // Logged-in user
114114 Util::addScript ('terms_of_service ' , 'terms_of_service-user ' );
115- } else if ( $ config -> getAppValue ( self :: APPNAME , 'tos_on_public_shares ' , ' 0 ' ) === ' 1 ' ) {
115+ } elseif ( $ appConfig -> getAppValueBool ( 'tos_on_public_shares ' ) === true ) {
116116 // Guests on public pages
117117 Util::addScript ('terms_of_service ' , 'terms_of_service-public ' );
118118 }
@@ -126,9 +126,6 @@ public function addStorageWrapper(): void {
126126 }
127127
128128 /**
129- * @param string $mountPoint
130- * @param IStorage $storage
131- *
132129 * @return StorageWrapper|IStorage
133130 * @throws Exception
134131 */
@@ -160,7 +157,7 @@ public function registerNotifier(IManager $notificationManager): void {
160157 }
161158
162159 public function createNotificationOnFirstLogin (IManager $ notificationManager , IEventDispatcher $ dispatcher ): void {
163- $ dispatcher ->addListener (UserFirstTimeLoggedInEvent::class, function (UserFirstTimeLoggedInEvent $ event ) use ($ notificationManager ) {
160+ $ dispatcher ->addListener (UserFirstTimeLoggedInEvent::class, function (UserFirstTimeLoggedInEvent $ event ) use ($ notificationManager ): void {
164161 $ user = $ event ->getUser ();
165162 $ notification = $ notificationManager ->createNotification ();
166163 $ notification ->setApp ('terms_of_service ' )
0 commit comments