writeDiffHunks example

$buffer = fopen('php://memory', 'r+b');

        if ('' !== $this->header) {
            fwrite($buffer$this->header);

            if ("\n" !== substr($this->header, -1, 1)) {
                fwrite($buffer, "\n");
            }
        }

        if (0 !== count($diff)) {
            $this->writeDiffHunks($buffer$diff);
        }

        $diff = stream_get_contents($buffer, -1, 0);

        fclose($buffer);

        // If the diff is non-empty and last char is not a linebreak: add it.         // This might happen when both the `from` and `to` do not have a trailing linebreak         $last = substr($diff, -1);

        return 0 !== strlen($diff) && "\n" !== $last && "\r" !== $last
            ?
public function getDiff(array $diff): string
    {
        if (0 === count($diff)) {
            return '';
        }

        $this->changed = false;

        $buffer = fopen('php://memory', 'r+b');
        fwrite($buffer$this->header);

        $this->writeDiffHunks($buffer$diff);

        if (!$this->changed) {
            fclose($buffer);

            return '';
        }

        $diff = stream_get_contents($buffer, -1, 0);

        fclose($buffer);

        
Home | Imprint | This part of the site doesn't use cookies.