Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/private/AppFramework/Bootstrap/RegistrationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class RegistrationContext {
/** @var array[] */
private $initialStates = [];

/** @var array[] */
private $userBackEnds = [];

/** @var ILogger */
private $logger;

Expand Down Expand Up @@ -174,6 +177,13 @@ public function registerInitialStateProvider(string $class): void {
$class
);
}

public function registerUserBackend(string $class): void {
$this->context->registerUserBackend(
$this->appId,
$class
);
}
};
}

Expand Down Expand Up @@ -260,6 +270,13 @@ public function registerInitialState(string $appId, string $class): void {
];
}

public function registerUserBackEnd(string $appId, string $class): void {
Copy link

@alexeyabel alexeyabel Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come classes are passed as strings and not as interfaces? Shouldn't interfaces be enforced by type checks?

I understand this is already the case in the whole class, but I am not familiar with this concept.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The registration code is run for every single request. User back-ends are built most likely for those requests but other things are just loaded conditionally on demand (lazily) so less resources are wasted. Php allows us to specify the class name to load and we use the dependency injection container to create an instance when needed.

See #20573 for most of the original ideas and design decisions.

$this->userBackEnds[] = [
'appId' => $appId,
'class' => $class,
];
}

/**
* @param App[] $apps
*/
Expand Down
12 changes: 12 additions & 0 deletions lib/public/AppFramework/Bootstrap/IRegistrationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,16 @@ public function registerAlternativeLogin(string $class): void;
* @since 21.0.0
*/
public function registerInitialStateProvider(string $class): void;

/**
* Register a user backend
*
* @param string $class the class name of an \OCP\IUserBackend implementation
* @psalm-param class-string<\OCP\IUserBackend> $class the class name of an \OCP\IUserBackend implementation
*
* @return void
*
* @since 21.0.0
*/
public function registerUserBackend(string $class): void;
}