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

Prevent drush from crushing, when command extends non-existent class #5861

Open
wants to merge 1 commit into
base: 12.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/Runtime/LegacyServiceInstantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public function instantiateServices(array $services)
$info['arguments'] ?? [],
$info['calls'] ?? []
);
if (empty($service)) {
$this->logger->debug("Could not instantiate {class} for '{service_name}' service", ['class' => $info['class'], 'service_name' => $serviceName]);
continue;
}

$this->instantiatedDrushServices[$serviceName] = $service;

Expand Down Expand Up @@ -166,12 +170,15 @@ public function taggedServices($tagName)
* @param string[] $arguments Parameters to class constructor
* @param array Method names and arguments to call after object is instantiated
*
* @return object
* Instantiated command handler from the service file
* @return object|null
* Instantiated command handler from the service file or empty result
*/
public function create($class, array $arguments, array $calls)
{
$instance = $this->instantiateObject($class, $arguments);
if (empty($instance)) {
return;
}
foreach ($calls as $callInfo) {
$this->call($instance, $callInfo[0], $callInfo[1]);
}
Expand All @@ -189,7 +196,11 @@ public function create($class, array $arguments, array $calls)
*/
public function instantiateObject($class, array $arguments)
{
$refl = new \ReflectionClass($class);
try {
$refl = new \ReflectionClass($class);
} catch (\Throwable $e) {
return;
}
return $refl->newInstanceArgs($this->resolveArguments($arguments));
}

Expand Down
6 changes: 5 additions & 1 deletion src/Runtime/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ public function instantiateServices(array $bootstrapCommandClasses, DrushContain
// n.b. we cannot simply use 'isInstantiable' here because
// the constructor is typically protected when using a static create method
$bootstrapCommandClasses = array_filter($bootstrapCommandClasses, function ($class) {
$reflection = new \ReflectionClass($class);
try {
$reflection = new \ReflectionClass($class);
} catch (\Throwable $e) {
return false;
}
return !$reflection->isAbstract();
});

Expand Down