Skip to content

Commit

Permalink
Prevent drush from crushing, when command extends non-existent class -
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyano committed Feb 8, 2024
1 parent 1f9e78a commit bae9873
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/Runtime/LegacyServiceInstantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public function instantiateServices(array $services)
$info['arguments'] ?? [],
$info['calls'] ?? []
);
if (empty($service)) {
continue;
}

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

Expand Down Expand Up @@ -166,12 +169,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 +195,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 @@ -309,7 +309,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

0 comments on commit bae9873

Please sign in to comment.