Move initialstate bootstrap to proper types classes
For more type safety Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
7198bed22d
commit
2e6cab4d82
|
@ -35,6 +35,7 @@ use OC\Support\CrashReport\Registry;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||||
use OCP\AppFramework\Middleware;
|
use OCP\AppFramework\Middleware;
|
||||||
|
use OCP\AppFramework\Services\InitialStateProvider;
|
||||||
use OCP\Authentication\IAlternativeLogin;
|
use OCP\Authentication\IAlternativeLogin;
|
||||||
use OCP\Capabilities\ICapability;
|
use OCP\Capabilities\ICapability;
|
||||||
use OCP\Dashboard\IManager;
|
use OCP\Dashboard\IManager;
|
||||||
|
@ -80,7 +81,7 @@ class RegistrationContext {
|
||||||
/** @var ServiceRegistration<IAlternativeLogin>[] */
|
/** @var ServiceRegistration<IAlternativeLogin>[] */
|
||||||
private $alternativeLogins = [];
|
private $alternativeLogins = [];
|
||||||
|
|
||||||
/** @var array[] */
|
/** @var ServiceRegistration<InitialStateProvider>[] */
|
||||||
private $initialStates = [];
|
private $initialStates = [];
|
||||||
|
|
||||||
/** @var ServiceRegistration<IHandler>[] */
|
/** @var ServiceRegistration<IHandler>[] */
|
||||||
|
@ -261,10 +262,7 @@ class RegistrationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerInitialState(string $appId, string $class): void {
|
public function registerInitialState(string $appId, string $class): void {
|
||||||
$this->initialStates[] = [
|
$this->initialStates[] = new ServiceRegistration($appId, $class);
|
||||||
'appId' => $appId,
|
|
||||||
'class' => $class,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerWellKnown(string $appId, string $class): void {
|
public function registerWellKnown(string $appId, string $class): void {
|
||||||
|
@ -440,7 +438,7 @@ class RegistrationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return ServiceRegistration<InitialStateProvider>[]
|
||||||
*/
|
*/
|
||||||
public function getInitialStates(): array {
|
public function getInitialStates(): array {
|
||||||
return $this->initialStates;
|
return $this->initialStates;
|
||||||
|
|
|
@ -115,25 +115,25 @@ class InitialStateService implements IInitialStateService {
|
||||||
$initialStates = $context->getInitialStates();
|
$initialStates = $context->getInitialStates();
|
||||||
foreach ($initialStates as $initialState) {
|
foreach ($initialStates as $initialState) {
|
||||||
try {
|
try {
|
||||||
$provider = $this->container->query($initialState['class']);
|
$provider = $this->container->query($initialState->getService());
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
// Log an continue. We can be fault tolerant here.
|
// Log an continue. We can be fault tolerant here.
|
||||||
$this->logger->logException($e, [
|
$this->logger->logException($e, [
|
||||||
'message' => 'Could not load initial state provider dynamically: ' . $e->getMessage(),
|
'message' => 'Could not load initial state provider dynamically: ' . $e->getMessage(),
|
||||||
'level' => ILogger::ERROR,
|
'level' => ILogger::ERROR,
|
||||||
'app' => $initialState['appId'],
|
'app' => $initialState->getAppId(),
|
||||||
]);
|
]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!($provider instanceof InitialStateProvider)) {
|
if (!($provider instanceof InitialStateProvider)) {
|
||||||
// Log an continue. We can be fault tolerant here.
|
// Log an continue. We can be fault tolerant here.
|
||||||
$this->logger->error('Initial state provider is not an InitialStateProvider instance: ' . $initialState['class'], [
|
$this->logger->error('Initial state provider is not an InitialStateProvider instance: ' . $initialState->getService(), [
|
||||||
'app' => $initialState['appId'],
|
'app' => $initialState->getAppId(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->provideInitialState($initialState['appId'], $provider->getKey(), $provider);
|
$this->provideInitialState($initialState->getAppId(), $provider->getKey(), $provider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue