@@ -36,9 +36,9 @@ |
||
36 | 36 | */ |
37 | 37 | interface IConditionalWidget extends IWidget { |
38 | 38 | |
39 | - /** |
|
40 | - * @return bool Whether the widget is enabled and should be registered |
|
41 | - * @since 26.0.0 |
|
42 | - */ |
|
43 | - public function isEnabled(): bool; |
|
39 | + /** |
|
40 | + * @return bool Whether the widget is enabled and should be registered |
|
41 | + * @since 26.0.0 |
|
42 | + */ |
|
43 | + public function isEnabled(): bool; |
|
44 | 44 | } |
@@ -38,105 +38,105 @@ |
||
38 | 38 | |
39 | 39 | class Manager implements IManager { |
40 | 40 | |
41 | - /** @var array */ |
|
42 | - private $lazyWidgets = []; |
|
41 | + /** @var array */ |
|
42 | + private $lazyWidgets = []; |
|
43 | 43 | |
44 | - /** @var IWidget[] */ |
|
45 | - private $widgets = []; |
|
44 | + /** @var IWidget[] */ |
|
45 | + private $widgets = []; |
|
46 | 46 | |
47 | - private ContainerInterface $serverContainer; |
|
48 | - private ?IAppManager $appManager = null; |
|
47 | + private ContainerInterface $serverContainer; |
|
48 | + private ?IAppManager $appManager = null; |
|
49 | 49 | |
50 | - public function __construct(ContainerInterface $serverContainer) { |
|
51 | - $this->serverContainer = $serverContainer; |
|
52 | - } |
|
50 | + public function __construct(ContainerInterface $serverContainer) { |
|
51 | + $this->serverContainer = $serverContainer; |
|
52 | + } |
|
53 | 53 | |
54 | - private function registerWidget(IWidget $widget): void { |
|
55 | - if (array_key_exists($widget->getId(), $this->widgets)) { |
|
56 | - throw new InvalidArgumentException('Dashboard widget with this id has already been registered'); |
|
57 | - } |
|
54 | + private function registerWidget(IWidget $widget): void { |
|
55 | + if (array_key_exists($widget->getId(), $this->widgets)) { |
|
56 | + throw new InvalidArgumentException('Dashboard widget with this id has already been registered'); |
|
57 | + } |
|
58 | 58 | |
59 | - $this->widgets[$widget->getId()] = $widget; |
|
60 | - } |
|
59 | + $this->widgets[$widget->getId()] = $widget; |
|
60 | + } |
|
61 | 61 | |
62 | - public function lazyRegisterWidget(string $widgetClass, string $appId): void { |
|
63 | - $this->lazyWidgets[] = ['class' => $widgetClass, 'appId' => $appId]; |
|
64 | - } |
|
62 | + public function lazyRegisterWidget(string $widgetClass, string $appId): void { |
|
63 | + $this->lazyWidgets[] = ['class' => $widgetClass, 'appId' => $appId]; |
|
64 | + } |
|
65 | 65 | |
66 | - public function loadLazyPanels(): void { |
|
67 | - if ($this->appManager === null) { |
|
68 | - $this->appManager = $this->serverContainer->get(IAppManager::class); |
|
69 | - } |
|
70 | - $services = $this->lazyWidgets; |
|
71 | - foreach ($services as $service) { |
|
72 | - /** @psalm-suppress InvalidCatch */ |
|
73 | - try { |
|
74 | - if (!$this->appManager->isEnabledForUser($service['appId'])) { |
|
75 | - // all apps are registered, but some may not be enabled for the user |
|
76 | - continue; |
|
77 | - } |
|
78 | - /** @var IWidget $widget */ |
|
79 | - $widget = $this->serverContainer->get($service['class']); |
|
80 | - } catch (ContainerExceptionInterface $e) { |
|
81 | - /* |
|
66 | + public function loadLazyPanels(): void { |
|
67 | + if ($this->appManager === null) { |
|
68 | + $this->appManager = $this->serverContainer->get(IAppManager::class); |
|
69 | + } |
|
70 | + $services = $this->lazyWidgets; |
|
71 | + foreach ($services as $service) { |
|
72 | + /** @psalm-suppress InvalidCatch */ |
|
73 | + try { |
|
74 | + if (!$this->appManager->isEnabledForUser($service['appId'])) { |
|
75 | + // all apps are registered, but some may not be enabled for the user |
|
76 | + continue; |
|
77 | + } |
|
78 | + /** @var IWidget $widget */ |
|
79 | + $widget = $this->serverContainer->get($service['class']); |
|
80 | + } catch (ContainerExceptionInterface $e) { |
|
81 | + /* |
|
82 | 82 | * There is a circular dependency between the logger and the registry, so |
83 | 83 | * we can not inject it. Thus the static call. |
84 | 84 | */ |
85 | - \OC::$server->get(LoggerInterface::class)->critical( |
|
86 | - 'Could not load lazy dashboard widget: ' . $service['class'], |
|
87 | - ['exception' => $e] |
|
88 | - ); |
|
89 | - continue; |
|
90 | - } |
|
91 | - /** |
|
92 | - * Try to register the loaded reporter. Theoretically it could be of a wrong |
|
93 | - * type, so we might get a TypeError here that we should catch. |
|
94 | - */ |
|
95 | - try { |
|
96 | - if ($widget instanceof IConditionalWidget && !$widget->isEnabled()) { |
|
97 | - continue; |
|
98 | - } |
|
85 | + \OC::$server->get(LoggerInterface::class)->critical( |
|
86 | + 'Could not load lazy dashboard widget: ' . $service['class'], |
|
87 | + ['exception' => $e] |
|
88 | + ); |
|
89 | + continue; |
|
90 | + } |
|
91 | + /** |
|
92 | + * Try to register the loaded reporter. Theoretically it could be of a wrong |
|
93 | + * type, so we might get a TypeError here that we should catch. |
|
94 | + */ |
|
95 | + try { |
|
96 | + if ($widget instanceof IConditionalWidget && !$widget->isEnabled()) { |
|
97 | + continue; |
|
98 | + } |
|
99 | 99 | |
100 | - $this->registerWidget($widget); |
|
101 | - } catch (Throwable $e) { |
|
102 | - /* |
|
100 | + $this->registerWidget($widget); |
|
101 | + } catch (Throwable $e) { |
|
102 | + /* |
|
103 | 103 | * There is a circular dependency between the logger and the registry, so |
104 | 104 | * we can not inject it. Thus the static call. |
105 | 105 | */ |
106 | - \OC::$server->get(LoggerInterface::class)->critical( |
|
107 | - 'Could not register lazy dashboard widget: ' . $service['class'], |
|
108 | - ['exception' => $e] |
|
109 | - ); |
|
110 | - continue; |
|
111 | - } |
|
106 | + \OC::$server->get(LoggerInterface::class)->critical( |
|
107 | + 'Could not register lazy dashboard widget: ' . $service['class'], |
|
108 | + ['exception' => $e] |
|
109 | + ); |
|
110 | + continue; |
|
111 | + } |
|
112 | 112 | |
113 | - try { |
|
114 | - $startTime = microtime(true); |
|
115 | - $widget->load(); |
|
116 | - $endTime = microtime(true); |
|
117 | - $duration = $endTime - $startTime; |
|
118 | - if ($duration > 1) { |
|
119 | - \OC::$server->get(LoggerInterface::class)->error( |
|
120 | - 'Dashboard widget {widget} took {duration} seconds to load.', |
|
121 | - [ |
|
122 | - 'widget' => $widget->getId(), |
|
123 | - 'duration' => round($duration, 2), |
|
124 | - ] |
|
125 | - ); |
|
126 | - } |
|
127 | - } catch (Throwable $e) { |
|
128 | - \OC::$server->get(LoggerInterface::class)->critical( |
|
129 | - 'Error during dashboard widget loading: ' . $service['class'], |
|
130 | - ['exception' => $e] |
|
131 | - ); |
|
132 | - continue; |
|
133 | - } |
|
134 | - } |
|
135 | - $this->lazyWidgets = []; |
|
136 | - } |
|
113 | + try { |
|
114 | + $startTime = microtime(true); |
|
115 | + $widget->load(); |
|
116 | + $endTime = microtime(true); |
|
117 | + $duration = $endTime - $startTime; |
|
118 | + if ($duration > 1) { |
|
119 | + \OC::$server->get(LoggerInterface::class)->error( |
|
120 | + 'Dashboard widget {widget} took {duration} seconds to load.', |
|
121 | + [ |
|
122 | + 'widget' => $widget->getId(), |
|
123 | + 'duration' => round($duration, 2), |
|
124 | + ] |
|
125 | + ); |
|
126 | + } |
|
127 | + } catch (Throwable $e) { |
|
128 | + \OC::$server->get(LoggerInterface::class)->critical( |
|
129 | + 'Error during dashboard widget loading: ' . $service['class'], |
|
130 | + ['exception' => $e] |
|
131 | + ); |
|
132 | + continue; |
|
133 | + } |
|
134 | + } |
|
135 | + $this->lazyWidgets = []; |
|
136 | + } |
|
137 | 137 | |
138 | - public function getWidgets(): array { |
|
139 | - $this->loadLazyPanels(); |
|
140 | - return $this->widgets; |
|
141 | - } |
|
138 | + public function getWidgets(): array { |
|
139 | + $this->loadLazyPanels(); |
|
140 | + return $this->widgets; |
|
141 | + } |
|
142 | 142 | } |