Skip to content

Commit

Permalink
use Console/Application::formatCommandString()
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigopedra committed Sep 16, 2024
1 parent a4bfafb commit df2beb5
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions src/Illuminate/Concurrency/ProcessDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
namespace Illuminate\Concurrency;

use Closure;
use Illuminate\Console\Application;
use Illuminate\Contracts\Concurrency\Driver;
use Illuminate\Foundation\Defer\DeferredCallback;
use Illuminate\Process\Factory as ProcessFactory;
use Illuminate\Process\Pool;
use Illuminate\Support\Arr;
use Illuminate\Support\ProcessUtils;
use Laravel\SerializableClosure\SerializableClosure;
use Symfony\Component\Process\PhpExecutableFinder;

class ProcessDriver implements Driver
{
Expand All @@ -27,7 +26,7 @@ public function __construct(protected ProcessFactory $processFactory)
*/
public function run(Closure|array $tasks): array
{
$command = $this->buildCommand();
$command = Application::formatCommandString('invoke-serialized-closure');

$results = $this->processFactory->pool(function (Pool $pool) use ($tasks, $command) {
foreach (Arr::wrap($tasks) as $task) {
Expand Down Expand Up @@ -55,7 +54,7 @@ public function run(Closure|array $tasks): array
*/
public function defer(Closure|array $tasks): DeferredCallback
{
$command = $this->buildCommand();
$command = Application::formatCommandString('invoke-serialized-closure');

return defer(function () use ($tasks, $command) {
foreach (Arr::wrap($tasks) as $task) {
Expand All @@ -65,30 +64,4 @@ public function defer(Closure|array $tasks): DeferredCallback
}
});
}

/**
* Get the PHP binary.
*/
protected function phpBinary(): string
{
return ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false) ?: 'php');
}

/**
* Get the Artisan binary.
*/
protected function artisanBinary(): string
{
return ProcessUtils::escapeArgument(defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan');
}

/**
* Build the command string.
*
* @return string
*/
protected function buildCommand(): string
{
return sprintf('%s %s invoke-serialized-closure', $this->phpBinary(), $this->artisanBinary());
}
}

0 comments on commit df2beb5

Please sign in to comment.