@@ -36,330 +36,330 @@ |
||
36 | 36 | |
37 | 37 | class RegistrationContext { |
38 | 38 | |
39 | - /** @var array[] */ |
|
40 | - private $capabilities = []; |
|
41 | - |
|
42 | - /** @var array[] */ |
|
43 | - private $crashReporters = []; |
|
44 | - |
|
45 | - /** @var array[] */ |
|
46 | - private $services = []; |
|
47 | - |
|
48 | - /** @var array[] */ |
|
49 | - private $aliases = []; |
|
50 | - |
|
51 | - /** @var array[] */ |
|
52 | - private $parameters = []; |
|
53 | - |
|
54 | - /** @var array[] */ |
|
55 | - private $eventListeners = []; |
|
56 | - |
|
57 | - /** @var array[] */ |
|
58 | - private $middlewares = []; |
|
59 | - |
|
60 | - /** @var array[] */ |
|
61 | - private $searchProviders = []; |
|
62 | - |
|
63 | - /** @var ILogger */ |
|
64 | - private $logger; |
|
65 | - |
|
66 | - public function __construct(ILogger $logger) { |
|
67 | - $this->logger = $logger; |
|
68 | - } |
|
69 | - |
|
70 | - public function for(string $appId): IRegistrationContext { |
|
71 | - return new class($appId, $this) implements IRegistrationContext { |
|
72 | - /** @var string */ |
|
73 | - private $appId; |
|
74 | - |
|
75 | - /** @var RegistrationContext */ |
|
76 | - private $context; |
|
77 | - |
|
78 | - public function __construct(string $appId, RegistrationContext $context) { |
|
79 | - $this->appId = $appId; |
|
80 | - $this->context = $context; |
|
81 | - } |
|
82 | - |
|
83 | - public function registerCapability(string $capability): void { |
|
84 | - $this->context->registerCapability( |
|
85 | - $this->appId, |
|
86 | - $capability |
|
87 | - ); |
|
88 | - } |
|
89 | - |
|
90 | - public function registerCrashReporter(string $reporterClass): void { |
|
91 | - $this->context->registerCrashReporter( |
|
92 | - $this->appId, |
|
93 | - $reporterClass |
|
94 | - ); |
|
95 | - } |
|
96 | - |
|
97 | - public function registerService(string $name, callable $factory, bool $shared = true): void { |
|
98 | - $this->context->registerService( |
|
99 | - $this->appId, |
|
100 | - $name, |
|
101 | - $factory, |
|
102 | - $shared |
|
103 | - ); |
|
104 | - } |
|
105 | - |
|
106 | - public function registerServiceAlias(string $alias, string $target): void { |
|
107 | - $this->context->registerServiceAlias( |
|
108 | - $this->appId, |
|
109 | - $alias, |
|
110 | - $target |
|
111 | - ); |
|
112 | - } |
|
113 | - |
|
114 | - public function registerParameter(string $name, $value): void { |
|
115 | - $this->context->registerParameter( |
|
116 | - $this->appId, |
|
117 | - $name, |
|
118 | - $value |
|
119 | - ); |
|
120 | - } |
|
121 | - |
|
122 | - public function registerEventListener(string $event, string $listener, int $priority = 0): void { |
|
123 | - $this->context->registerEventListener( |
|
124 | - $this->appId, |
|
125 | - $event, |
|
126 | - $listener, |
|
127 | - $priority |
|
128 | - ); |
|
129 | - } |
|
130 | - |
|
131 | - public function registerMiddleware(string $class): void { |
|
132 | - $this->context->registerMiddleware( |
|
133 | - $this->appId, |
|
134 | - $class |
|
135 | - ); |
|
136 | - } |
|
137 | - |
|
138 | - public function registerSearchProvider(string $class): void { |
|
139 | - $this->context->registerSearchProvider( |
|
140 | - $this->appId, |
|
141 | - $class |
|
142 | - ); |
|
143 | - } |
|
144 | - }; |
|
145 | - } |
|
146 | - |
|
147 | - public function registerCapability(string $appId, string $capability): void { |
|
148 | - $this->capabilities[] = [ |
|
149 | - 'appId' => $appId, |
|
150 | - 'capability' => $capability |
|
151 | - ]; |
|
152 | - } |
|
153 | - |
|
154 | - public function registerCrashReporter(string $appId, string $reporterClass): void { |
|
155 | - $this->crashReporters[] = [ |
|
156 | - 'appId' => $appId, |
|
157 | - 'class' => $reporterClass, |
|
158 | - ]; |
|
159 | - } |
|
160 | - |
|
161 | - public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { |
|
162 | - $this->services[] = [ |
|
163 | - "appId" => $appId, |
|
164 | - "name" => $name, |
|
165 | - "factory" => $factory, |
|
166 | - "sharred" => $shared, |
|
167 | - ]; |
|
168 | - } |
|
169 | - |
|
170 | - public function registerServiceAlias(string $appId, string $alias, string $target): void { |
|
171 | - $this->aliases[] = [ |
|
172 | - "appId" => $appId, |
|
173 | - "alias" => $alias, |
|
174 | - "target" => $target, |
|
175 | - ]; |
|
176 | - } |
|
177 | - |
|
178 | - public function registerParameter(string $appId, string $name, $value): void { |
|
179 | - $this->parameters[] = [ |
|
180 | - "appId" => $appId, |
|
181 | - "name" => $name, |
|
182 | - "value" => $value, |
|
183 | - ]; |
|
184 | - } |
|
185 | - |
|
186 | - public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void { |
|
187 | - $this->eventListeners[] = [ |
|
188 | - "appId" => $appId, |
|
189 | - "event" => $event, |
|
190 | - "listener" => $listener, |
|
191 | - "priority" => $priority, |
|
192 | - ]; |
|
193 | - } |
|
194 | - |
|
195 | - public function registerMiddleware(string $appId, string $class): void { |
|
196 | - $this->middlewares[] = [ |
|
197 | - "appId" => $appId, |
|
198 | - "class" => $class, |
|
199 | - ]; |
|
200 | - } |
|
201 | - |
|
202 | - public function registerSearchProvider(string $appId, string $class) { |
|
203 | - $this->searchProviders[] = [ |
|
204 | - 'appId' => $appId, |
|
205 | - 'class' => $class, |
|
206 | - ]; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @param App[] $apps |
|
211 | - */ |
|
212 | - public function delegateCapabilityRegistrations(array $apps): void { |
|
213 | - foreach ($this->capabilities as $registration) { |
|
214 | - try { |
|
215 | - $apps[$registration['appId']] |
|
216 | - ->getContainer() |
|
217 | - ->registerCapability($registration['capability']); |
|
218 | - } catch (Throwable $e) { |
|
219 | - $appId = $registration['appId']; |
|
220 | - $this->logger->logException($e, [ |
|
221 | - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), |
|
222 | - 'level' => ILogger::ERROR, |
|
223 | - ]); |
|
224 | - } |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @param App[] $apps |
|
230 | - */ |
|
231 | - public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { |
|
232 | - foreach ($this->crashReporters as $registration) { |
|
233 | - try { |
|
234 | - $registry->registerLazy($registration['class']); |
|
235 | - } catch (Throwable $e) { |
|
236 | - $appId = $registration['appId']; |
|
237 | - $this->logger->logException($e, [ |
|
238 | - 'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(), |
|
239 | - 'level' => ILogger::ERROR, |
|
240 | - ]); |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { |
|
246 | - foreach ($this->eventListeners as $registration) { |
|
247 | - try { |
|
248 | - if (isset($registration['priority'])) { |
|
249 | - $eventDispatcher->addServiceListener( |
|
250 | - $registration['event'], |
|
251 | - $registration['listener'], |
|
252 | - $registration['priority'] |
|
253 | - ); |
|
254 | - } else { |
|
255 | - $eventDispatcher->addServiceListener( |
|
256 | - $registration['event'], |
|
257 | - $registration['listener'] |
|
258 | - ); |
|
259 | - } |
|
260 | - } catch (Throwable $e) { |
|
261 | - $appId = $registration['appId']; |
|
262 | - $this->logger->logException($e, [ |
|
263 | - 'message' => "Error during event listener registration of $appId: " . $e->getMessage(), |
|
264 | - 'level' => ILogger::ERROR, |
|
265 | - ]); |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * @param App[] $apps |
|
272 | - */ |
|
273 | - public function delegateContainerRegistrations(array $apps): void { |
|
274 | - foreach ($this->services as $registration) { |
|
275 | - try { |
|
276 | - /** |
|
277 | - * Register the service and convert the callable into a \Closure if necessary |
|
278 | - */ |
|
279 | - $apps[$registration['appId']] |
|
280 | - ->getContainer() |
|
281 | - ->registerService( |
|
282 | - $registration['name'], |
|
283 | - Closure::fromCallable($registration['factory']), |
|
284 | - $registration['shared'] ?? true |
|
285 | - ); |
|
286 | - } catch (Throwable $e) { |
|
287 | - $appId = $registration['appId']; |
|
288 | - $this->logger->logException($e, [ |
|
289 | - 'message' => "Error during service registration of $appId: " . $e->getMessage(), |
|
290 | - 'level' => ILogger::ERROR, |
|
291 | - ]); |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - foreach ($this->aliases as $registration) { |
|
296 | - try { |
|
297 | - $apps[$registration['appId']] |
|
298 | - ->getContainer() |
|
299 | - ->registerAlias( |
|
300 | - $registration['alias'], |
|
301 | - $registration['target'] |
|
302 | - ); |
|
303 | - } catch (Throwable $e) { |
|
304 | - $appId = $registration['appId']; |
|
305 | - $this->logger->logException($e, [ |
|
306 | - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), |
|
307 | - 'level' => ILogger::ERROR, |
|
308 | - ]); |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - foreach ($this->parameters as $registration) { |
|
313 | - try { |
|
314 | - $apps[$registration['appId']] |
|
315 | - ->getContainer() |
|
316 | - ->registerParameter( |
|
317 | - $registration['name'], |
|
318 | - $registration['value'] |
|
319 | - ); |
|
320 | - } catch (Throwable $e) { |
|
321 | - $appId = $registration['appId']; |
|
322 | - $this->logger->logException($e, [ |
|
323 | - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), |
|
324 | - 'level' => ILogger::ERROR, |
|
325 | - ]); |
|
326 | - } |
|
327 | - } |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * @param App[] $apps |
|
332 | - */ |
|
333 | - public function delegateMiddlewareRegistrations(array $apps): void { |
|
334 | - foreach ($this->middlewares as $middleware) { |
|
335 | - try { |
|
336 | - $apps[$middleware['appId']] |
|
337 | - ->getContainer() |
|
338 | - ->registerMiddleWare($middleware['class']); |
|
339 | - } catch (Throwable $e) { |
|
340 | - $appId = $middleware['appId']; |
|
341 | - $this->logger->logException($e, [ |
|
342 | - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), |
|
343 | - 'level' => ILogger::ERROR, |
|
344 | - ]); |
|
345 | - } |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * @param App[] $apps |
|
351 | - */ |
|
352 | - public function delegateSearchProviderRegistration(array $apps, SearchComposer $searchComposer): void { |
|
353 | - foreach ($this->searchProviders as $registration) { |
|
354 | - try { |
|
355 | - $searchComposer->registerProvider($registration['class']); |
|
356 | - } catch (Throwable $e) { |
|
357 | - $appId = $registration['appId']; |
|
358 | - $this->logger->logException($e, [ |
|
359 | - 'message' => "Error during search provider registration of $appId: " . $e->getMessage(), |
|
360 | - 'level' => ILogger::ERROR, |
|
361 | - ]); |
|
362 | - } |
|
363 | - } |
|
364 | - } |
|
39 | + /** @var array[] */ |
|
40 | + private $capabilities = []; |
|
41 | + |
|
42 | + /** @var array[] */ |
|
43 | + private $crashReporters = []; |
|
44 | + |
|
45 | + /** @var array[] */ |
|
46 | + private $services = []; |
|
47 | + |
|
48 | + /** @var array[] */ |
|
49 | + private $aliases = []; |
|
50 | + |
|
51 | + /** @var array[] */ |
|
52 | + private $parameters = []; |
|
53 | + |
|
54 | + /** @var array[] */ |
|
55 | + private $eventListeners = []; |
|
56 | + |
|
57 | + /** @var array[] */ |
|
58 | + private $middlewares = []; |
|
59 | + |
|
60 | + /** @var array[] */ |
|
61 | + private $searchProviders = []; |
|
62 | + |
|
63 | + /** @var ILogger */ |
|
64 | + private $logger; |
|
65 | + |
|
66 | + public function __construct(ILogger $logger) { |
|
67 | + $this->logger = $logger; |
|
68 | + } |
|
69 | + |
|
70 | + public function for(string $appId): IRegistrationContext { |
|
71 | + return new class($appId, $this) implements IRegistrationContext { |
|
72 | + /** @var string */ |
|
73 | + private $appId; |
|
74 | + |
|
75 | + /** @var RegistrationContext */ |
|
76 | + private $context; |
|
77 | + |
|
78 | + public function __construct(string $appId, RegistrationContext $context) { |
|
79 | + $this->appId = $appId; |
|
80 | + $this->context = $context; |
|
81 | + } |
|
82 | + |
|
83 | + public function registerCapability(string $capability): void { |
|
84 | + $this->context->registerCapability( |
|
85 | + $this->appId, |
|
86 | + $capability |
|
87 | + ); |
|
88 | + } |
|
89 | + |
|
90 | + public function registerCrashReporter(string $reporterClass): void { |
|
91 | + $this->context->registerCrashReporter( |
|
92 | + $this->appId, |
|
93 | + $reporterClass |
|
94 | + ); |
|
95 | + } |
|
96 | + |
|
97 | + public function registerService(string $name, callable $factory, bool $shared = true): void { |
|
98 | + $this->context->registerService( |
|
99 | + $this->appId, |
|
100 | + $name, |
|
101 | + $factory, |
|
102 | + $shared |
|
103 | + ); |
|
104 | + } |
|
105 | + |
|
106 | + public function registerServiceAlias(string $alias, string $target): void { |
|
107 | + $this->context->registerServiceAlias( |
|
108 | + $this->appId, |
|
109 | + $alias, |
|
110 | + $target |
|
111 | + ); |
|
112 | + } |
|
113 | + |
|
114 | + public function registerParameter(string $name, $value): void { |
|
115 | + $this->context->registerParameter( |
|
116 | + $this->appId, |
|
117 | + $name, |
|
118 | + $value |
|
119 | + ); |
|
120 | + } |
|
121 | + |
|
122 | + public function registerEventListener(string $event, string $listener, int $priority = 0): void { |
|
123 | + $this->context->registerEventListener( |
|
124 | + $this->appId, |
|
125 | + $event, |
|
126 | + $listener, |
|
127 | + $priority |
|
128 | + ); |
|
129 | + } |
|
130 | + |
|
131 | + public function registerMiddleware(string $class): void { |
|
132 | + $this->context->registerMiddleware( |
|
133 | + $this->appId, |
|
134 | + $class |
|
135 | + ); |
|
136 | + } |
|
137 | + |
|
138 | + public function registerSearchProvider(string $class): void { |
|
139 | + $this->context->registerSearchProvider( |
|
140 | + $this->appId, |
|
141 | + $class |
|
142 | + ); |
|
143 | + } |
|
144 | + }; |
|
145 | + } |
|
146 | + |
|
147 | + public function registerCapability(string $appId, string $capability): void { |
|
148 | + $this->capabilities[] = [ |
|
149 | + 'appId' => $appId, |
|
150 | + 'capability' => $capability |
|
151 | + ]; |
|
152 | + } |
|
153 | + |
|
154 | + public function registerCrashReporter(string $appId, string $reporterClass): void { |
|
155 | + $this->crashReporters[] = [ |
|
156 | + 'appId' => $appId, |
|
157 | + 'class' => $reporterClass, |
|
158 | + ]; |
|
159 | + } |
|
160 | + |
|
161 | + public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { |
|
162 | + $this->services[] = [ |
|
163 | + "appId" => $appId, |
|
164 | + "name" => $name, |
|
165 | + "factory" => $factory, |
|
166 | + "sharred" => $shared, |
|
167 | + ]; |
|
168 | + } |
|
169 | + |
|
170 | + public function registerServiceAlias(string $appId, string $alias, string $target): void { |
|
171 | + $this->aliases[] = [ |
|
172 | + "appId" => $appId, |
|
173 | + "alias" => $alias, |
|
174 | + "target" => $target, |
|
175 | + ]; |
|
176 | + } |
|
177 | + |
|
178 | + public function registerParameter(string $appId, string $name, $value): void { |
|
179 | + $this->parameters[] = [ |
|
180 | + "appId" => $appId, |
|
181 | + "name" => $name, |
|
182 | + "value" => $value, |
|
183 | + ]; |
|
184 | + } |
|
185 | + |
|
186 | + public function registerEventListener(string $appId, string $event, string $listener, int $priority = 0): void { |
|
187 | + $this->eventListeners[] = [ |
|
188 | + "appId" => $appId, |
|
189 | + "event" => $event, |
|
190 | + "listener" => $listener, |
|
191 | + "priority" => $priority, |
|
192 | + ]; |
|
193 | + } |
|
194 | + |
|
195 | + public function registerMiddleware(string $appId, string $class): void { |
|
196 | + $this->middlewares[] = [ |
|
197 | + "appId" => $appId, |
|
198 | + "class" => $class, |
|
199 | + ]; |
|
200 | + } |
|
201 | + |
|
202 | + public function registerSearchProvider(string $appId, string $class) { |
|
203 | + $this->searchProviders[] = [ |
|
204 | + 'appId' => $appId, |
|
205 | + 'class' => $class, |
|
206 | + ]; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @param App[] $apps |
|
211 | + */ |
|
212 | + public function delegateCapabilityRegistrations(array $apps): void { |
|
213 | + foreach ($this->capabilities as $registration) { |
|
214 | + try { |
|
215 | + $apps[$registration['appId']] |
|
216 | + ->getContainer() |
|
217 | + ->registerCapability($registration['capability']); |
|
218 | + } catch (Throwable $e) { |
|
219 | + $appId = $registration['appId']; |
|
220 | + $this->logger->logException($e, [ |
|
221 | + 'message' => "Error during capability registration of $appId: " . $e->getMessage(), |
|
222 | + 'level' => ILogger::ERROR, |
|
223 | + ]); |
|
224 | + } |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @param App[] $apps |
|
230 | + */ |
|
231 | + public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { |
|
232 | + foreach ($this->crashReporters as $registration) { |
|
233 | + try { |
|
234 | + $registry->registerLazy($registration['class']); |
|
235 | + } catch (Throwable $e) { |
|
236 | + $appId = $registration['appId']; |
|
237 | + $this->logger->logException($e, [ |
|
238 | + 'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(), |
|
239 | + 'level' => ILogger::ERROR, |
|
240 | + ]); |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { |
|
246 | + foreach ($this->eventListeners as $registration) { |
|
247 | + try { |
|
248 | + if (isset($registration['priority'])) { |
|
249 | + $eventDispatcher->addServiceListener( |
|
250 | + $registration['event'], |
|
251 | + $registration['listener'], |
|
252 | + $registration['priority'] |
|
253 | + ); |
|
254 | + } else { |
|
255 | + $eventDispatcher->addServiceListener( |
|
256 | + $registration['event'], |
|
257 | + $registration['listener'] |
|
258 | + ); |
|
259 | + } |
|
260 | + } catch (Throwable $e) { |
|
261 | + $appId = $registration['appId']; |
|
262 | + $this->logger->logException($e, [ |
|
263 | + 'message' => "Error during event listener registration of $appId: " . $e->getMessage(), |
|
264 | + 'level' => ILogger::ERROR, |
|
265 | + ]); |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * @param App[] $apps |
|
272 | + */ |
|
273 | + public function delegateContainerRegistrations(array $apps): void { |
|
274 | + foreach ($this->services as $registration) { |
|
275 | + try { |
|
276 | + /** |
|
277 | + * Register the service and convert the callable into a \Closure if necessary |
|
278 | + */ |
|
279 | + $apps[$registration['appId']] |
|
280 | + ->getContainer() |
|
281 | + ->registerService( |
|
282 | + $registration['name'], |
|
283 | + Closure::fromCallable($registration['factory']), |
|
284 | + $registration['shared'] ?? true |
|
285 | + ); |
|
286 | + } catch (Throwable $e) { |
|
287 | + $appId = $registration['appId']; |
|
288 | + $this->logger->logException($e, [ |
|
289 | + 'message' => "Error during service registration of $appId: " . $e->getMessage(), |
|
290 | + 'level' => ILogger::ERROR, |
|
291 | + ]); |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + foreach ($this->aliases as $registration) { |
|
296 | + try { |
|
297 | + $apps[$registration['appId']] |
|
298 | + ->getContainer() |
|
299 | + ->registerAlias( |
|
300 | + $registration['alias'], |
|
301 | + $registration['target'] |
|
302 | + ); |
|
303 | + } catch (Throwable $e) { |
|
304 | + $appId = $registration['appId']; |
|
305 | + $this->logger->logException($e, [ |
|
306 | + 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), |
|
307 | + 'level' => ILogger::ERROR, |
|
308 | + ]); |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + foreach ($this->parameters as $registration) { |
|
313 | + try { |
|
314 | + $apps[$registration['appId']] |
|
315 | + ->getContainer() |
|
316 | + ->registerParameter( |
|
317 | + $registration['name'], |
|
318 | + $registration['value'] |
|
319 | + ); |
|
320 | + } catch (Throwable $e) { |
|
321 | + $appId = $registration['appId']; |
|
322 | + $this->logger->logException($e, [ |
|
323 | + 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), |
|
324 | + 'level' => ILogger::ERROR, |
|
325 | + ]); |
|
326 | + } |
|
327 | + } |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * @param App[] $apps |
|
332 | + */ |
|
333 | + public function delegateMiddlewareRegistrations(array $apps): void { |
|
334 | + foreach ($this->middlewares as $middleware) { |
|
335 | + try { |
|
336 | + $apps[$middleware['appId']] |
|
337 | + ->getContainer() |
|
338 | + ->registerMiddleWare($middleware['class']); |
|
339 | + } catch (Throwable $e) { |
|
340 | + $appId = $middleware['appId']; |
|
341 | + $this->logger->logException($e, [ |
|
342 | + 'message' => "Error during capability registration of $appId: " . $e->getMessage(), |
|
343 | + 'level' => ILogger::ERROR, |
|
344 | + ]); |
|
345 | + } |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * @param App[] $apps |
|
351 | + */ |
|
352 | + public function delegateSearchProviderRegistration(array $apps, SearchComposer $searchComposer): void { |
|
353 | + foreach ($this->searchProviders as $registration) { |
|
354 | + try { |
|
355 | + $searchComposer->registerProvider($registration['class']); |
|
356 | + } catch (Throwable $e) { |
|
357 | + $appId = $registration['appId']; |
|
358 | + $this->logger->logException($e, [ |
|
359 | + 'message' => "Error during search provider registration of $appId: " . $e->getMessage(), |
|
360 | + 'level' => ILogger::ERROR, |
|
361 | + ]); |
|
362 | + } |
|
363 | + } |
|
364 | + } |
|
365 | 365 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $this->logger = $logger; |
68 | 68 | } |
69 | 69 | |
70 | - public function for(string $appId): IRegistrationContext { |
|
70 | + public function for (string $appId): IRegistrationContext { |
|
71 | 71 | return new class($appId, $this) implements IRegistrationContext { |
72 | 72 | /** @var string */ |
73 | 73 | private $appId; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } catch (Throwable $e) { |
219 | 219 | $appId = $registration['appId']; |
220 | 220 | $this->logger->logException($e, [ |
221 | - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), |
|
221 | + 'message' => "Error during capability registration of $appId: ".$e->getMessage(), |
|
222 | 222 | 'level' => ILogger::ERROR, |
223 | 223 | ]); |
224 | 224 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | } catch (Throwable $e) { |
236 | 236 | $appId = $registration['appId']; |
237 | 237 | $this->logger->logException($e, [ |
238 | - 'message' => "Error during crash reporter registration of $appId: " . $e->getMessage(), |
|
238 | + 'message' => "Error during crash reporter registration of $appId: ".$e->getMessage(), |
|
239 | 239 | 'level' => ILogger::ERROR, |
240 | 240 | ]); |
241 | 241 | } |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | } catch (Throwable $e) { |
261 | 261 | $appId = $registration['appId']; |
262 | 262 | $this->logger->logException($e, [ |
263 | - 'message' => "Error during event listener registration of $appId: " . $e->getMessage(), |
|
263 | + 'message' => "Error during event listener registration of $appId: ".$e->getMessage(), |
|
264 | 264 | 'level' => ILogger::ERROR, |
265 | 265 | ]); |
266 | 266 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | } catch (Throwable $e) { |
287 | 287 | $appId = $registration['appId']; |
288 | 288 | $this->logger->logException($e, [ |
289 | - 'message' => "Error during service registration of $appId: " . $e->getMessage(), |
|
289 | + 'message' => "Error during service registration of $appId: ".$e->getMessage(), |
|
290 | 290 | 'level' => ILogger::ERROR, |
291 | 291 | ]); |
292 | 292 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | } catch (Throwable $e) { |
304 | 304 | $appId = $registration['appId']; |
305 | 305 | $this->logger->logException($e, [ |
306 | - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), |
|
306 | + 'message' => "Error during service alias registration of $appId: ".$e->getMessage(), |
|
307 | 307 | 'level' => ILogger::ERROR, |
308 | 308 | ]); |
309 | 309 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | } catch (Throwable $e) { |
321 | 321 | $appId = $registration['appId']; |
322 | 322 | $this->logger->logException($e, [ |
323 | - 'message' => "Error during service alias registration of $appId: " . $e->getMessage(), |
|
323 | + 'message' => "Error during service alias registration of $appId: ".$e->getMessage(), |
|
324 | 324 | 'level' => ILogger::ERROR, |
325 | 325 | ]); |
326 | 326 | } |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | } catch (Throwable $e) { |
340 | 340 | $appId = $middleware['appId']; |
341 | 341 | $this->logger->logException($e, [ |
342 | - 'message' => "Error during capability registration of $appId: " . $e->getMessage(), |
|
342 | + 'message' => "Error during capability registration of $appId: ".$e->getMessage(), |
|
343 | 343 | 'level' => ILogger::ERROR, |
344 | 344 | ]); |
345 | 345 | } |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | } catch (Throwable $e) { |
357 | 357 | $appId = $registration['appId']; |
358 | 358 | $this->logger->logException($e, [ |
359 | - 'message' => "Error during search provider registration of $appId: " . $e->getMessage(), |
|
359 | + 'message' => "Error during search provider registration of $appId: ".$e->getMessage(), |
|
360 | 360 | 'level' => ILogger::ERROR, |
361 | 361 | ]); |
362 | 362 | } |
@@ -41,118 +41,118 @@ |
||
41 | 41 | |
42 | 42 | class Coordinator { |
43 | 43 | |
44 | - /** @var IServerContainer */ |
|
45 | - private $serverContainer; |
|
46 | - |
|
47 | - /** @var Registry */ |
|
48 | - private $registry; |
|
49 | - |
|
50 | - /** @var IEventDispatcher */ |
|
51 | - private $eventDispatcher; |
|
52 | - |
|
53 | - /** @var SearchComposer */ |
|
54 | - private $searchComposer; |
|
55 | - |
|
56 | - /** @var ILogger */ |
|
57 | - private $logger; |
|
58 | - |
|
59 | - public function __construct(IServerContainer $container, |
|
60 | - Registry $registry, |
|
61 | - IEventDispatcher $eventListener, |
|
62 | - SearchComposer $searchComposer, |
|
63 | - ILogger $logger) { |
|
64 | - $this->serverContainer = $container; |
|
65 | - $this->registry = $registry; |
|
66 | - $this->eventDispatcher = $eventListener; |
|
67 | - $this->searchComposer = $searchComposer; |
|
68 | - $this->logger = $logger; |
|
69 | - } |
|
70 | - |
|
71 | - public function runRegistration(): void { |
|
72 | - $context = new RegistrationContext($this->logger); |
|
73 | - $apps = []; |
|
74 | - foreach (OC_App::getEnabledApps() as $appId) { |
|
75 | - /* |
|
44 | + /** @var IServerContainer */ |
|
45 | + private $serverContainer; |
|
46 | + |
|
47 | + /** @var Registry */ |
|
48 | + private $registry; |
|
49 | + |
|
50 | + /** @var IEventDispatcher */ |
|
51 | + private $eventDispatcher; |
|
52 | + |
|
53 | + /** @var SearchComposer */ |
|
54 | + private $searchComposer; |
|
55 | + |
|
56 | + /** @var ILogger */ |
|
57 | + private $logger; |
|
58 | + |
|
59 | + public function __construct(IServerContainer $container, |
|
60 | + Registry $registry, |
|
61 | + IEventDispatcher $eventListener, |
|
62 | + SearchComposer $searchComposer, |
|
63 | + ILogger $logger) { |
|
64 | + $this->serverContainer = $container; |
|
65 | + $this->registry = $registry; |
|
66 | + $this->eventDispatcher = $eventListener; |
|
67 | + $this->searchComposer = $searchComposer; |
|
68 | + $this->logger = $logger; |
|
69 | + } |
|
70 | + |
|
71 | + public function runRegistration(): void { |
|
72 | + $context = new RegistrationContext($this->logger); |
|
73 | + $apps = []; |
|
74 | + foreach (OC_App::getEnabledApps() as $appId) { |
|
75 | + /* |
|
76 | 76 | * First, we have to enable the app's autoloader |
77 | 77 | * |
78 | 78 | * @todo use $this->appManager->getAppPath($appId) here |
79 | 79 | */ |
80 | - $path = OC_App::getAppPath($appId); |
|
81 | - if ($path === false) { |
|
82 | - // Ignore |
|
83 | - continue; |
|
84 | - } |
|
85 | - OC_App::registerAutoloading($appId, $path); |
|
86 | - |
|
87 | - /* |
|
80 | + $path = OC_App::getAppPath($appId); |
|
81 | + if ($path === false) { |
|
82 | + // Ignore |
|
83 | + continue; |
|
84 | + } |
|
85 | + OC_App::registerAutoloading($appId, $path); |
|
86 | + |
|
87 | + /* |
|
88 | 88 | * Next we check if there is an application class and it implements |
89 | 89 | * the \OCP\AppFramework\Bootstrap\IBootstrap interface |
90 | 90 | */ |
91 | - $appNameSpace = App::buildAppNamespace($appId); |
|
92 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
93 | - if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) { |
|
94 | - try { |
|
95 | - /** @var IBootstrap|App $application */ |
|
96 | - $apps[$appId] = $application = $this->serverContainer->query($applicationClassName); |
|
97 | - } catch (QueryException $e) { |
|
98 | - // Weird, but ok |
|
99 | - continue; |
|
100 | - } |
|
101 | - try { |
|
102 | - $application->register($context->for($appId)); |
|
103 | - } catch (Throwable $e) { |
|
104 | - $this->logger->logException($e, [ |
|
105 | - 'message' => 'Error during app service registration: ' . $e->getMessage(), |
|
106 | - 'level' => ILogger::FATAL, |
|
107 | - ]); |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Now that all register methods have been called, we can delegate the registrations |
|
114 | - * to the actual services |
|
115 | - */ |
|
116 | - $context->delegateCapabilityRegistrations($apps); |
|
117 | - $context->delegateCrashReporterRegistrations($apps, $this->registry); |
|
118 | - $context->delegateEventListenerRegistrations($this->eventDispatcher); |
|
119 | - $context->delegateContainerRegistrations($apps); |
|
120 | - $context->delegateMiddlewareRegistrations($apps); |
|
121 | - $context->delegateSearchProviderRegistration($apps, $this->searchComposer); |
|
122 | - } |
|
123 | - |
|
124 | - public function bootApp(string $appId): void { |
|
125 | - $appNameSpace = App::buildAppNamespace($appId); |
|
126 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
127 | - if (!class_exists($applicationClassName)) { |
|
128 | - // Nothing to boot |
|
129 | - return; |
|
130 | - } |
|
131 | - |
|
132 | - /* |
|
91 | + $appNameSpace = App::buildAppNamespace($appId); |
|
92 | + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
93 | + if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) { |
|
94 | + try { |
|
95 | + /** @var IBootstrap|App $application */ |
|
96 | + $apps[$appId] = $application = $this->serverContainer->query($applicationClassName); |
|
97 | + } catch (QueryException $e) { |
|
98 | + // Weird, but ok |
|
99 | + continue; |
|
100 | + } |
|
101 | + try { |
|
102 | + $application->register($context->for($appId)); |
|
103 | + } catch (Throwable $e) { |
|
104 | + $this->logger->logException($e, [ |
|
105 | + 'message' => 'Error during app service registration: ' . $e->getMessage(), |
|
106 | + 'level' => ILogger::FATAL, |
|
107 | + ]); |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Now that all register methods have been called, we can delegate the registrations |
|
114 | + * to the actual services |
|
115 | + */ |
|
116 | + $context->delegateCapabilityRegistrations($apps); |
|
117 | + $context->delegateCrashReporterRegistrations($apps, $this->registry); |
|
118 | + $context->delegateEventListenerRegistrations($this->eventDispatcher); |
|
119 | + $context->delegateContainerRegistrations($apps); |
|
120 | + $context->delegateMiddlewareRegistrations($apps); |
|
121 | + $context->delegateSearchProviderRegistration($apps, $this->searchComposer); |
|
122 | + } |
|
123 | + |
|
124 | + public function bootApp(string $appId): void { |
|
125 | + $appNameSpace = App::buildAppNamespace($appId); |
|
126 | + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
127 | + if (!class_exists($applicationClassName)) { |
|
128 | + // Nothing to boot |
|
129 | + return; |
|
130 | + } |
|
131 | + |
|
132 | + /* |
|
133 | 133 | * Now it is time to fetch an instance of the App class. For classes |
134 | 134 | * that implement \OCP\AppFramework\Bootstrap\IBootstrap this means |
135 | 135 | * the instance was already created for register, but any other |
136 | 136 | * (legacy) code will now do their magic via the constructor. |
137 | 137 | */ |
138 | - try { |
|
139 | - /** @var App $application */ |
|
140 | - $application = $this->serverContainer->query($applicationClassName); |
|
141 | - if ($application instanceof IBootstrap) { |
|
142 | - /** @var BootContext $context */ |
|
143 | - $context = new BootContext($application->getContainer()); |
|
144 | - $application->boot($context); |
|
145 | - } |
|
146 | - } catch (QueryException $e) { |
|
147 | - $this->logger->logException($e, [ |
|
148 | - 'message' => "Could not boot $appId" . $e->getMessage(), |
|
149 | - ]); |
|
150 | - return; |
|
151 | - } catch (Throwable $e) { |
|
152 | - $this->logger->logException($e, [ |
|
153 | - 'message' => "Could not boot $appId" . $e->getMessage(), |
|
154 | - 'level' => ILogger::FATAL, |
|
155 | - ]); |
|
156 | - } |
|
157 | - } |
|
138 | + try { |
|
139 | + /** @var App $application */ |
|
140 | + $application = $this->serverContainer->query($applicationClassName); |
|
141 | + if ($application instanceof IBootstrap) { |
|
142 | + /** @var BootContext $context */ |
|
143 | + $context = new BootContext($application->getContainer()); |
|
144 | + $application->boot($context); |
|
145 | + } |
|
146 | + } catch (QueryException $e) { |
|
147 | + $this->logger->logException($e, [ |
|
148 | + 'message' => "Could not boot $appId" . $e->getMessage(), |
|
149 | + ]); |
|
150 | + return; |
|
151 | + } catch (Throwable $e) { |
|
152 | + $this->logger->logException($e, [ |
|
153 | + 'message' => "Could not boot $appId" . $e->getMessage(), |
|
154 | + 'level' => ILogger::FATAL, |
|
155 | + ]); |
|
156 | + } |
|
157 | + } |
|
158 | 158 | } |
@@ -36,45 +36,45 @@ |
||
36 | 36 | */ |
37 | 37 | class File extends \OCP\Search\Provider { |
38 | 38 | |
39 | - /** |
|
40 | - * Search for files and folders matching the given query |
|
41 | - * @param string $query |
|
42 | - * @return \OCP\Search\Result |
|
43 | - * @deprecated 20.0.0 |
|
44 | - */ |
|
45 | - public function search($query) { |
|
46 | - $files = Filesystem::search($query); |
|
47 | - $results = []; |
|
48 | - // edit results |
|
49 | - foreach ($files as $fileData) { |
|
50 | - // skip versions |
|
51 | - if (strpos($fileData['path'], '_versions') === 0) { |
|
52 | - continue; |
|
53 | - } |
|
54 | - // skip top-level folder |
|
55 | - if ($fileData['name'] === 'files' && $fileData['parent'] === -1) { |
|
56 | - continue; |
|
57 | - } |
|
58 | - // create audio result |
|
59 | - if ($fileData['mimepart'] === 'audio') { |
|
60 | - $result = new \OC\Search\Result\Audio($fileData); |
|
61 | - } |
|
62 | - // create image result |
|
63 | - elseif ($fileData['mimepart'] === 'image') { |
|
64 | - $result = new \OC\Search\Result\Image($fileData); |
|
65 | - } |
|
66 | - // create folder result |
|
67 | - elseif ($fileData['mimetype'] === 'httpd/unix-directory') { |
|
68 | - $result = new \OC\Search\Result\Folder($fileData); |
|
69 | - } |
|
70 | - // or create file result |
|
71 | - else { |
|
72 | - $result = new \OC\Search\Result\File($fileData); |
|
73 | - } |
|
74 | - // add to results |
|
75 | - $results[] = $result; |
|
76 | - } |
|
77 | - // return |
|
78 | - return $results; |
|
79 | - } |
|
39 | + /** |
|
40 | + * Search for files and folders matching the given query |
|
41 | + * @param string $query |
|
42 | + * @return \OCP\Search\Result |
|
43 | + * @deprecated 20.0.0 |
|
44 | + */ |
|
45 | + public function search($query) { |
|
46 | + $files = Filesystem::search($query); |
|
47 | + $results = []; |
|
48 | + // edit results |
|
49 | + foreach ($files as $fileData) { |
|
50 | + // skip versions |
|
51 | + if (strpos($fileData['path'], '_versions') === 0) { |
|
52 | + continue; |
|
53 | + } |
|
54 | + // skip top-level folder |
|
55 | + if ($fileData['name'] === 'files' && $fileData['parent'] === -1) { |
|
56 | + continue; |
|
57 | + } |
|
58 | + // create audio result |
|
59 | + if ($fileData['mimepart'] === 'audio') { |
|
60 | + $result = new \OC\Search\Result\Audio($fileData); |
|
61 | + } |
|
62 | + // create image result |
|
63 | + elseif ($fileData['mimepart'] === 'image') { |
|
64 | + $result = new \OC\Search\Result\Image($fileData); |
|
65 | + } |
|
66 | + // create folder result |
|
67 | + elseif ($fileData['mimetype'] === 'httpd/unix-directory') { |
|
68 | + $result = new \OC\Search\Result\Folder($fileData); |
|
69 | + } |
|
70 | + // or create file result |
|
71 | + else { |
|
72 | + $result = new \OC\Search\Result\File($fileData); |
|
73 | + } |
|
74 | + // add to results |
|
75 | + $results[] = $result; |
|
76 | + } |
|
77 | + // return |
|
78 | + return $results; |
|
79 | + } |
|
80 | 80 | } |
@@ -28,61 +28,61 @@ |
||
28 | 28 | use OCP\Search\ISearchQuery; |
29 | 29 | |
30 | 30 | class SearchQuery implements ISearchQuery { |
31 | - public const LIMIT_DEFAULT = 20; |
|
31 | + public const LIMIT_DEFAULT = 20; |
|
32 | 32 | |
33 | - /** @var string */ |
|
34 | - private $term; |
|
33 | + /** @var string */ |
|
34 | + private $term; |
|
35 | 35 | |
36 | - /** @var int */ |
|
37 | - private $sortOrder; |
|
36 | + /** @var int */ |
|
37 | + private $sortOrder; |
|
38 | 38 | |
39 | - /** @var int */ |
|
40 | - private $limit; |
|
39 | + /** @var int */ |
|
40 | + private $limit; |
|
41 | 41 | |
42 | - /** @var int|string|null */ |
|
43 | - private $cursor; |
|
42 | + /** @var int|string|null */ |
|
43 | + private $cursor; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $term |
|
47 | - * @param int $sortOrder |
|
48 | - * @param int $limit |
|
49 | - * @param int|string|null $cursor |
|
50 | - */ |
|
51 | - public function __construct(string $term, |
|
52 | - int $sortOrder = ISearchQuery::SORT_DATE_DESC, |
|
53 | - int $limit = self::LIMIT_DEFAULT, |
|
54 | - $cursor = null) { |
|
55 | - $this->term = $term; |
|
56 | - $this->sortOrder = $sortOrder; |
|
57 | - $this->limit = $limit; |
|
58 | - $this->cursor = $cursor; |
|
59 | - } |
|
45 | + /** |
|
46 | + * @param string $term |
|
47 | + * @param int $sortOrder |
|
48 | + * @param int $limit |
|
49 | + * @param int|string|null $cursor |
|
50 | + */ |
|
51 | + public function __construct(string $term, |
|
52 | + int $sortOrder = ISearchQuery::SORT_DATE_DESC, |
|
53 | + int $limit = self::LIMIT_DEFAULT, |
|
54 | + $cursor = null) { |
|
55 | + $this->term = $term; |
|
56 | + $this->sortOrder = $sortOrder; |
|
57 | + $this->limit = $limit; |
|
58 | + $this->cursor = $cursor; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @inheritDoc |
|
63 | - */ |
|
64 | - public function getTerm(): string { |
|
65 | - return $this->term; |
|
66 | - } |
|
61 | + /** |
|
62 | + * @inheritDoc |
|
63 | + */ |
|
64 | + public function getTerm(): string { |
|
65 | + return $this->term; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @inheritDoc |
|
70 | - */ |
|
71 | - public function getSortOrder(): int { |
|
72 | - return $this->sortOrder; |
|
73 | - } |
|
68 | + /** |
|
69 | + * @inheritDoc |
|
70 | + */ |
|
71 | + public function getSortOrder(): int { |
|
72 | + return $this->sortOrder; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @inheritDoc |
|
77 | - */ |
|
78 | - public function getLimit(): int { |
|
79 | - return $this->limit; |
|
80 | - } |
|
75 | + /** |
|
76 | + * @inheritDoc |
|
77 | + */ |
|
78 | + public function getLimit(): int { |
|
79 | + return $this->limit; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @inheritDoc |
|
84 | - */ |
|
85 | - public function getCursor() { |
|
86 | - return $this->cursor; |
|
87 | - } |
|
82 | + /** |
|
83 | + * @inheritDoc |
|
84 | + */ |
|
85 | + public function getCursor() { |
|
86 | + return $this->cursor; |
|
87 | + } |
|
88 | 88 | } |
@@ -57,98 +57,98 @@ |
||
57 | 57 | */ |
58 | 58 | class SearchComposer { |
59 | 59 | |
60 | - /** @var string[] */ |
|
61 | - private $lazyProviders = []; |
|
62 | - |
|
63 | - /** @var IProvider[] */ |
|
64 | - private $providers = []; |
|
65 | - |
|
66 | - /** @var IServerContainer */ |
|
67 | - private $container; |
|
68 | - |
|
69 | - /** @var ILogger */ |
|
70 | - private $logger; |
|
71 | - |
|
72 | - public function __construct(IServerContainer $container, |
|
73 | - ILogger $logger) { |
|
74 | - $this->container = $container; |
|
75 | - $this->logger = $logger; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Register a search provider lazily |
|
80 | - * |
|
81 | - * Registers the fully-qualified class name of an implementation of an |
|
82 | - * IProvider. The service will only be queried on demand. Apps will register |
|
83 | - * the providers through the registration context object. |
|
84 | - * |
|
85 | - * @see IRegistrationContext::registerSearchProvider() |
|
86 | - * |
|
87 | - * @param string $class |
|
88 | - */ |
|
89 | - public function registerProvider(string $class): void { |
|
90 | - $this->lazyProviders[] = $class; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Load all providers dynamically that were registered through `registerProvider` |
|
95 | - * |
|
96 | - * If a provider can't be loaded we log it but the operation continues nevertheless |
|
97 | - */ |
|
98 | - private function loadLazyProviders(): void { |
|
99 | - $classes = $this->lazyProviders; |
|
100 | - foreach ($classes as $class) { |
|
101 | - try { |
|
102 | - /** @var IProvider $provider */ |
|
103 | - $provider = $this->container->query($class); |
|
104 | - $this->providers[$provider->getId()] = $provider; |
|
105 | - } catch (QueryException $e) { |
|
106 | - // Log an continue. We can be fault tolerant here. |
|
107 | - $this->logger->logException($e, [ |
|
108 | - 'message' => 'Could not load search provider dynamically: ' . $e->getMessage(), |
|
109 | - 'level' => ILogger::ERROR, |
|
110 | - ]); |
|
111 | - } |
|
112 | - } |
|
113 | - $this->lazyProviders = []; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Get a list of all provider IDs for the consecutive calls to `search` |
|
118 | - * |
|
119 | - * @return string[] |
|
120 | - */ |
|
121 | - public function getProviders(): array { |
|
122 | - $this->loadLazyProviders(); |
|
123 | - |
|
124 | - /** |
|
125 | - * Return an array with the IDs, but strip the associative keys |
|
126 | - */ |
|
127 | - return array_values( |
|
128 | - array_map(function (IProvider $provider) { |
|
129 | - return $provider->getId(); |
|
130 | - }, $this->providers)); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Query an individual search provider for results |
|
135 | - * |
|
136 | - * @param IUser $user |
|
137 | - * @param string $providerId one of the IDs received by `getProviders` |
|
138 | - * @param ISearchQuery $query |
|
139 | - * |
|
140 | - * @return SearchResult |
|
141 | - * @throws InvalidArgumentException when the $providerId does not correspond to a registered provider |
|
142 | - */ |
|
143 | - public function search(IUser $user, |
|
144 | - string $providerId, |
|
145 | - ISearchQuery $query): SearchResult { |
|
146 | - $this->loadLazyProviders(); |
|
147 | - |
|
148 | - $provider = $this->providers[$providerId] ?? null; |
|
149 | - if ($provider === null) { |
|
150 | - throw new InvalidArgumentException("Provider $providerId is unknown"); |
|
151 | - } |
|
152 | - return $provider->search($user, $query); |
|
153 | - } |
|
60 | + /** @var string[] */ |
|
61 | + private $lazyProviders = []; |
|
62 | + |
|
63 | + /** @var IProvider[] */ |
|
64 | + private $providers = []; |
|
65 | + |
|
66 | + /** @var IServerContainer */ |
|
67 | + private $container; |
|
68 | + |
|
69 | + /** @var ILogger */ |
|
70 | + private $logger; |
|
71 | + |
|
72 | + public function __construct(IServerContainer $container, |
|
73 | + ILogger $logger) { |
|
74 | + $this->container = $container; |
|
75 | + $this->logger = $logger; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Register a search provider lazily |
|
80 | + * |
|
81 | + * Registers the fully-qualified class name of an implementation of an |
|
82 | + * IProvider. The service will only be queried on demand. Apps will register |
|
83 | + * the providers through the registration context object. |
|
84 | + * |
|
85 | + * @see IRegistrationContext::registerSearchProvider() |
|
86 | + * |
|
87 | + * @param string $class |
|
88 | + */ |
|
89 | + public function registerProvider(string $class): void { |
|
90 | + $this->lazyProviders[] = $class; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Load all providers dynamically that were registered through `registerProvider` |
|
95 | + * |
|
96 | + * If a provider can't be loaded we log it but the operation continues nevertheless |
|
97 | + */ |
|
98 | + private function loadLazyProviders(): void { |
|
99 | + $classes = $this->lazyProviders; |
|
100 | + foreach ($classes as $class) { |
|
101 | + try { |
|
102 | + /** @var IProvider $provider */ |
|
103 | + $provider = $this->container->query($class); |
|
104 | + $this->providers[$provider->getId()] = $provider; |
|
105 | + } catch (QueryException $e) { |
|
106 | + // Log an continue. We can be fault tolerant here. |
|
107 | + $this->logger->logException($e, [ |
|
108 | + 'message' => 'Could not load search provider dynamically: ' . $e->getMessage(), |
|
109 | + 'level' => ILogger::ERROR, |
|
110 | + ]); |
|
111 | + } |
|
112 | + } |
|
113 | + $this->lazyProviders = []; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Get a list of all provider IDs for the consecutive calls to `search` |
|
118 | + * |
|
119 | + * @return string[] |
|
120 | + */ |
|
121 | + public function getProviders(): array { |
|
122 | + $this->loadLazyProviders(); |
|
123 | + |
|
124 | + /** |
|
125 | + * Return an array with the IDs, but strip the associative keys |
|
126 | + */ |
|
127 | + return array_values( |
|
128 | + array_map(function (IProvider $provider) { |
|
129 | + return $provider->getId(); |
|
130 | + }, $this->providers)); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Query an individual search provider for results |
|
135 | + * |
|
136 | + * @param IUser $user |
|
137 | + * @param string $providerId one of the IDs received by `getProviders` |
|
138 | + * @param ISearchQuery $query |
|
139 | + * |
|
140 | + * @return SearchResult |
|
141 | + * @throws InvalidArgumentException when the $providerId does not correspond to a registered provider |
|
142 | + */ |
|
143 | + public function search(IUser $user, |
|
144 | + string $providerId, |
|
145 | + ISearchQuery $query): SearchResult { |
|
146 | + $this->loadLazyProviders(); |
|
147 | + |
|
148 | + $provider = $this->providers[$providerId] ?? null; |
|
149 | + if ($provider === null) { |
|
150 | + throw new InvalidArgumentException("Provider $providerId is unknown"); |
|
151 | + } |
|
152 | + return $provider->search($user, $query); |
|
153 | + } |
|
154 | 154 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | } catch (QueryException $e) { |
106 | 106 | // Log an continue. We can be fault tolerant here. |
107 | 107 | $this->logger->logException($e, [ |
108 | - 'message' => 'Could not load search provider dynamically: ' . $e->getMessage(), |
|
108 | + 'message' => 'Could not load search provider dynamically: '.$e->getMessage(), |
|
109 | 109 | 'level' => ILogger::ERROR, |
110 | 110 | ]); |
111 | 111 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * Return an array with the IDs, but strip the associative keys |
126 | 126 | */ |
127 | 127 | return array_values( |
128 | - array_map(function (IProvider $provider) { |
|
128 | + array_map(function(IProvider $provider) { |
|
129 | 129 | return $provider->getId(); |
130 | 130 | }, $this->providers)); |
131 | 131 | } |
@@ -31,14 +31,14 @@ |
||
31 | 31 | */ |
32 | 32 | class Image extends File { |
33 | 33 | |
34 | - /** |
|
35 | - * Type name; translated in templates |
|
36 | - * @var string |
|
37 | - * @deprecated 20.0.0 |
|
38 | - */ |
|
39 | - public $type = 'image'; |
|
34 | + /** |
|
35 | + * Type name; translated in templates |
|
36 | + * @var string |
|
37 | + * @deprecated 20.0.0 |
|
38 | + */ |
|
39 | + public $type = 'image'; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @TODO add EXIF information |
|
43 | - */ |
|
41 | + /** |
|
42 | + * @TODO add EXIF information |
|
43 | + */ |
|
44 | 44 | } |
@@ -31,10 +31,10 @@ |
||
31 | 31 | */ |
32 | 32 | class Folder extends File { |
33 | 33 | |
34 | - /** |
|
35 | - * Type name; translated in templates |
|
36 | - * @var string |
|
37 | - * @deprecated 20.0.0 |
|
38 | - */ |
|
39 | - public $type = 'folder'; |
|
34 | + /** |
|
35 | + * Type name; translated in templates |
|
36 | + * @var string |
|
37 | + * @deprecated 20.0.0 |
|
38 | + */ |
|
39 | + public $type = 'folder'; |
|
40 | 40 | } |
@@ -31,14 +31,14 @@ |
||
31 | 31 | */ |
32 | 32 | class Audio extends File { |
33 | 33 | |
34 | - /** |
|
35 | - * Type name; translated in templates |
|
36 | - * @var string |
|
37 | - * @deprecated 20.0.0 |
|
38 | - */ |
|
39 | - public $type = 'audio'; |
|
34 | + /** |
|
35 | + * Type name; translated in templates |
|
36 | + * @var string |
|
37 | + * @deprecated 20.0.0 |
|
38 | + */ |
|
39 | + public $type = 'audio'; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @TODO add ID3 information |
|
43 | - */ |
|
41 | + /** |
|
42 | + * @TODO add ID3 information |
|
43 | + */ |
|
44 | 44 | } |
@@ -35,92 +35,92 @@ |
||
35 | 35 | */ |
36 | 36 | class File extends \OCP\Search\Result { |
37 | 37 | |
38 | - /** |
|
39 | - * Type name; translated in templates |
|
40 | - * @var string |
|
41 | - * @deprecated 20.0.0 |
|
42 | - */ |
|
43 | - public $type = 'file'; |
|
38 | + /** |
|
39 | + * Type name; translated in templates |
|
40 | + * @var string |
|
41 | + * @deprecated 20.0.0 |
|
42 | + */ |
|
43 | + public $type = 'file'; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Path to file |
|
47 | - * @var string |
|
48 | - * @deprecated 20.0.0 |
|
49 | - */ |
|
50 | - public $path; |
|
45 | + /** |
|
46 | + * Path to file |
|
47 | + * @var string |
|
48 | + * @deprecated 20.0.0 |
|
49 | + */ |
|
50 | + public $path; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Size, in bytes |
|
54 | - * @var int |
|
55 | - * @deprecated 20.0.0 |
|
56 | - */ |
|
57 | - public $size; |
|
52 | + /** |
|
53 | + * Size, in bytes |
|
54 | + * @var int |
|
55 | + * @deprecated 20.0.0 |
|
56 | + */ |
|
57 | + public $size; |
|
58 | 58 | |
59 | - /** |
|
60 | - * Date modified, in human readable form |
|
61 | - * @var string |
|
62 | - * @deprecated 20.0.0 |
|
63 | - */ |
|
64 | - public $modified; |
|
59 | + /** |
|
60 | + * Date modified, in human readable form |
|
61 | + * @var string |
|
62 | + * @deprecated 20.0.0 |
|
63 | + */ |
|
64 | + public $modified; |
|
65 | 65 | |
66 | - /** |
|
67 | - * File mime type |
|
68 | - * @var string |
|
69 | - * @deprecated 20.0.0 |
|
70 | - */ |
|
71 | - public $mime_type; |
|
66 | + /** |
|
67 | + * File mime type |
|
68 | + * @var string |
|
69 | + * @deprecated 20.0.0 |
|
70 | + */ |
|
71 | + public $mime_type; |
|
72 | 72 | |
73 | - /** |
|
74 | - * File permissions: |
|
75 | - * |
|
76 | - * @var string |
|
77 | - * @deprecated 20.0.0 |
|
78 | - */ |
|
79 | - public $permissions; |
|
73 | + /** |
|
74 | + * File permissions: |
|
75 | + * |
|
76 | + * @var string |
|
77 | + * @deprecated 20.0.0 |
|
78 | + */ |
|
79 | + public $permissions; |
|
80 | 80 | |
81 | - /** |
|
82 | - * Create a new file search result |
|
83 | - * @param FileInfo $data file data given by provider |
|
84 | - * @deprecated 20.0.0 |
|
85 | - */ |
|
86 | - public function __construct(FileInfo $data) { |
|
87 | - $path = $this->getRelativePath($data->getPath()); |
|
81 | + /** |
|
82 | + * Create a new file search result |
|
83 | + * @param FileInfo $data file data given by provider |
|
84 | + * @deprecated 20.0.0 |
|
85 | + */ |
|
86 | + public function __construct(FileInfo $data) { |
|
87 | + $path = $this->getRelativePath($data->getPath()); |
|
88 | 88 | |
89 | - $info = pathinfo($path); |
|
90 | - $this->id = $data->getId(); |
|
91 | - $this->name = $info['basename']; |
|
92 | - $this->link = \OC::$server->getURLGenerator()->linkToRoute( |
|
93 | - 'files.view.index', |
|
94 | - [ |
|
95 | - 'dir' => $info['dirname'], |
|
96 | - 'scrollto' => $info['basename'], |
|
97 | - ] |
|
98 | - ); |
|
99 | - $this->permissions = $data->getPermissions(); |
|
100 | - $this->path = $path; |
|
101 | - $this->size = $data->getSize(); |
|
102 | - $this->modified = $data->getMtime(); |
|
103 | - $this->mime_type = $data->getMimetype(); |
|
104 | - } |
|
89 | + $info = pathinfo($path); |
|
90 | + $this->id = $data->getId(); |
|
91 | + $this->name = $info['basename']; |
|
92 | + $this->link = \OC::$server->getURLGenerator()->linkToRoute( |
|
93 | + 'files.view.index', |
|
94 | + [ |
|
95 | + 'dir' => $info['dirname'], |
|
96 | + 'scrollto' => $info['basename'], |
|
97 | + ] |
|
98 | + ); |
|
99 | + $this->permissions = $data->getPermissions(); |
|
100 | + $this->path = $path; |
|
101 | + $this->size = $data->getSize(); |
|
102 | + $this->modified = $data->getMtime(); |
|
103 | + $this->mime_type = $data->getMimetype(); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @var Folder $userFolderCache |
|
108 | - * @deprecated 20.0.0 |
|
109 | - */ |
|
110 | - protected static $userFolderCache = null; |
|
106 | + /** |
|
107 | + * @var Folder $userFolderCache |
|
108 | + * @deprecated 20.0.0 |
|
109 | + */ |
|
110 | + protected static $userFolderCache = null; |
|
111 | 111 | |
112 | - /** |
|
113 | - * converts a path relative to the users files folder |
|
114 | - * eg /user/files/foo.txt -> /foo.txt |
|
115 | - * @param string $path |
|
116 | - * @return string relative path |
|
117 | - * @deprecated 20.0.0 |
|
118 | - */ |
|
119 | - protected function getRelativePath($path) { |
|
120 | - if (!isset(self::$userFolderCache)) { |
|
121 | - $user = \OC::$server->getUserSession()->getUser()->getUID(); |
|
122 | - self::$userFolderCache = \OC::$server->getUserFolder($user); |
|
123 | - } |
|
124 | - return self::$userFolderCache->getRelativePath($path); |
|
125 | - } |
|
112 | + /** |
|
113 | + * converts a path relative to the users files folder |
|
114 | + * eg /user/files/foo.txt -> /foo.txt |
|
115 | + * @param string $path |
|
116 | + * @return string relative path |
|
117 | + * @deprecated 20.0.0 |
|
118 | + */ |
|
119 | + protected function getRelativePath($path) { |
|
120 | + if (!isset(self::$userFolderCache)) { |
|
121 | + $user = \OC::$server->getUserSession()->getUser()->getUID(); |
|
122 | + self::$userFolderCache = \OC::$server->getUserFolder($user); |
|
123 | + } |
|
124 | + return self::$userFolderCache->getRelativePath($path); |
|
125 | + } |
|
126 | 126 | } |