summaryrefslogtreecommitdiff
path: root/includes/pear/Text/Diff.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/pear/Text/Diff.php')
-rwxr-xr-x[-rw-r--r--]includes/pear/Text/Diff.php71
1 files changed, 36 insertions, 35 deletions
diff --git a/includes/pear/Text/Diff.php b/includes/pear/Text/Diff.php
index 4b3de1b..3b8d883 100644..100755
--- a/includes/pear/Text/Diff.php
+++ b/includes/pear/Text/Diff.php
@@ -35,25 +35,28 @@ class Text_Diff {
* Normally an array of two arrays, each
* containing the lines from a file.
*/
- function Text_Diff($engine, $params)
+ function __construct($engine, $params)
{
// Backward compatibility workaround.
if (!is_string($engine)) {
$params = array($engine, $params);
- $engine = 'auto';
+ $engine = "auto";
}
- if ($engine == 'auto') {
- $engine = extension_loaded('xdiff') ? 'xdiff' : 'native';
+ if ($engine == "auto") {
+ $engine = extension_loaded("xdiff") ? "xdiff" : "native";
} else {
$engine = basename($engine);
}
- require_once 'Text/Diff/Engine/' . $engine . '.php';
- $class = 'Text_Diff_Engine_' . $engine;
+ $class = "Text_Diff_Engine_" . $engine;
+ if (!class_exists($class)) {
+ require_once "Text/Diff/Engine/" . $engine . ".php";
+ }
+
$diff_engine = new $class();
- $this->_edits = call_user_func_array(array($diff_engine, 'diff'), $params);
+ $this->_edits = call_user_func_array(array($diff_engine, "diff"), $params);
}
/**
@@ -63,7 +66,7 @@ class Text_Diff {
{
return $this->_edits;
}
-
+
/**
* returns the number of new (added) lines in a given diff.
*
@@ -76,14 +79,14 @@ class Text_Diff {
{
$count = 0;
foreach ($this->_edits as $edit) {
- if (is_a($edit, 'Text_Diff_Op_add') ||
- is_a($edit, 'Text_Diff_Op_change')) {
+ if (is_a($edit, "Text_Diff_Op_add") ||
+ is_a($edit, "Text_Diff_Op_change")) {
$count += $edit->nfinal();
}
}
return $count;
}
-
+
/**
* Returns the number of deleted (removed) lines in a given diff.
*
@@ -96,8 +99,8 @@ class Text_Diff {
{
$count = 0;
foreach ($this->_edits as $edit) {
- if (is_a($edit, 'Text_Diff_Op_delete') ||
- is_a($edit, 'Text_Diff_Op_change')) {
+ if (is_a($edit, "Text_Diff_Op_delete") ||
+ is_a($edit, "Text_Diff_Op_change")) {
$count += $edit->norig();
}
}
@@ -120,7 +123,7 @@ class Text_Diff {
*/
function reverse()
{
- if (version_compare(zend_version(), '2', '>')) {
+ if (version_compare(zend_version(), "2", ">")) {
$rev = clone($this);
} else {
$rev = $this;
@@ -140,7 +143,7 @@ class Text_Diff {
function isEmpty()
{
foreach ($this->_edits as $edit) {
- if (!is_a($edit, 'Text_Diff_Op_copy')) {
+ if (!is_a($edit, "Text_Diff_Op_copy")) {
return false;
}
}
@@ -158,7 +161,7 @@ class Text_Diff {
{
$lcs = 0;
foreach ($this->_edits as $edit) {
- if (is_a($edit, 'Text_Diff_Op_copy')) {
+ if (is_a($edit, "Text_Diff_Op_copy")) {
$lcs += count($edit->orig);
}
}
@@ -208,32 +211,30 @@ class Text_Diff {
* @param string $line The line to trim.
* @param integer $key The index of the line in the array. Not used.
*/
- function trimNewlines(&$line, $key)
+ static function trimNewlines(&$line, $key)
{
- $line = str_replace(array("\n", "\r"), '', $line);
+ $line = str_replace(array("\n", "\r"), "", $line);
}
/**
* Determines the location of the system temporary directory.
*
- * @static
- *
* @access protected
*
* @return string A directory name which can be used for temp files.
* Returns false if one could not be found.
*/
- function _getTempDir()
+ static function _getTempDir()
{
- $tmp_locations = array('/tmp', '/var/tmp', 'c:\WUTemp', 'c:\temp',
+ $tmp_locations = array("/tmp", "/var/tmp", 'c:\WUTemp', 'c:\temp',
'c:\windows\temp', 'c:\winnt\temp');
/* Try PHP's upload_tmp_dir directive. */
- $tmp = ini_get('upload_tmp_dir');
+ $tmp = ini_get("upload_tmp_dir");
/* Otherwise, try to determine the TMPDIR environment variable. */
if (!strlen($tmp)) {
- $tmp = getenv('TMPDIR');
+ $tmp = getenv("TMPDIR");
}
/* If we still cannot determine a value, then cycle through a list of
@@ -307,13 +308,13 @@ class Text_MappedDiff extends Text_Diff {
* @param array $mapped_to_lines This array should have the same number
* of elements as $to_lines.
*/
- function Text_MappedDiff($from_lines, $to_lines,
+ function __construct($from_lines, $to_lines,
$mapped_from_lines, $mapped_to_lines)
{
assert(count($from_lines) == count($mapped_from_lines));
assert(count($to_lines) == count($mapped_to_lines));
- parent::Text_Diff($mapped_from_lines, $mapped_to_lines);
+ parent::__construct($mapped_from_lines, $mapped_to_lines);
$xi = $yi = 0;
for ($i = 0; $i < count($this->_edits); $i++) {
@@ -346,7 +347,7 @@ class Text_Diff_Op {
function &reverse()
{
- trigger_error('Abstract method', E_USER_ERROR);
+ trigger_error("Abstract method", E_USER_ERROR);
}
function norig()
@@ -369,7 +370,7 @@ class Text_Diff_Op {
*/
class Text_Diff_Op_copy extends Text_Diff_Op {
- function Text_Diff_Op_copy($orig, $final = false)
+ function __construct($orig, $final = false)
{
if (!is_array($final)) {
$final = $orig;
@@ -380,7 +381,7 @@ class Text_Diff_Op_copy extends Text_Diff_Op {
function &reverse()
{
- $reverse = &new Text_Diff_Op_copy($this->final, $this->orig);
+ $reverse = new Text_Diff_Op_copy($this->final, $this->orig);
return $reverse;
}
@@ -394,7 +395,7 @@ class Text_Diff_Op_copy extends Text_Diff_Op {
*/
class Text_Diff_Op_delete extends Text_Diff_Op {
- function Text_Diff_Op_delete($lines)
+ function __construct($lines)
{
$this->orig = $lines;
$this->final = false;
@@ -402,7 +403,7 @@ class Text_Diff_Op_delete extends Text_Diff_Op {
function &reverse()
{
- $reverse = &new Text_Diff_Op_add($this->orig);
+ $reverse = new Text_Diff_Op_add($this->orig);
return $reverse;
}
@@ -416,7 +417,7 @@ class Text_Diff_Op_delete extends Text_Diff_Op {
*/
class Text_Diff_Op_add extends Text_Diff_Op {
- function Text_Diff_Op_add($lines)
+ function __construct($lines)
{
$this->final = $lines;
$this->orig = false;
@@ -424,7 +425,7 @@ class Text_Diff_Op_add extends Text_Diff_Op {
function &reverse()
{
- $reverse = &new Text_Diff_Op_delete($this->final);
+ $reverse = new Text_Diff_Op_delete($this->final);
return $reverse;
}
@@ -438,7 +439,7 @@ class Text_Diff_Op_add extends Text_Diff_Op {
*/
class Text_Diff_Op_change extends Text_Diff_Op {
- function Text_Diff_Op_change($orig, $final)
+ function __construct($orig, $final)
{
$this->orig = $orig;
$this->final = $final;
@@ -446,7 +447,7 @@ class Text_Diff_Op_change extends Text_Diff_Op {
function &reverse()
{
- $reverse = &new Text_Diff_Op_change($this->final, $this->orig);
+ $reverse = new Text_Diff_Op_change($this->final, $this->orig);
return $reverse;
}