2
2
3
3
namespace Caxy \HtmlDiff ;
4
4
5
- error_reporting (E_ALL );
6
-
7
5
class ListDiff extends HtmlDiff
8
6
{
9
7
/**
@@ -40,8 +38,16 @@ class ListDiff extends HtmlDiff
40
38
*/
41
39
protected $ listType ;
42
40
41
+ /**
42
+ * Used to hold what type of list the old list is.
43
+ * @var string
44
+ */
43
45
protected $ oldListType ;
44
46
47
+ /**
48
+ * Used to hold what type of list the new list is.
49
+ * @var string
50
+ */
45
51
protected $ newListType ;
46
52
47
53
/**
@@ -68,10 +74,16 @@ class ListDiff extends HtmlDiff
68
74
*/
69
75
protected $ listsIndex ;
70
76
77
+ /**
78
+ * Array that holds the index of all content outside of the array. Format is array(index => content).
79
+ * @var array
80
+ */
71
81
protected $ contentIndex = array ();
72
82
73
- protected $ contentMatches = array ();
74
-
83
+ /**
84
+ * Holds the order and data on each list/content block within this list.
85
+ * @var array
86
+ */
75
87
protected $ diffOrderIndex = array ();
76
88
77
89
/**
@@ -124,6 +136,9 @@ protected function diffListContent()
124
136
$ this ->diff ();
125
137
}
126
138
139
+ /**
140
+ * This function is used to populate both contentIndex and diffOrderIndex arrays for use in the diff function.
141
+ */
127
142
protected function indexContent ()
128
143
{
129
144
$ this ->contentIndex = array ();
@@ -262,12 +277,23 @@ protected function matchAndCompareLists()
262
277
*/
263
278
$ this ->compareChildLists ();
264
279
}
265
-
280
+
281
+ /**
282
+ * Creates matches for lists.
283
+ */
266
284
protected function compareChildLists ()
267
285
{
268
286
$ this ->createNewOldMatches ($ this ->childLists , $ this ->textMatches , 'content ' );
269
287
}
270
288
289
+ /**
290
+ * Abstracted function used to match items in an array.
291
+ * This is used primarily for populating lists matches.
292
+ *
293
+ * @param array $listArray
294
+ * @param array $resultArray
295
+ * @param string|null $column
296
+ */
271
297
protected function createNewOldMatches (&$ listArray , &$ resultArray , $ column = null )
272
298
{
273
299
// Always compare the new against the old.
@@ -408,8 +434,6 @@ protected function buildChildLists()
408
434
*/
409
435
protected function diff ()
410
436
{
411
- //$this->dump($this->diffOrderIndex, "diff order index");
412
- //$this->dump($this->list, "list");
413
437
// Add the opening parent node from listType. So if ol, <ol>, etc.
414
438
$ this ->content = $ this ->addListTypeWrapper ();
415
439
@@ -459,25 +483,15 @@ protected function diff()
459
483
$ this ->content .= $ this ->addListTypeWrapper (false );
460
484
}
461
485
462
- protected function dump ($ asset , $ string = '' )
463
- {
464
- ini_set ('xdebug.var_display_max_depth ' , 5 );
465
- ini_set ('xdebug.var_display_max_children ' , 2000 );
466
- ini_set ('xdebug.var_display_max_data ' , 1024 );
467
-
468
- if ($ string ) {
469
- $ trueString = "======================= " . $ string ;
470
- var_dump (strtoupper ($ trueString ));
471
- }
472
-
473
- var_dump ($ asset );
474
-
475
- if (isset ($ trueString )) {
476
- $ trueString .= " ========= END END END " ;
477
- var_dump (strtoupper ($ trueString ));
478
- }
479
- }
480
-
486
+ /**
487
+ * This function replaces array_column function in PHP for older versions of php.
488
+ *
489
+ * @param array $parentArray
490
+ * @param string $column
491
+ * @param mixed $value
492
+ * @param boolean $allMatches
493
+ * @return array|boolean
494
+ */
481
495
protected function getArrayByColumnValue ($ parentArray , $ column , $ value , $ allMatches = false )
482
496
{
483
497
$ returnArray = array ();
@@ -493,41 +507,6 @@ protected function getArrayByColumnValue($parentArray, $column, $value, $allMatc
493
507
494
508
return $ allMatches ? $ returnArray : false ;
495
509
}
496
-
497
- protected function diffThisList ($ word , $ key )
498
- {
499
- $ listIndexValue = $ this ->getListIndexValue ($ key );
500
- $ newList = $ this ->childLists ['new ' ][$ listIndexValue ];
501
-
502
- $ textMatchKey = $ this ->getTextMatchKey ($ listIndexValue );
503
- $ oldList = $ this ->childLists ['old ' ][$ this ->textMatches [$ textMatchKey ]['old ' ]];
504
-
505
- return $ this ->processPlaceholders (
506
- $ this ->diffElements (
507
- $ this ->convertListContentArrayToString ($ oldList ),
508
- $ this ->convertListContentArrayToString ($ newList ),
509
- false
510
- ),
511
- $ this ->textMatches [$ textMatchKey ]
512
- );
513
- }
514
-
515
- protected function getListIndexValue ($ key , $ type = 'new ' )
516
- {
517
- return array_search ($ key , $ this ->listsIndex [$ type ]);
518
- }
519
-
520
- protected function getTextMatchKey ($ listIndexValue , $ type = 'new ' )
521
- {
522
- return array_search ($ listIndexValue , array_column ($ this ->textMatches , $ type ));
523
- }
524
-
525
- protected function getListByMatchKey ($ textMatchKey , $ type = 'old ' )
526
- {
527
- return array_key_exists ($ textMatchKey , $ this ->textMatches )
528
- ? $ this ->childLists [$ type ][$ this ->textMatches [$ textMatchKey ][$ type ]]
529
- : '' ;
530
- }
531
510
532
511
/**
533
512
* Converts the list (li) content arrays to string.
0 commit comments