Skip to content

Rename PHP executable finder #93

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

Merged
merged 1 commit into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
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
22 changes: 7 additions & 15 deletions src/Parallelization.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@

use function getcwd;
use function realpath;
use RuntimeException;
use function sprintf;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Terminal;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
use Webmozart\Assert\Assert;
use Webmozarts\Console\Parallelization\ErrorHandler\ItemProcessingErrorHandler;
use Webmozarts\Console\Parallelization\ErrorHandler\ItemProcessingErrorHandlerLogger;
use Webmozarts\Console\Parallelization\ErrorHandler\ResetContainerErrorHandler;
use Webmozarts\Console\Parallelization\Logger\DebugProgressBarFactory;
use Webmozarts\Console\Parallelization\Logger\Logger;
use Webmozarts\Console\Parallelization\Logger\StandardLogger;
use Webmozarts\Console\Parallelization\Process\PhpExecutableFinder;

/**
* Adds parallelization capabilities to console commands.
Expand Down Expand Up @@ -229,9 +227,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
fn (string $item, InputInterface $input, OutputInterface $output) => $this->runSingleCommand($item, $input, $output),
fn (int $count) => $this->getItemName($count),
$this->getConsolePath(),
self::detectPhpExecutable(),
$this->getPhpExecutable(),
$this->getName(),
self::getWorkingDirectory(),
$this->getWorkingDirectory(),
$this->getExtraEnvironmentVariables(),
$this->getDefinition(),
$this->createItemErrorHandler(),
Expand Down Expand Up @@ -325,23 +323,17 @@ private static function getProgressSymbol(): string
}

/**
* Detects the path of the PHP interpreter.
* Returns the path of the PHP executable.
*/
private static function detectPhpExecutable(): string
private function getPhpExecutable(): string
{
$php = (new PhpExecutableFinder())->find();

if (false === $php) {
throw new RuntimeException('Cannot find php executable');
}

return $php;
return PhpExecutableFinder::find();
}

/**
* Returns the working directory for the child process.
*/
private static function getWorkingDirectory(): string
private function getWorkingDirectory(): string
{
return getcwd();
}
Expand Down
47 changes: 47 additions & 0 deletions src/Process/PhpExecutableFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Webmozarts Console Parallelization package.
*
* (c) Webmozarts GmbH <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Webmozarts\Console\Parallelization\Process;

use Symfony\Component\Process\PhpExecutableFinder as SymfonyPhpExecutableFinder;
use Webmozart\Assert\Assert;

final class PhpExecutableFinder
{
private static SymfonyPhpExecutableFinder $finder;

private function __construct()
{
}

public static function find(): string
{
$phpExecutable = self::getFinder()->find();

Assert::notFalse(
$phpExecutable,
'Could not find the PHP executable.',
);

return $phpExecutable;
}

private static function getFinder(): SymfonyPhpExecutableFinder
{
if (!isset(self::$finder)) {
self::$finder = new SymfonyPhpExecutableFinder();
}

return self::$finder;
}
}