mirror of
https://github.com/danog/process.git
synced 2024-12-02 09:37:55 +01:00
Rename escape function
Renamed constants.php to functions.php since it now contains a function.
This commit is contained in:
parent
6810aacc5d
commit
155960d7dd
@ -31,7 +31,7 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Amp\\Process\\": "lib"
|
"Amp\\Process\\": "lib"
|
||||||
},
|
},
|
||||||
"files": ["lib/constants.php"]
|
"files": ["lib/functions.php"]
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -46,7 +46,7 @@ final class Process
|
|||||||
public function __construct($command, string $cwd = null, array $env = [], array $options = [])
|
public function __construct($command, string $cwd = null, array $env = [], array $options = [])
|
||||||
{
|
{
|
||||||
$command = \is_array($command)
|
$command = \is_array($command)
|
||||||
? \implode(" ", \array_map(__NAMESPACE__ . "\\escape_arg", $command))
|
? \implode(" ", \array_map(__NAMESPACE__ . "\\escapeArguments", $command))
|
||||||
: (string) $command;
|
: (string) $command;
|
||||||
|
|
||||||
$cwd = $cwd ?? "";
|
$cwd = $cwd ?? "";
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Amp\Process;
|
|
||||||
|
|
||||||
const BIN_DIR = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bin';
|
|
||||||
const IS_WINDOWS = (PHP_OS & "\xDF\xDF\xDF") === 'WIN';
|
|
||||||
|
|
||||||
if (IS_WINDOWS) {
|
|
||||||
function escape_arg($arg)
|
|
||||||
{
|
|
||||||
return '"' . \preg_replace_callback('(\\\\*("|$))', function ($m) {
|
|
||||||
return \str_repeat('\\', \strlen($m[0])) . $m[0];
|
|
||||||
}, $arg) . '"';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
function escape_arg($arg)
|
|
||||||
{
|
|
||||||
return \escapeshellarg($arg);
|
|
||||||
}
|
|
||||||
}
|
|
34
lib/functions.php
Normal file
34
lib/functions.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Amp\Process;
|
||||||
|
|
||||||
|
const BIN_DIR = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bin';
|
||||||
|
const IS_WINDOWS = (PHP_OS & "\xDF\xDF\xDF") === 'WIN';
|
||||||
|
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
/**
|
||||||
|
* Escapes the command argument for safe inclusion into a Windows command string.
|
||||||
|
*
|
||||||
|
* @param string $arg
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function escapeArguments(string $arg): string
|
||||||
|
{
|
||||||
|
return '"' . \preg_replace_callback('(\\\\*("|$))', function (array $m): string {
|
||||||
|
return \str_repeat('\\', \strlen($m[0])) . $m[0];
|
||||||
|
}, $arg) . '"';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/**
|
||||||
|
* Escapes the command argument for safe inclusion into a Posix shell command string.
|
||||||
|
*
|
||||||
|
* @param string $arg
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function escapeArguments(string $arg): string
|
||||||
|
{
|
||||||
|
return \escapeshellarg($arg);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user