Escape a shell argument.

@param  mixed <string|array> $argument
@return string
181377
protected function escapeArgument($argument) : string
    {
        if (is_array($argument)) {
            $argument = array_map('escapeshellarg', $argument);
            $escaped  = implode(' ', $argument);
        } else {
            $escaped = escapeshellarg($argument);
        }
        return $escaped;
    }
936467
public static function constructStringFromArguments(array $arguments): string
    {
        $result = '';
        foreach ($arguments as $argument) {
            $result .= ' ' . $argument;
        }

        return $result;
    }
673224
private function formatArrayArgument(Argument $argument) : string
    {
        $arrayArgumentTextOne = $argument->getName() . '1';
        $arrayArgumentTextN = $argument->getName() . 'N';

        if ($argument->isOptional()) {
            $arrayArgumentTextOne = "[$arrayArgumentTextOne]";
            $arrayArgumentTextN = "[$arrayArgumentTextN]";
        }

        return "$arrayArgumentTextOne...$arrayArgumentTextN";
    }
1119774
protected static function parseArguments(array $arguments) {
    $string = '';
    foreach ($arguments as $name => $value) {
      if (is_null($value)) {
        $string .= ' --' . $name;
      }
      else {
        $string .= ' --' . $name . '=' . $value;
      }
    }
    return $string;
  }
1106688
protected function escapeRow(array $row)
    {
        $arrayDot = array_filter(array_dot($row));
        foreach ($arrayDot as $key => $value) {
            if (! in_array($key, $this->rawColumns)) {
                $arrayDot[$key] = e($value);
            }
        }

        foreach ($arrayDot as $key => $value) {
            array_set($row, $key, $value);
        }

        return $row;
    }
328953
private function resolveArgument($argument)
    {
        if (is_array($argument)) {
            return array_map(array($this, 'resolveArgument'), $argument);
        }

        if (!is_string($argument)) {
            return $argument;
        }

        $container = $this->kernel->getContainer();
        $container = $container->has('test.service_container') ? $container->get('test.service_container') : $container;

        if ($service = $this->getService($container, $argument)) {
            return $service;
        }

        $resolvedParam = $this->replaceParameters($container, $argument);

        if (!is_string($resolvedParam)) {
            return $resolvedParam;
        }

        return $this->escape($resolvedParam);
    }
749491
public static function escapeFunction($parameter)
    {
        $result = $parameter;

        switch (true) {
            case is_string($result) :
                $result = "'" . addslashes($result) . "'";
                break;

            case is_array($result) :
                foreach ($result as &$value) {
                    $value = static::escapeFunction($value);
                }

                $result = implode(', ', $result);
                break;

            case is_object($result) :
                $result = addslashes((string) $result);
                break;
        }

        return $result;
    }
49947
private function createArgumentDescriptorForMagicMethod($argument)
    {
        $argumentType = null;
        $argumentName = null;
        $argumentDefault = false; // false means we have not encountered the '=' yet.
        foreach ($argument as $part) {
            $part = trim($part);
            if (!$part) {
                continue;
            }

            // Type should not be assigned after name
            if (!$argumentName && !$argumentType && $part{0} != '$') {
                $argumentType = $part;
            } elseif (!$argumentName && $part{0} == '$') {
                $argumentName = $part;
            } elseif ($part == '=') {
                $argumentDefault = null;
            } elseif ($argumentDefault === null) {
                $argumentDefault = $part;
            }
        }
        if ($argumentDefault === false) {
            $argumentDefault = null;
        }

        // if no name is set but a type is then the input is malformed and we correct for it
        if ($argumentType && !$argumentName) {
            $argumentName = $argumentType;
            $argumentType = null;
        }

        // if there is no type then we assume it is 'mixed'
        if (!$argumentType) {
            $argumentType = 'mixed';
        }

        $argumentDescriptor = new ArgumentDescriptor();
        $argumentDescriptor->setTypes($this->builder->buildDescriptor(new Collection(array($argumentType))));
        $argumentDescriptor->setName($argumentName[0] == '$' ? $argumentName : '$' . $argumentName);
        $argumentDescriptor->setDefault($argumentDefault);

        return $argumentDescriptor;
    }
1364570
public function argument(Argument $argument)
    {
        $summary     = $this->prefixedArguments($argument);
        $printedName = mb_strstr($summary, ' ' . $argument->name());

        // Print the argument name if it's not printed yet.
        if (!$printedName && !$argument->noValue()) {
            $summary .= $argument->name();
        }

        if ($defaults = $argument->defaultValue()) {
            if (count($defaults) == 1) {
                $summary .= " (default: {$defaults[0]})";
            } else {
                $summary .= ' (defaults: ' . implode(', ', $defaults) . ')';
            }
        }

        return $summary;
    }
