Skip to content

Commit

Permalink
Merge pull request #4536 from yiisoft/4534-fix-pear-diff-php-deprecat…
Browse files Browse the repository at this point in the history
…ions

Fix pear diff php deprecations
  • Loading branch information
marcovtwout authored Nov 14, 2023
2 parents 059b67b + 9f6583f commit 0361fac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Version 1.1.29 under development

- Bug #4516: PHP 8 compatibility: Allow union types and intersection types in action declarations (wtommyw)
- Bug #4523: Fixed translated in Greek class messages in framework requirements view, which they should not be translated (lourdas)
- Bug #4534: PHP 8.2 compatibility: Fix deprecated dynamic properties in gii/components/Pear/Text/Diff (mdeweerd, marcovtwout)
- Enh #4529: Exceptions thrown while loading fixture file rows now contain more details (eduardor2k)

Version 1.1.28 February 28, 2023
Expand Down
4 changes: 1 addition & 3 deletions framework/gii/components/Pear/Text/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,12 @@ static function trimNewlines(&$line, $key)
/**
* 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',
'c:\windows\temp', 'c:\winnt\temp');
Expand Down
24 changes: 20 additions & 4 deletions framework/gii/components/Pear/Text/Diff/Engine/native.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
*/
class Text_Diff_Engine_native {

public $xchanged;
public $ychanged;
public $xv;
public $yv;
public $xind;
public $yind;
public $seq;
public $in_seq;
public $lcs;

function diff($from_lines, $to_lines)
{
array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
Expand Down Expand Up @@ -63,9 +73,11 @@ function diff($from_lines, $to_lines)
}

// Ignore lines which do not exist in both files.
$xhash = [];
for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
$xhash[$from_lines[$xi]] = 1;
}
$yhash = [];
for ($yi = $skip; $yi < $n_to - $endskip; $yi++) {
$line = $to_lines[$yi];
if (($this->ychanged[$yi] = empty($xhash[$line]))) {
Expand Down Expand Up @@ -160,6 +172,7 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks)
= array($yoff, $ylim, $xoff, $xlim);
}

$ymatches = array();
if ($flip) {
for ($i = $ylim - 1; $i >= $yoff; $i--) {
$ymatches[$this->xv[$i]][] = $i;
Expand All @@ -173,7 +186,7 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks)
$this->lcs = 0;
$this->seq[0]= $yoff - 1;
$this->in_seq = array();
$ymids[0] = array();
$ymids = array(array());

$numer = $xlim - $xoff + $nchunks - 1;
$x = $xoff;
Expand All @@ -191,15 +204,17 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks)
continue;
}
$matches = $ymatches[$line];
while (($y = array_shift($matches)) !== null) {
reset($matches);
while ($y = current($matches)) {
if (empty($this->in_seq[$y])) {
$k = $this->_lcsPos($y);
assert($k > 0);
$ymids[$k] = $ymids[$k - 1];
break;
}
next($matches);
}
while (($y = array_shift($matches)) !== null) {
while ($y = current($matches)) {
if ($y > $this->seq[$k - 1]) {
assert($y <= $this->seq[$k]);
/* Optimization: this is a common case: next match is
Expand All @@ -212,11 +227,12 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks)
assert($k > 0);
$ymids[$k] = $ymids[$k - 1];
}
next($matches);
}
}
}

$seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
$seps = array($flip ? array($yoff, $xoff) : array($xoff, $yoff));
$ymid = $ymids[$this->lcs];
for ($n = 0; $n < $nchunks - 1; $n++) {
$x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks);
Expand Down
2 changes: 1 addition & 1 deletion framework/gii/components/Pear/Text/Diff/Mapped.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function __construct($from_lines, $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++) {
Expand Down

0 comments on commit 0361fac

Please sign in to comment.