From 05c35b9a63af1dce36844c56e055687c72fa8dac Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 27 Jun 2024 20:08:56 +0200 Subject: [PATCH 1/2] retrieve tables apps --- lib/Service/AppRepository.php | 59 ++++++++++++++--------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/lib/Service/AppRepository.php b/lib/Service/AppRepository.php index ec10a36..d53317c 100644 --- a/lib/Service/AppRepository.php +++ b/lib/Service/AppRepository.php @@ -5,6 +5,11 @@ namespace OCA\SideMenu\Service; use OC\User\User; use OCP\INavigationManager; use OCP\L10N\IFactory; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\IUserSession; +use OCP\AppFramework\Http\TemplateResponse; +use OCA\SideMenu\AppInfo\Application; /** * class AppRepository. @@ -13,43 +18,19 @@ use OCP\L10N\IFactory; */ class AppRepository { - /** - * @var \OC_App - */ - protected $ocApp; - - /** - * @var IFactory - */ - protected $l10nFactory; - - /** - * @var ConfigProxy - */ - protected $config; - - /** - * @var CategoryRepository - */ - protected $categoryRepository; - - /** - * @var INavigationManager - */ - protected $navigationManager; - public function __construct( - \OC_App $ocApp, - INavigationManager $navigationManager, - IFactory $l10nFactory, - ConfigProxy $config, - CategoryRepository $categoryRepository + protected \OC_App $ocApp, + protected INavigationManager $navigationManager, + protected IFactory $l10nFactory, + protected ConfigProxy $config, + protected CategoryRepository $categoryRepository, + protected IEventDispatcher $dispatcher, + protected IUserSession $userSession, ) { - $this->ocApp = $ocApp; - $this->l10nFactory = $l10nFactory; - $this->config = $config; - $this->navigationManager = $navigationManager; - $this->categoryRepository = $categoryRepository; + $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent( + $this->userSession->isLoggedIn(), + new TemplateResponse(Application::APP_NAME, '') + )); } /** @@ -90,6 +71,14 @@ class AppRepository 'external_links', ], ]; + } elseif ('tables_application' === substr($app['id'], 0, 18)) { + $visibleApps[$app['id']] = [ + 'id' => $app['id'], + 'name' => $this->getAppName($app), + 'href' => $app['href'], + 'icon' => $app['icon'], + 'category' => [], + ]; } elseif ('files' === $app['id']) { $visibleApps[$app['id']] = [ 'id' => $app['id'], From 7c5654f3bc1887c8eea8a214733d17f1445f7075 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 27 Jun 2024 20:27:31 +0200 Subject: [PATCH 2/2] add constructor property promotion add return type of methods --- lib/Controller/AdminSettingController.php | 30 +++------ lib/Controller/AppController.php | 20 +----- lib/Controller/CssController.php | 41 +++--------- lib/Controller/JsController.php | 26 ++------ lib/Controller/NavController.php | 50 +++----------- lib/Controller/PersonalSettingController.php | 30 ++------- lib/Service/AppRepository.php | 20 +++--- lib/Service/CategoryRepository.php | 44 ++---------- lib/Service/ConfigProxy.php | 7 +- lib/Service/LangRepository.php | 7 +- lib/Settings/Admin.php | 70 +++----------------- lib/Settings/AdminSection.php | 37 ++--------- lib/Settings/Personal.php | 40 ++--------- lib/Settings/PersonalSection.php | 44 ++---------- 14 files changed, 78 insertions(+), 388 deletions(-) diff --git a/lib/Controller/AdminSettingController.php b/lib/Controller/AdminSettingController.php index aa11d9a..4ecfbea 100644 --- a/lib/Controller/AdminSettingController.php +++ b/lib/Controller/AdminSettingController.php @@ -22,37 +22,25 @@ use OCA\SideMenu\AppInfo\Application; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataDownloadResponse; use OCP\AppFramework\Http\RedirectResponse; -use OCP\AppFramework\Http\Response; use OCP\IConfig; use OCP\IRequest; use OCP\IURLGenerator; class AdminSettingController extends Controller { - /** - * @var IConfig - */ - protected $config; - - /** - * @var IURLGenerator - */ - protected $urlGenerator; - - public function __construct($appName, IRequest $request, IConfig $config, IURLGenerator $urlGenerator) - { + public function __construct( + $appName, + IRequest $request, + protected IConfig $config, + protected IURLGenerator $urlGenerator + ) { parent::__construct($appName, $request); - - $this->config = $config; - $this->urlGenerator = $urlGenerator; } /** * @NoCSRFRequired - * - * @return RedirectResponse */ - public function removeCache() + public function removeCache(): RedirectResponse { $this->config->setAppValue(Application::APP_ID, 'cache-categories', '[]'); @@ -63,10 +51,8 @@ class AdminSettingController extends Controller /** * @NoCSRFRequired - * - * @return Response */ - public function exportConfiguration() + public function exportConfiguration(): DataDownloadResponse { $keys = $this->config->getAppKeys(Application::APP_ID); $appConfig = []; diff --git a/lib/Controller/AppController.php b/lib/Controller/AppController.php index 588911f..dd2993e 100644 --- a/lib/Controller/AppController.php +++ b/lib/Controller/AppController.php @@ -29,28 +29,14 @@ use OCP\IUserSession; class AppController extends Controller { - /** - * @var ConfigProxy - */ - protected $config; - - /** - * @var AppRepository - */ - protected $appRepository; - public function __construct( string $appName, IRequest $request, - AppRepository $appRepository, - IURLGenerator $urlGenerator, - ConfigProxy $config + protected AppRepository $appRepository, + protected IURLGenerator $urlGenerator, + protected ConfigProxy $config ) { parent::__construct($appName, $request); - - $this->appRepository = $appRepository; - $this->urlGenerator = $urlGenerator; - $this->config = $config; } /** diff --git a/lib/Controller/CssController.php b/lib/Controller/CssController.php index 06f7ae8..93fafb3 100644 --- a/lib/Controller/CssController.php +++ b/lib/Controller/CssController.php @@ -32,49 +32,26 @@ use OCP\IUserSession; class CssController extends Controller { - /** - * @var ConfigProxy - */ - protected $config; - - /** - * @var User - */ - protected $user; - - /** - * @var ThemingDefaults - */ - protected $theming; - - /** - * @var Color - */ - protected $color; + protected ?User $user; public function __construct( string $appName, IRequest $request, - ConfigProxy $config, - ThemingDefaults $theming, - Color $color + protected ConfigProxy $config, + protected ThemingDefaults $theming, + protected Color $color ) { parent::__construct($appName, $request); $this->user = OC::$server[IUserSession::class]->getUser(); - $this->config = $config; - $this->theming = $theming; - $this->color = $color; } /** * @NoAdminRequired * @NoCSRFRequired * @PublicPage - * - * @return Response */ - public function stylesheet() + public function stylesheet(): TemplateResponse { $response = new TemplateResponse(Application::APP_ID, 'css/stylesheet', $this->getConfig(), 'blank'); $response->addHeader('Content-Type', 'text/css'); @@ -107,15 +84,15 @@ class CssController extends Controller $isDarkThemeUserEnabled = 'dark' === $this->config->getUserValue($this->user, 'theme', '', 'accessibility'); $isBreezeDarkUserEnabled = $this->config->getUserValue($this->user, 'theme_enabled', '', 'breezedark'); - $isBreezeDarkUserEnabled = '1' === $isBreezeDarkUserEnabled || - ($isBreezeDarkGlobalEnabled && '' === $isBreezeDarkUserEnabled); + $isBreezeDarkUserEnabled = '1' === $isBreezeDarkUserEnabled + || ($isBreezeDarkGlobalEnabled && '' === $isBreezeDarkUserEnabled); } else { $isDarkThemeUserEnabled = false; $isBreezeDarkUserEnabled = false; } - $isDarkMode = ($isAccessibilityAppEnabled && $isDarkThemeUserEnabled) || - ($isBreezeDarkAppEnabled && $isBreezeDarkUserEnabled); + $isDarkMode = ($isAccessibilityAppEnabled && $isDarkThemeUserEnabled) + || ($isBreezeDarkAppEnabled && $isBreezeDarkUserEnabled); $primaryColor = $this->theming->getColorPrimary(); $lightenPrimaryColor = $this->color->adjustBrightness($primaryColor, 0.2); diff --git a/lib/Controller/JsController.php b/lib/Controller/JsController.php index 13d803e..a1b26e3 100644 --- a/lib/Controller/JsController.php +++ b/lib/Controller/JsController.php @@ -32,32 +32,14 @@ use OCP\L10N\IFactory; class JsController extends Controller { - /** - * @var ConfigProxy - */ - protected $config; - - /** - * @var User - */ - protected $user; - - /** - * @var ThemingDefaults - */ - protected $themingDefaults; - - /** - * @var IFactory - */ - protected $l10nFactory; + protected ?User $user; public function __construct( string $appName, IRequest $request, - ConfigProxy $config, - ThemingDefaults $themingDefaults, - IFactory $l10nFactory + protected ConfigProxy $config, + protected ThemingDefaults $themingDefaults, + protected IFactory $l10nFactory ) { parent::__construct($appName, $request); diff --git a/lib/Controller/NavController.php b/lib/Controller/NavController.php index 50efc4c..21fb23c 100644 --- a/lib/Controller/NavController.php +++ b/lib/Controller/NavController.php @@ -19,7 +19,6 @@ namespace OCA\SideMenu\Controller; use OC; -use OC\App\AppStore\Fetcher\CategoryFetcher; use OC\URLGenerator; use OCA\SideMenu\Service\AppRepository; use OCA\SideMenu\Service\CategoryRepository; @@ -32,57 +31,24 @@ use OCP\L10N\IFactory; class NavController extends Controller { - /** - * @var ConfigProxy - */ - protected $config; - - /** - * @var AppRepository - */ - protected $appRepository; - - /** - * @var IFactory - */ - protected $l10nFactory; - - /** - * @var CategoryFetcher - */ - protected $categoryFetcher; - - /** - * @var URLGenerator - */ - protected $router; - public function __construct( string $appName, IRequest $request, - ConfigProxy $config, - AppRepository $appRepository, - CategoryRepository $categoryRepository, - URLGenerator $router, - IFactory $l10nFactory + protected ConfigProxy $config, + protected AppRepository $appRepository, + protected CategoryRepository $categoryRepository, + protected URLGenerator $router, + protected IFactory $l10nFactory ) { parent::__construct($appName, $request); - - $this->config = $config; - $this->appRepository = $appRepository; - $this->categoryRepository = $categoryRepository; - $this->l10nFactory = $l10nFactory; - $this->router = $router; } /** * @NoAdminRequired * @NoCSRFRequired * @PublicPage - * - * @return JSONResponse */ - public function items() + public function items(): JSONResponse { $user = OC::$server[IUserSession::class]->getUser(); $items = []; @@ -189,11 +155,11 @@ class NavController extends Controller usort($items, function ($a, $b) use ($categoriesLabels) { foreach ($categoriesLabels as $key => $value) { - if ($a['categoryId'] === 'other') { + if ('other' === $a['categoryId']) { return -1; } - if ($b['categoryId'] === 'other') { + if ('other' === $b['categoryId']) { return 1; } diff --git a/lib/Controller/PersonalSettingController.php b/lib/Controller/PersonalSettingController.php index fc30c35..e4f6331 100644 --- a/lib/Controller/PersonalSettingController.php +++ b/lib/Controller/PersonalSettingController.php @@ -21,40 +21,20 @@ namespace OCA\SideMenu\Controller; use OCA\SideMenu\AppInfo\Application; use OCA\SideMenu\Service\ConfigProxy; use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\Response; use OCP\IConfig; use OCP\IRequest; use OCP\IUserSession; class PersonalSettingController extends Controller { - /** - * @var IConfig - */ - protected $config; - - /** - * @var ConfigProxy - */ - protected $configProxy; - - /** - * @var IUserSession - */ - protected $userSession; - public function __construct( $appName, IRequest $request, - IConfig $config, - ConfigProxy $configProxy, - IUserSession $userSession + protected IConfig $config, + protected ConfigProxy $configProxy, + protected IUserSession $userSession ) { parent::__construct($appName, $request); - - $this->config = $config; - $this->configProxy = $configProxy; - $this->userSession = $userSession; } /** @@ -63,10 +43,8 @@ class PersonalSettingController extends Controller * * @param mixed $name * @param mixed $value - * - * @return Response */ - public function valueSet($name, $value) + public function valueSet($name, $value): array { $doSave = false; $user = $this->userSession->getUser(); diff --git a/lib/Service/AppRepository.php b/lib/Service/AppRepository.php index d53317c..3c64f7d 100644 --- a/lib/Service/AppRepository.php +++ b/lib/Service/AppRepository.php @@ -3,13 +3,13 @@ namespace OCA\SideMenu\Service; use OC\User\User; -use OCP\INavigationManager; -use OCP\L10N\IFactory; -use OCP\EventDispatcher\IEventDispatcher; -use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; -use OCP\IUserSession; -use OCP\AppFramework\Http\TemplateResponse; use OCA\SideMenu\AppInfo\Application; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\INavigationManager; +use OCP\IUserSession; +use OCP\L10N\IFactory; /** * class AppRepository. @@ -35,10 +35,8 @@ class AppRepository /** * Retrieves visibles apps. - * - * @return array */ - public function getVisibleApps() + public function getVisibleApps(): array { $navigation = $this->navigationManager->getAll(); $appCategoriesCustom = $this->config->getAppValueArray('apps-categories-custom', '[]'); @@ -99,7 +97,7 @@ class AppRepository return $visibleApps; } - public function getAppName($app) + public function getAppName($app): string { return $this->config->getAppValue( 'app.navigation.name', @@ -108,7 +106,7 @@ class AppRepository ); } - public function getOrderedApps(?User $user = null) + public function getOrderedApps(?User $user = null): array { $apps = $this->getVisibleApps(); $orders = $this->config->getAppValueArray('apps-order', '[]'); diff --git a/lib/Service/CategoryRepository.php b/lib/Service/CategoryRepository.php index c146609..7173442 100644 --- a/lib/Service/CategoryRepository.php +++ b/lib/Service/CategoryRepository.php @@ -15,51 +15,19 @@ use OCP\L10N\IFactory; */ class CategoryRepository { - /** - * @var CategoryFetcher - */ - protected $categoryFetcher; - - /** - * @var IFactory - */ - protected $l10nFactory; - - /** - * @var ConfigProxy - */ - protected $config; - - /** - * @var IConfig - */ - protected $iConfig; - - /** - * @var IUserSession - */ - protected $userSession; - public function __construct( - CategoryFetcher $categoryFetcher, - ConfigProxy $config, - IConfig $iConfig, - IFactory $l10nFactory, - IUserSession $userSession + protected CategoryFetcher $categoryFetcher, + protected ConfigProxy $config, + protected IConfig $iConfig, + protected IFactory $l10nFactory, + protected IUserSession $userSession ) { - $this->categoryFetcher = $categoryFetcher; - $this->l10nFactory = $l10nFactory; - $this->config = $config; - $this->iConfig = $iConfig; - $this->userSession = $userSession; } /** * Retrieves categories. - * - * @return array */ - public function getOrderedCategories() + public function getOrderedCategories(): array { $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2); $type = $this->config->getAppValue('categories-order-type', 'default'); diff --git a/lib/Service/ConfigProxy.php b/lib/Service/ConfigProxy.php index d162dfd..6745851 100644 --- a/lib/Service/ConfigProxy.php +++ b/lib/Service/ConfigProxy.php @@ -13,12 +13,7 @@ use OCP\IConfig; */ class ConfigProxy { - /** - * @var IConfig - */ - protected $config; - - public function __construct(IConfig $config) + public function __construct(protected IConfig $config) { $this->config = $config; } diff --git a/lib/Service/LangRepository.php b/lib/Service/LangRepository.php index 3c379f0..1cde40a 100644 --- a/lib/Service/LangRepository.php +++ b/lib/Service/LangRepository.php @@ -11,12 +11,7 @@ use OCP\IDBConnection; */ class LangRepository { - /** - * @var IDBConnection - */ - protected $db; - - public function __construct(IDBConnection $db) + public function __construct(protected IDBConnection $db) { $this->db = $db; } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 86ddac4..a6c438e 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -21,75 +21,27 @@ namespace OCA\SideMenu\Settings; use OCA\SideMenu\AppInfo\Application; use OCA\SideMenu\Service\AppRepository; use OCA\SideMenu\Service\CategoryRepository; +use OCA\SideMenu\Service\Color; use OCA\SideMenu\Service\ConfigProxy; +use OCA\SideMenu\Service\LangRepository; +use OCA\Theming\ThemingDefaults; use OCP\AppFramework\Http\TemplateResponse; use OCP\IL10N; use OCP\ILogger; use OCP\Settings\ISettings; -use OCA\Theming\ThemingDefaults; -use OCA\SideMenu\Service\Color; -use OCA\SideMenu\Service\LangRepository; class Admin implements ISettings { - /** - * @var IL10N - */ - private $l; - - /** - * @var ILogger - */ - private $logger; - - /** - * @var ConfigProxy - */ - private $config; - - /** - * @var AppRepository - */ - private $appRepository; - - /** - * @var CategoryRepository - */ - private $categoryRepository; - - /** - * @var ThemingDefaults - */ - protected $theming; - - /** - * @var Color - */ - protected $color; - - /** - * @var LangRepository - */ - protected $langRepository; - public function __construct( - IL10N $l, - ILogger $logger, - ConfigProxy $config, - AppRepository $appRepository, - CategoryRepository $categoryRepository, - ThemingDefaults $theming, - Color $color, - LangRepository $langRepository + protected IL10N $l, + protected ILogger $logger, + protected ConfigProxy $config, + protected AppRepository $appRepository, + protected CategoryRepository $categoryRepository, + protected ThemingDefaults $theming, + protected Color $color, + protected LangRepository $langRepository ) { - $this->l = $l; - $this->logger = $logger; - $this->config = $config; - $this->appRepository = $appRepository; - $this->categoryRepository = $categoryRepository; - $this->theming = $theming; - $this->color = $color; - $this->langRepository = $langRepository; } /** diff --git a/lib/Settings/AdminSection.php b/lib/Settings/AdminSection.php index 8629e8a..c8993b4 100644 --- a/lib/Settings/AdminSection.php +++ b/lib/Settings/AdminSection.php @@ -25,51 +25,22 @@ use OCP\Settings\IIconSection; class AdminSection implements IIconSection { - /** - * @var IL10N - */ - private $l; - - /** - * @var IURLGenerator - */ - private $url; - - public function __construct(IURLGenerator $url, IL10N $l) - { - $this->url = $url; - $this->l = $l; + public function __construct( + protected IURLGenerator $url, + protected IL10N $l + ) { } - /** - * returns the ID of the section. It is supposed to be a lower case string, - * e.g. 'ldap'. - * - * @returns string - */ public function getID() { return Application::APP_ID; } - /** - * returns the translated name as it should be displayed, e.g. 'LDAP / AD - * integration'. Use the L10N service to translate it. - * - * @return string - */ public function getName() { return $this->l->t(Application::APP_NAME); } - /** - * @return int whether the form should be rather on the top or bottom of - * the settings navigation. The sections are arranged in ascending order of - * the priority values. It is required to return a value between 0 and 99. - * - * E.g.: 70 - */ public function getPriority() { return 70; diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index 57112d0..efa5e16 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -29,43 +29,13 @@ use OCP\Settings\ISettings; class Personal implements ISettings { - /** - * @var IL10N - */ - private $l; - - /** - * @var ILogger - */ - private $logger; - - /** - * @var ConfigProxy - */ - private $config; - - /** - * @var IUserSession - */ - private $userSession; - - /** - * @var AppRepository - */ - private $appRepository; - public function __construct( - IL10N $l, - ILogger $logger, - ConfigProxy $config, - IUserSession $userSession, - AppRepository $appRepository + protected IL10N $l, + protected ILogger $logger, + protected ConfigProxy $config, + protected IUserSession $userSession, + protected AppRepository $appRepository ) { - $this->l = $l; - $this->logger = $logger; - $this->config = $config; - $this->userSession = $userSession; - $this->appRepository = $appRepository; } /** diff --git a/lib/Settings/PersonalSection.php b/lib/Settings/PersonalSection.php index 58a773f..9456ff7 100644 --- a/lib/Settings/PersonalSection.php +++ b/lib/Settings/PersonalSection.php @@ -26,34 +26,13 @@ use OCP\Settings\IIconSection; class PersonalSection implements IIconSection { - /** - * @var IL10N - */ - private $l; - - /** - * @var IURLGenerator - */ - private $url; - - /** - * @var ConfigProxy - */ - private $configProxy; - - public function __construct(IURLGenerator $url, IL10N $l, ConfigProxy $configProxy) - { - $this->url = $url; - $this->l = $l; - $this->configProxy = $configProxy; + public function __construct( + protected IURLGenerator $url, + protected IL10N $l, + protected ConfigProxy $configProxy + ) { } - /** - * returns the ID of the section. It is supposed to be a lower case string, - * e.g. 'ldap'. - * - * @returns string - */ public function getID() { if ($this->configProxy->getAppValueBool('force', '0')) { @@ -63,12 +42,6 @@ class PersonalSection implements IIconSection return Application::APP_ID; } - /** - * returns the translated name as it should be displayed, e.g. 'LDAP / AD - * integration'. Use the L10N service to translate it. - * - * @return string - */ public function getName() { if ($this->configProxy->getAppValueBool('force', '0')) { @@ -78,13 +51,6 @@ class PersonalSection implements IIconSection return $this->l->t(Application::APP_NAME); } - /** - * @return int whether the form should be rather on the top or bottom of - * the settings navigation. The sections are arranged in ascending order of - * the priority values. It is required to return a value between 0 and 99. - * - * E.g.: 70 - */ public function getPriority() { if ($this->configProxy->getAppValueBool('force', '0')) {