Skip to content

Commit

Permalink
Backport requiresBootstrap change (#5905)
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman authored Mar 12, 2024
1 parent 041af88 commit 0639d21
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Runtime/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,27 +370,32 @@ protected function hasStaticCreateFactory(string $class): bool
}

/*
* Does the provided class have a Bootstrap Attribute, indicating early loading.
* Get any value for the #[Bootstrap] Attribute on the class.
*/
protected function hasBootStrapAttributeNone(string $class): bool
protected function bootStrapAttributeValue(string $class): ?int
{
try {
$reflection = new \ReflectionClass($class);
if ($attributes = $reflection->getAttributes(Bootstrap::class)) {
$bootstrap = $attributes[0]->newInstance();
return $bootstrap->level === DrupalBootLevels::NONE;
return $bootstrap->level;
}
} catch (\ReflectionException $e) {
}
return false;
return null;
}

/**
* Check whether a command class requires Drupal bootstrap.
*/
protected function requiresBootstrap(string $class): bool
{
return $this->hasStaticCreateFactory($class) && !$this->hasBootStrapAttributeNone($class);
if ($this->bootStrapAttributeValue($class) === DrupalBootLevels::FULL) {
return true;
} elseif ($this->bootStrapAttributeValue($class) === DrupalBootLevels::NONE) {
return false;
}
return $this->hasStaticCreateFactory($class);
}

/**
Expand Down

0 comments on commit 0639d21

Please sign in to comment.