1<?php
2/**
3 * "Context" diff renderer.
4 *
5 * This class renders the diff in classic "context diff" format.
6 *
7 * Copyright 2004-2017 Horde LLC (http://www.horde.org/)
8 *
9 * See the enclosed file COPYING for license information (LGPL). If you did
10 * not receive this file, see http://www.horde.org/licenses/lgpl21.
11 *
12 * @package Text_Diff
13 */
14class Horde_Text_Diff_Renderer_Context extends Horde_Text_Diff_Renderer
15{
16    /**
17     * Number of leading context "lines" to preserve.
18     */
19    protected $_leading_context_lines = 4;
20
21    /**
22     * Number of trailing context "lines" to preserve.
23     */
24    protected $_trailing_context_lines = 4;
25
26    protected $_second_block = '';
27
28    protected function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
29    {
30        if ($xlen != 1) {
31            $xbeg .= ',' . $xlen;
32        }
33        if ($ylen != 1) {
34            $ybeg .= ',' . $ylen;
35        }
36        $this->_second_block = "--- $ybeg ----\n";
37        return "***************\n*** $xbeg ****";
38    }
39
40    protected function _endBlock()
41    {
42        return $this->_second_block;
43    }
44
45    protected function _context($lines)
46    {
47        $this->_second_block .= $this->_lines($lines, '  ');
48        return $this->_lines($lines, '  ');
49    }
50
51    protected function _added($lines)
52    {
53        $this->_second_block .= $this->_lines($lines, '+ ');
54        return '';
55    }
56
57    protected function _deleted($lines)
58    {
59        return $this->_lines($lines, '- ');
60    }
61
62    protected function _changed($orig, $final)
63    {
64        $this->_second_block .= $this->_lines($final, '! ');
65        return $this->_lines($orig, '! ');
66    }
67
68}
69