mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
add SourcePatcher::patchFile
This commit is contained in:
parent
56caef78e3
commit
630c0d3a5d
@ -117,6 +117,30 @@ class SourcePatcher
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use existing patch file for patching
|
||||
*
|
||||
* @param string $patch_name Patch file name in src/globals/patch/
|
||||
* @param string $cwd Working directory for patch command
|
||||
* @param bool $reverse Reverse patches (default: False)
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public static function patchFile(string $patch_name, string $cwd, bool $reverse = false): bool
|
||||
{
|
||||
if (!file_exists(ROOT_DIR . "/src/globals/patch/{$patch_name}")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}";
|
||||
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, $patch_file);
|
||||
|
||||
f_passthru(
|
||||
'cd ' . $cwd . ' && ' .
|
||||
(PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . $patch_str . ' | patch -p1 ' . ($reverse ? '-R' : '')
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user