Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable21] Harden bootstrap context registrations when apps are missing #27681

Merged
merged 1 commit into from
Aug 31, 2021
Merged
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
62 changes: 51 additions & 11 deletions lib/private/AppFramework/Bootstrap/RegistrationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,20 @@ public function registerTemplateProvider(string $appId, string $class): void {
*/
public function delegateCapabilityRegistrations(array $apps): void {
while (($registration = array_shift($this->capabilities)) !== null) {
$appId = $registration['appId'];
if (!isset($apps[$appId])) {
// If we land here something really isn't right. But at least we caught the
// notice that is otherwise emitted for the undefined index
$this->logger->error("App $appId not loaded for the capability registration");

continue;
}

try {
$apps[$registration['appId']]
$apps[$appId]
->getContainer()
->registerCapability($registration['capability']);
} catch (Throwable $e) {
$appId = $registration['appId'];
$this->logger->logException($e, [
'message' => "Error during capability registration of $appId: " . $e->getMessage(),
'level' => ILogger::ERROR,
Expand Down Expand Up @@ -380,19 +388,27 @@ public function delegateEventListenerRegistrations(IEventDispatcher $eventDispat
*/
public function delegateContainerRegistrations(array $apps): void {
while (($registration = array_shift($this->services)) !== null) {
$appId = $registration['appId'];
if (!isset($apps[$appId])) {
// If we land here something really isn't right. But at least we caught the
// notice that is otherwise emitted for the undefined index
$this->logger->error("App $appId not loaded for the container service registration");

continue;
}

try {
/**
* Register the service and convert the callable into a \Closure if necessary
*/
$apps[$registration['appId']]
$apps[$appId]
->getContainer()
->registerService(
$registration['name'],
Closure::fromCallable($registration['factory']),
$registration['shared'] ?? true
);
} catch (Throwable $e) {
$appId = $registration['appId'];
$this->logger->logException($e, [
'message' => "Error during service registration of $appId: " . $e->getMessage(),
'level' => ILogger::ERROR,
Expand All @@ -401,15 +417,23 @@ public function delegateContainerRegistrations(array $apps): void {
}

while (($registration = array_shift($this->aliases)) !== null) {
$appId = $registration['appId'];
if (!isset($apps[$appId])) {
// If we land here something really isn't right. But at least we caught the
// notice that is otherwise emitted for the undefined index
$this->logger->error("App $appId not loaded for the container alias registration");

continue;
}

try {
$apps[$registration['appId']]
$apps[$appId]
->getContainer()
->registerAlias(
$registration['alias'],
$registration['target']
);
} catch (Throwable $e) {
$appId = $registration['appId'];
$this->logger->logException($e, [
'message' => "Error during service alias registration of $appId: " . $e->getMessage(),
'level' => ILogger::ERROR,
Expand All @@ -418,17 +442,25 @@ public function delegateContainerRegistrations(array $apps): void {
}

while (($registration = array_shift($this->parameters)) !== null) {
$appId = $registration['appId'];
if (!isset($apps[$appId])) {
// If we land here something really isn't right. But at least we caught the
// notice that is otherwise emitted for the undefined index
$this->logger->error("App $appId not loaded for the container parameter registration");

continue;
}

try {
$apps[$registration['appId']]
$apps[$appId]
->getContainer()
->registerParameter(
$registration['name'],
$registration['value']
);
} catch (Throwable $e) {
$appId = $registration['appId'];
$this->logger->logException($e, [
'message' => "Error during service alias registration of $appId: " . $e->getMessage(),
'message' => "Error during service parameter registration of $appId: " . $e->getMessage(),
'level' => ILogger::ERROR,
]);
}
Expand All @@ -440,12 +472,20 @@ public function delegateContainerRegistrations(array $apps): void {
*/
public function delegateMiddlewareRegistrations(array $apps): void {
while (($middleware = array_shift($this->middlewares)) !== null) {
$appId = $middleware['appId'];
if (!isset($apps[$appId])) {
// If we land here something really isn't right. But at least we caught the
// notice that is otherwise emitted for the undefined index
$this->logger->error("App $appId not loaded for the container middleware registration");

continue;
}

try {
$apps[$middleware['appId']]
$apps[$appId]
->getContainer()
->registerMiddleWare($middleware['class']);
} catch (Throwable $e) {
$appId = $middleware['appId'];
$this->logger->logException($e, [
'message' => "Error during capability registration of $appId: " . $e->getMessage(),
'level' => ILogger::ERROR,
Expand Down