Skip to content

Commit 5c5c179

Browse files
author
Chris Boulton
committed
Redo directory structure to match current coding style, rename classes to match directory style, fix up naming conventions
1 parent ac22200 commit 5c5c179

File tree

10 files changed

+99
-98
lines changed

10 files changed

+99
-98
lines changed

README

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
PHP DiffLib
1+
PHP Diff Class
2+
--------------
23

34
Introduction
45
------------
5-
PHP DiffLib is a comprehensive library for generating differences between
6-
two hasable objects (strings or arrays). Generated differences can be
6+
A comprehensive library for generating differences between
7+
two hashable objects (strings or arrays). Generated differences can be
78
rendered in all of the standard formats including:
89
* Unified
910
* Context
@@ -40,7 +41,7 @@ modification, are permitted provided that the following conditions are met:
4041
- Redistributions in binary form must reproduce the above copyright notice,
4142
this list of conditions and the following disclaimer in the documentation
4243
and/or other materials provided with the distribution.
43-
- Neither the name of the Chris Boulton, Inc. nor the names of its contributors
44+
- Neither the name of the Chris Boulton nor the names of its contributors
4445
may be used to endorse or promote products derived from this software
4546
without specific prior written permission.
4647

example/example.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<?php
1313

1414
// Include the diff class
15-
require_once dirname(__FILE__).'/../difflib.php';
15+
require_once dirname(__FILE__).'/../lib/Diff.php';
1616

1717
// Include two sample files for comparison
1818
$a = explode("\n", file_get_contents(dirname(__FILE__).'/a.txt'));
@@ -23,44 +23,44 @@
2323
);
2424

2525
// Initialize the diff class
26-
$diff = new DiffLib($a, $b, $options);
26+
$diff = new Diff($a, $b, $options);
2727

2828
?>
2929
<h2>Side by Side Diff</h2>
3030
<?php
3131

3232
// Generate a side by side diff
33-
require_once dirname(__FILE__).'/../renderer/sidebyside_html.php';
34-
$renderer = new DiffLib_Renderer_SideBySide_Html;
33+
require_once dirname(__FILE__).'/../lib/Diff/Renderer/Html/SideBySide.php';
34+
$renderer = new Diff_Renderer_Html_SideBySide;
3535
echo $diff->Render($renderer);
3636

3737
?>
3838
<h2>Inline Diff</h2>
3939
<?php
4040

4141
// Generate an inline diff
42-
require_once dirname(__FILE__).'/../renderer/inline_html.php';
43-
$renderer = new DiffLib_Renderer_Inline_Html;
44-
echo $diff->Render($renderer);
42+
require_once dirname(__FILE__).'/../lib/Diff/Renderer/Html/Inline.php';
43+
$renderer = new Diff_Renderer_Html_Inline;
44+
echo $diff->render($renderer);
4545

4646
?>
4747
<h2>Unified Diff</h2>
4848
<pre><?php
4949

5050
// Generate a unified diff
51-
require_once dirname(__FILE__).'/../renderer/unified.php';
52-
$renderer = new DiffLib_Renderer_Unified;
53-
echo htmlspecialchars($diff->Render($renderer));
51+
require_once dirname(__FILE__).'/../lib/Diff/Renderer/Text/Unified.php';
52+
$renderer = new Diff_Renderer_Text_Unified;
53+
echo htmlspecialchars($diff->render($renderer));
5454

5555
?>
5656
</pre>
5757
<h2>Context Diff</h2>
5858
<pre><?php
5959

6060
// Generate a context diff
61-
require_once dirname(__FILE__).'/../renderer/context.php';
62-
$renderer = new DiffLib_Renderer_Context;
63-
echo htmlspecialchars($diff->Render($renderer));
61+
require_once dirname(__FILE__).'/../lib/Diff/Renderer/Text/Context.php';
62+
$renderer = new Diff_Renderer_Text_Context;
63+
echo htmlspecialchars($diff->render($renderer));
6464
?>
6565
</pre>
6666
</body>