1357544
protected function prefixedArguments(Argument $argument)
    {
        $prefixes = [$argument->prefix(), $argument->longPrefix()];
        $summary  = [];

        foreach ($prefixes as $key => $prefix) {
            if (!$prefix) {
                continue;
            }

            $sub = str_repeat('-', $key + 1) . $prefix;

            if (!$argument->noValue()) {
                $sub .= " {$argument->name()}";
            }

            $summary[] = $sub;
        }

        return implode(', ', $summary);
    }
1003954
protected function escape($string)
    {
        if (preg_match('/["\s,]/', $string) === false) {
            return addslashes($string);
        } else {
            return sprintf('"%s"', addcslashes($string, '"\\'));
        }
    }
1163882
private static function run(array $arguments)
	{
		// Unwind the args, figure out which ones were passed in as an array
		self::$stdin = null;
		$closureOut = false;
		foreach ($arguments as $k => $argument) {
			// If it's being passed in as an object, then pipe into stdin
			if (\is_object($argument)) {
				// If it's a anonymous function, then push stdout into it
				if ($argument instanceof \Closure) {
					$closureOut = $argument;
				} else {
					self::$stdin = (string) $argument;
				}
				unset($arguments[$k]);
			} elseif (\is_array($argument)) {
				if (Arrays::isAssoc($argument)) {
					// Ok, so we're passing in arguments
					$output = '';
					foreach ($argument as $key => $val) {
						if ($output !== '') {
							$output .= ' ';
						}
						// If you pass 'false', it'll ignore the arg altogether
						if ($val !== false) {
							// Figure out if it's a long or short commandline arg
							if (\strlen($key) === 1) {
								$output .= '-';
							} else {
								$output .= '--';
							}
							$output .= $key;
							// If you just pass in 'true', it'll just add the arg
							if ($val !== true) {
								$output .= ' ' . \escapeshellarg($val);
							}
						}
					}
					$arguments[$k] = $output;
				} else {
					// We're passing in an array, but it's not --key=val style
					$arguments[$k] = \implode(' ', $argument);
				}
			}
		}
		$shell = \implode(' ', $arguments);

		// Prepend the path
		if (\stripos(PHP_OS, 'win') !== 0) {
			$parts = \explode(' ', $shell);
			$parts[0] = \exec('which ' . $parts[0]);
			if ($parts[0] !== '') {
				$shell = \implode(' ', $parts);
			}
		}

		$descriptor_spec = [
			0 => ['pipe', 'r'], // Stdin
			1 => ['pipe', 'w'], // Stdout
			2 => ['pipe', 'w'] // Stderr
		];
		$process = \proc_open($shell, $descriptor_spec, $pipes);
		if (\is_resource($process)) {
			\fwrite($pipes[0], self::$stdin);
			\fclose($pipes[0]);
			$output = '';
			while (!\feof($pipes[1])) {
				$stdout = \fgets($pipes[1], 1024);
				if ($stdout === '') {
					break;
				}

				echo $stdout;

				if ($closureOut instanceof \Closure) {
					$closureOut($stdout);
				}
				$output .= $stdout;
			}
			$error_output = \trim(\stream_get_contents($pipes[2]));
			if (self::$displayStderr) {
				echo $error_output;
			}
			self::$output = $output;
			\fclose($pipes[1]);
			\fclose($pipes[2]);
			$return_value = \proc_close($process);
			if ($return_value !== 0) {
				throw new ShellException($error_output, $return_value);
			}
		} else {
			throw new ShellException('Process failed to spawn');
		}
	}
713830
public function escape($input)
    {
        $input = strtolower($input);
        $input = preg_replace('/[^a-z0-9_. -]+/', '', $input);
        $input = trim($input);
        $input = str_replace(' ', '_', $input);
        $input = preg_replace('/_{2,}/', '_', $input);

        return $input;
    }
245337
private function buildCommand($command, $argument)
    {
        $command = sprintf($command, $argument);
        $this->output->writeln(
            'Calling following command:' . "\n" . $command,
            OutputInterface::VERBOSITY_DEBUG
        );

        return $command;
    }
568121
def _escape_arg(self, arg):
        '''
        
        '''
        if self.winrm:
            return arg
        return ''.join(['\\' + char if re.match(r'\W', char) else char for char in arg])
896717
public function removeArgument(IStackableArgument $argument)
    {
        if ($argument instanceof ISubKeyedStackableArgument) {
            $key = $argument->getSubKey();
        } else {
            $key = $this->stackKey();
        }

        unset($this->args[$key][$argument->getSubKey()]);
        if (empty($this->args[$key])) {
            unset($this->args[$key]);
        }

        return $this;
    }
1205521
private function escapeArgs(&$args) {
    $escaped = array();
    foreach ($args as $arg) {
      $escaped[] = escapeshellarg($arg);
    }
    return $escaped;
  }