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