PhpBrew\PatchUtils::applyFileStdin PHP Method

applyFileStdin() public static method

public static applyFileStdin ( $originalFile, $diff, &$output, $level )
    public static function applyFileStdin($originalFile, $diff, &$output, $level = 0)
    {
        $desc = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'));
        $process = proc_open("patch {$originalFile}", $desc, $pipes);
        if (!is_resource($process)) {
            throw new RuntimeException("Can't open process");
        }
        fwrite($pipes[0], $diff);
        fclose($pipes[0]);
        $output = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        return proc_close($process);
    }

Usage Example

Beispiel #1
0
    public function test()
    {
        $diff = <<<'PATCH'
--- tests/a.txt	2014-10-11 23:04:39.000000000 +0800
+++ tests/b.txt	2014-10-11 23:04:50.000000000 +0800
@@ -1 +1 @@
-aaa
+bbb

PATCH;
        file_put_contents('tests/a.txt', "aaa\n");
        $this->assertSame(0, PatchUtils::applyFileStdin('tests/a.txt', $diff, $output));
        unlink('tests/a.txt');
    }