difflib.php lib/Diff.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* PHP LibDiff
3+
* Diff
44
*
55
* A comprehensive library for generating differences between two strings
66
* in multiple formats (unified, side by side HTML etc)
@@ -19,7 +19,7 @@
1919
* - Redistributions in binary form must reproduce the above copyright notice,
2020
* this list of conditions and the following disclaimer in the documentation
2121
* and/or other materials provided with the distribution.
22-
* - Neither the name of the Chris Boulton, Inc. nor the names of its contributors
22+
* - Neither the name of the Chris Boulton nor the names of its contributors
2323
* may be used to endorse or promote products derived from this software
2424
* without specific prior written permission.
2525
*
@@ -35,15 +35,15 @@
3535
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3636
* POSSIBILITY OF SUCH DAMAGE.
3737
*
38-
* @package DiffLib
38+
* @package Diff
3939
* @author Chris Boulton <[email protected]>
4040
* @copyright (c) 2009 Chris Boulton
4141
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
4242
* @version 1.0
43-
* @link http://github.com/chrisboulton/phpdifflib/
43+
* @link http://github.com/chrisboulton/phpdiff
4444
*/
4545

46-
class DiffLib
46+
class Diff
4747
{
4848
/**
4949
* @var array The "old" sequence to use as the basis for the comparison.
@@ -95,7 +95,7 @@ public function __construct($a, $b, $options=array())
9595
* @param object $renderer An instance of the rendering object to use for generating the diff.
9696
* @return mixed The generated diff. Exact return value depends on the rendered.
9797
*/
98-
public function Render(DiffLib_Renderer_Base $renderer)
98+
public function render(Diff_Renderer_Abstract $renderer)
9999
{
100100
$renderer->diff = $this;
101101
return $renderer->Render();
@@ -111,7 +111,7 @@ public function Render(DiffLib_Renderer_Base $renderer)
111111
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
112112
* @return array Array of all of the lines between the specified range.
113113
*/
114-
public function GetA($start=0, $end=null)
114+
public function getA($start=0, $end=null)
115115
{
116116
if($start == 0 && $end === null) {
117117
return $this->a;
@@ -138,7 +138,7 @@ public function GetA($start=0, $end=null)
138138
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
139139
* @return array Array of all of the lines between the specified range.
140140
*/
141-
public function GetB($start=0, $end=null)
141+
public function getB($start=0, $end=null)
142142
{
143143
if($start == 0 && $end === null) {
144144
return $this->b;
@@ -162,15 +162,15 @@ public function GetB($start=0, $end=null)
162162
*
163163
* @return array Array of the grouped opcodes for the generated diff.
164164
*/
165-
public function GetGroupedOpcodes()
165+
public function getGroupedOpcodes()
166166
{
167167
if(!is_null($this->groupedCodes)) {
168168
return $this->groupedCodes;
169169
}
170170

171-
require_once dirname(__FILE__).'/sequencematcher.php';
172-
$sequenceMatcher = new DiffLib_SequenceMatcher($this->a, $this->b);
173-
$this->groupedCodes = $sequenceMatcher->GetGroupedOpCodes();
171+
require_once dirname(__FILE__).'/Diff/SequenceMatcher.php';
172+
$sequenceMatcher = new Diff_SequenceMatcher($this->a, $this->b);
173+
$this->groupedCodes = $sequenceMatcher->getGroupedOpcodes();
174174
return $this->groupedCodes;
175175
}
176176
}

renderer/base.php lib/Diff/Renderer/Abstract.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* - Redistributions in binary form must reproduce the above copyright notice,
1717
* this list of conditions and the following disclaimer in the documentation
1818
* and/or other materials provided with the distribution.
19-
* - Neither the name of the Chris Boulton, Inc. nor the names of its contributors
19+
* - Neither the name of the Chris Boulton nor the names of its contributors
2020
* may be used to endorse or promote products derived from this software
2121
* without specific prior written permission.
2222
*
@@ -37,10 +37,10 @@
3737
* @copyright (c) 2009 Chris Boulton
3838
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
3939
* @version 1.0
40-
* @link http://github.com/chrisboulton/phpdifflib/
40+
* @link http://github.com/chrisboulton/phpdiff
4141
*/
4242

43-
abstract class DiffLib_Renderer_Base
43+
abstract class Diff_Renderer_Abstract
4444
{
4545
/**
4646
* @var object Instance of the diff class that this renderer is generating the rendered diff for.

renderer/array_html.php lib/Diff/Renderer/Html/Array.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* - Redistributions in binary form must reproduce the above copyright notice,
1717
* this list of conditions and the following disclaimer in the documentation
1818
* and/or other materials provided with the distribution.
19-
* - Neither the name of the Chris Boulton, Inc. nor the names of its contributors
19+
* - Neither the name of the Chris Boulton nor the names of its contributors
2020
* may be used to endorse or promote products derived from this software
2121
* without specific prior written permission.
2222
*
@@ -37,12 +37,12 @@
3737
* @copyright (c) 2009 Chris Boulton
3838
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
3939
* @version 1.0
40-
* @link http://github.com/chrisboulton/phpdifflib/
40+
* @link http://github.com/chrisboulton/phpdiff
4141
*/
4242

43-
require_once dirname(__FILE__).'/base.php';
43+
require_once dirname(__FILE__).'/../Abstract.php';
4444

45-
class DiffLib_Renderer_Array_Html extends DiffLib_Renderer_Base
45+
class Diff_Renderer_Html_Array extends Diff_Renderer_Abstract
4646
{
4747
/**
4848
* @var array Array of the default options that apply to this renderer.
@@ -67,7 +67,7 @@ public function Render()
6767
$b = $this->diff->GetB();
6868

6969
$changes = array();
70-
$opCodes = $this->diff->GetGroupedOpCodes();
70+
$opCodes = $this->diff->getGroupedOpcodes();
7171
foreach($opCodes as $group) {
7272
$blocks = array();
7373
$lastTag = null;

renderer/inline_html.php lib/Diff/Renderer/Html/Inline.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* - Redistributions in binary form must reproduce the above copyright notice,
1717
* this list of conditions and the following disclaimer in the documentation
1818
* and/or other materials provided with the distribution.
19-
* - Neither the name of the Chris Boulton, Inc. nor the names of its contributors
19+
* - Neither the name of the Chris Boulton nor the names of its contributors
2020
* may be used to endorse or promote products derived from this software
2121
* without specific prior written permission.
2222
*
@@ -37,12 +37,12 @@
3737
* @copyright (c) 2009 Chris Boulton
3838
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
3939
* @version 1.0
40-
* @link http://github.com/chrisboulton/phpdifflib/
40+
* @link http://github.com/chrisboulton/phpdiff
4141
*/
4242

43-
require_once dirname(__FILE__).'/array_html.php';
43+
require_once dirname(__FILE__).'/Array.php';
4444

45-
class DiffLib_Renderer_Inline_Html extends DiffLib_Renderer_Array_Html
45+
class Diff_Renderer_Html_Inline extends Diff_Renderer_Html_Array
4646
{
4747
/**
4848
* Render a and return diff with changes between the two sequences

renderer/sidebyside_html.php lib/Diff/Renderer/Html/SideBySide.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* - Redistributions in binary form must reproduce the above copyright notice,
1717
* this list of conditions and the following disclaimer in the documentation
1818
* and/or other materials provided with the distribution.
19-
* - Neither the name of the Chris Boulton, Inc. nor the names of its contributors
19+
* - Neither the name of the Chris Boulton nor the names of its contributors
2020
* may be used to endorse or promote products derived from this software
2121
* without specific prior written permission.
2222
*
@@ -37,12 +37,12 @@
3737
* @copyright (c) 2009 Chris Boulton
3838
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
3939
* @version 1.0
40-
* @link http://github.com/chrisboulton/phpdifflib/
40+
* @link http://github.com/chrisboulton/phpdiff
4141
*/
4242

43-
require_once dirname(__FILE__).'/array_html.php';
43+
require_once dirname(__FILE__).'/Array.php';
4444

45-
class DiffLib_Renderer_SideBySide_Html extends DiffLib_Renderer_Array_Html
45+
class Diff_Renderer_Html_SideBySide extends Diff_Renderer_Html_Array
4646
{
4747
/**
4848
* Render a and return diff with changes between the two sequences

renderer/context.php lib/Diff/Renderer/Text/Context.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* - Redistributions in binary form must reproduce the above copyright notice,
1717
* this list of conditions and the following disclaimer in the documentation
1818
* and/or other materials provided with the distribution.
19-
* - Neither the name of the Chris Boulton, Inc. nor the names of its contributors
19+
* - Neither the name of the Chris Boulton nor the names of its contributors
2020
* may be used to endorse or promote products derived from this software
2121
* without specific prior written permission.
2222
*
@@ -37,12 +37,12 @@
3737
* @copyright (c) 2009 Chris Boulton
3838
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
3939
* @version 1.0
40-
* @link http://github.com/chrisboulton/phpdifflib/
40+
* @link http://github.com/chrisboulton/phpdiff
4141
*/
4242

43-
require_once dirname(__FILE__).'/base.php';
43+
require_once dirname(__FILE__).'/../Abstract.php';
4444

45-
class DiffLib_Renderer_Context extends DiffLib_Renderer_Base
45+
class Diff_Renderer_Text_Context extends Diff_Renderer_Abstract
4646
{
4747
/**
4848
* @var array Array of the different opcode tags and how they map to the context diff equivalent.
@@ -62,7 +62,7 @@ class DiffLib_Renderer_Context extends DiffLib_Renderer_Base
6262
public function Render()
6363
{
6464
$diff = '';
65-
$opCodes = $this->diff->GetGroupedOpCodes();
65+
$opCodes = $this->diff->getGroupedOpcodes();
6666
foreach($opCodes as $group) {
6767
$diff .= "***************\n";
6868
$lastItem = count($group)-1;

renderer/unified.php lib/Diff/Renderer/Text/Unified.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* - Redistributions in binary form must reproduce the above copyright notice,
1717
* this list of conditions and the following disclaimer in the documentation
1818
* and/or other materials provided with the distribution.
19-
* - Neither the name of the Chris Boulton, Inc. nor the names of its contributors
19+
* - Neither the name of the Chris Boulton nor the names of its contributors
2020
* may be used to endorse or promote products derived from this software
2121
* without specific prior written permission.
2222
*
@@ -37,12 +37,12 @@
3737
* @copyright (c) 2009 Chris Boulton
3838
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
3939
* @version 1.0
40-
* @link http://github.com/chrisboulton/phpdifflib/
40+
* @link http://github.com/chrisboulton/phpdiff
4141
*/
4242

43-
require_once dirname(__FILE__).'/base.php';
43+
require_once dirname(__FILE__).'/../Abstract.php';
4444

45-
class DiffLib_Renderer_Unified extends DiffLib_Renderer_Base
45+
class Diff_Renderer_Text_Unified extends Diff_Renderer_Abstract
4646
{
4747
/**
4848
* Render and return a unified diff.
@@ -52,7 +52,7 @@ class DiffLib_Renderer_Unified extends DiffLib_Renderer_Base
5252
public function Render()
5353
{
5454
$diff = '';
55-
$opCodes = $this->diff->GetGroupedOpCodes();
55+
$opCodes = $this->diff->getGroupedOpcodes();
5656
foreach($opCodes as $group) {
5757
$lastItem = count($group)-1;
5858
$i1 = $group[0][1];

0 commit comments

Comments
 (0)