1
0
mirror of https://github.com/danog/process.git synced 2024-11-30 04:39:04 +01:00

Rename escape function

Renamed constants.php to functions.php since it now contains a function.
This commit is contained in:
Aaron Piotrowski 2019-02-25 22:50:25 -06:00
parent 6810aacc5d
commit 155960d7dd
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
4 changed files with 36 additions and 22 deletions

View File

@ -31,7 +31,7 @@
"psr-4": {
"Amp\\Process\\": "lib"
},
"files": ["lib/constants.php"]
"files": ["lib/functions.php"]
},
"autoload-dev": {
"psr-4": {

View File

@ -46,7 +46,7 @@ final class Process
public function __construct($command, string $cwd = null, array $env = [], array $options = [])
{
$command = \is_array($command)
? \implode(" ", \array_map(__NAMESPACE__ . "\\escape_arg", $command))
? \implode(" ", \array_map(__NAMESPACE__ . "\\escapeArguments", $command))
: (string) $command;
$cwd = $cwd ?? "";

View File

@ -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
View 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);
}
}