Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../vendor/symfony/process
File: ProcessUtils.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of the Symfony package.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier <fabien@symfony.com>
[5] Fix | Delete
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
namespace Symfony\Component\Process;
[11] Fix | Delete
[12] Fix | Delete
use Symfony\Component\Process\Exception\InvalidArgumentException;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* ProcessUtils is a bunch of utility methods.
[16] Fix | Delete
*
[17] Fix | Delete
* This class contains static methods only and is not meant to be instantiated.
[18] Fix | Delete
*
[19] Fix | Delete
* @author Martin HasoĊˆ <martin.hason@gmail.com>
[20] Fix | Delete
*/
[21] Fix | Delete
class ProcessUtils
[22] Fix | Delete
{
[23] Fix | Delete
/**
[24] Fix | Delete
* This class should not be instantiated.
[25] Fix | Delete
*/
[26] Fix | Delete
private function __construct()
[27] Fix | Delete
{
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Escapes a string to be used as a shell argument.
[32] Fix | Delete
*
[33] Fix | Delete
* @param string $argument The argument that will be escaped
[34] Fix | Delete
*
[35] Fix | Delete
* @return string The escaped argument
[36] Fix | Delete
*
[37] Fix | Delete
* @deprecated since version 3.3, to be removed in 4.0. Use a command line array or give env vars to the `Process::start/run()` method instead.
[38] Fix | Delete
*/
[39] Fix | Delete
public static function escapeArgument($argument)
[40] Fix | Delete
{
[41] Fix | Delete
@trigger_error('The '.__METHOD__.'() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use a command line array or give env vars to the Process::start/run() method instead.', \E_USER_DEPRECATED);
[42] Fix | Delete
[43] Fix | Delete
//Fix for PHP bug #43784 escapeshellarg removes % from given string
[44] Fix | Delete
//Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
[45] Fix | Delete
//@see https://bugs.php.net/43784
[46] Fix | Delete
//@see https://bugs.php.net/49446
[47] Fix | Delete
if ('\\' === \DIRECTORY_SEPARATOR) {
[48] Fix | Delete
if ('' === $argument) {
[49] Fix | Delete
return escapeshellarg($argument);
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
$escapedArgument = '';
[53] Fix | Delete
$quote = false;
[54] Fix | Delete
foreach (preg_split('/(")/', $argument, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE) as $part) {
[55] Fix | Delete
if ('"' === $part) {
[56] Fix | Delete
$escapedArgument .= '\\"';
[57] Fix | Delete
} elseif (self::isSurroundedBy($part, '%')) {
[58] Fix | Delete
// Avoid environment variable expansion
[59] Fix | Delete
$escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
[60] Fix | Delete
} else {
[61] Fix | Delete
// escape trailing backslash
[62] Fix | Delete
if ('\\' === substr($part, -1)) {
[63] Fix | Delete
$part .= '\\';
[64] Fix | Delete
}
[65] Fix | Delete
$quote = true;
[66] Fix | Delete
$escapedArgument .= $part;
[67] Fix | Delete
}
[68] Fix | Delete
}
[69] Fix | Delete
if ($quote) {
[70] Fix | Delete
$escapedArgument = '"'.$escapedArgument.'"';
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
return $escapedArgument;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
return "'".str_replace("'", "'\\''", $argument)."'";
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Validates and normalizes a Process input.
[81] Fix | Delete
*
[82] Fix | Delete
* @param string $caller The name of method call that validates the input
[83] Fix | Delete
* @param mixed $input The input to validate
[84] Fix | Delete
*
[85] Fix | Delete
* @return mixed The validated input
[86] Fix | Delete
*
[87] Fix | Delete
* @throws InvalidArgumentException In case the input is not valid
[88] Fix | Delete
*/
[89] Fix | Delete
public static function validateInput($caller, $input)
[90] Fix | Delete
{
[91] Fix | Delete
if (null !== $input) {
[92] Fix | Delete
if (\is_resource($input)) {
[93] Fix | Delete
return $input;
[94] Fix | Delete
}
[95] Fix | Delete
if (\is_string($input)) {
[96] Fix | Delete
return $input;
[97] Fix | Delete
}
[98] Fix | Delete
if (is_scalar($input)) {
[99] Fix | Delete
return (string) $input;
[100] Fix | Delete
}
[101] Fix | Delete
if ($input instanceof Process) {
[102] Fix | Delete
return $input->getIterator($input::ITER_SKIP_ERR);
[103] Fix | Delete
}
[104] Fix | Delete
if ($input instanceof \Iterator) {
[105] Fix | Delete
return $input;
[106] Fix | Delete
}
[107] Fix | Delete
if ($input instanceof \Traversable) {
[108] Fix | Delete
return new \IteratorIterator($input);
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
throw new InvalidArgumentException(sprintf('"%s" only accepts strings, Traversable objects or stream resources.', $caller));
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
return $input;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
private static function isSurroundedBy($arg, $char)
[118] Fix | Delete
{
[119] Fix | Delete
return 2 < \strlen($arg) && $char === $arg[0] && $char === $arg[\strlen($arg) - 1];
[120] Fix | Delete
}
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function