Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Process.php

class Process

Same name in this branch
  1. 11.1.x vendor/open-telemetry/sdk/Resource/Detectors/Process.php \OpenTelemetry\SDK\Resource\Detectors\Process
  2. 11.1.x vendor/php-tuf/composer-stager/src/Internal/Process/Service/Process.php \PhpTuf\ComposerStager\Internal\Process\Service\Process
  3. 11.1.x vendor/symfony/process/Process.php \Symfony\Component\Process\Process

Process utility functions

@author John Stevenson <john-stevenson@blueyonder.co.uk>

Hierarchy

  • class \Composer\XdebugHandler\Process

Expanded class hierarchy of Process

20 string references to 'Process'
ConfigSingleImportForm::submitForm in core/modules/config/src/Form/ConfigSingleImportForm.php
Form submission handler.
ConfigSync::submitForm in core/modules/config/src/Form/ConfigSync.php
Form submission handler.
d6_block.yml in core/modules/block/migrations/d6_block.yml
core/modules/block/migrations/d6_block.yml
d6_comment.yml in core/modules/comment/migrations/d6_comment.yml
core/modules/comment/migrations/d6_comment.yml
d6_taxonomy_term.yml in core/modules/taxonomy/migrations/d6_taxonomy_term.yml
core/modules/taxonomy/migrations/d6_taxonomy_term.yml

... See full list

File

vendor/composer/xdebug-handler/src/Process.php, line 23

Namespace

Composer\XdebugHandler
View source
class Process {
    
    /**
     * Escapes a string to be used as a shell argument.
     *
     * From https://github.com/johnstevenson/winbox-args
     * MIT Licensed (c) John Stevenson <john-stevenson@blueyonder.co.uk>
     *
     * @param string $arg  The argument to be escaped
     * @param bool $meta Additionally escape cmd.exe meta characters
     * @param bool $module The argument is the module to invoke
     */
    public static function escape(string $arg, bool $meta = true, bool $module = false) : string {
        if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
            return "'" . str_replace("'", "'\\''", $arg) . "'";
        }
        $quote = strpbrk($arg, " \t") !== false || $arg === '';
        $arg = Preg::replace('/(\\\\*)"/', '$1$1\\"', $arg, -1, $dquotes);
        $dquotes = (bool) $dquotes;
        if ($meta) {
            $meta = $dquotes || Preg::isMatch('/%[^%]+%/', $arg);
            if (!$meta) {
                $quote = $quote || strpbrk($arg, '^&|<>()') !== false;
            }
            elseif ($module && !$dquotes && $quote) {
                $meta = false;
            }
        }
        if ($quote) {
            $arg = '"' . Preg::replace('/(\\\\*)$/', '$1$1', $arg) . '"';
        }
        if ($meta) {
            $arg = Preg::replace('/(["^&|<>()%])/', '^$1', $arg);
        }
        return $arg;
    }
    
    /**
     * Escapes an array of arguments that make up a shell command
     *
     * @param string[] $args Argument list, with the module name first
     */
    public static function escapeShellCommand(array $args) : string {
        $command = '';
        $module = array_shift($args);
        if ($module !== null) {
            $command = self::escape($module, true, true);
            foreach ($args as $arg) {
                $command .= ' ' . self::escape($arg);
            }
        }
        return $command;
    }
    
    /**
     * Makes putenv environment changes available in $_SERVER and $_ENV
     *
     * @param string $name
     * @param ?string $value A null value unsets the variable
     */
    public static function setEnv(string $name, ?string $value = null) : bool {
        $unset = null === $value;
        if (!putenv($unset ? $name : $name . '=' . $value)) {
            return false;
        }
        if ($unset) {
            unset($_SERVER[$name]);
        }
        else {
            $_SERVER[$name] = $value;
        }
        // Update $_ENV if it is being used
        if (false !== stripos((string) ini_get('variables_order'), 'E')) {
            if ($unset) {
                unset($_ENV[$name]);
            }
            else {
                $_ENV[$name] = $value;
            }
        }
        return true;
    }

}

Members

Title Sort descending Modifiers Object type Summary
Process::escape public static function Escapes a string to be used as a shell argument.
Process::escapeShellCommand public static function Escapes an array of arguments that make up a shell command
Process::setEnv public static function Makes putenv environment changes available in $_SERVER and $_ENV
RSS feed
Powered by Drupal