Skip to content

Commit

Permalink
Prevent function redeclare while using preload (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
grachevko authored Oct 8, 2021
1 parent 860877c commit 3d36327
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@
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);
if (!\function_exists(__NAMESPACE__ . '\\escapeArguments')) {
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);
}
}
}

0 comments on commit 3d36327

Please sign in to comment.