DiffOp.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)
  4. *
  5. * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
  6. * You may copy this code freely under the conditions of the GPL.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. * http://www.gnu.org/copyleft/gpl.html
  22. *
  23. * @file
  24. * @ingroup DifferenceEngine
  25. * @defgroup DifferenceEngine DifferenceEngine
  26. */
  27. /**
  28. * The base class for all other DiffOp classes.
  29. *
  30. * The classes that extend DiffOp are: DiffOpCopy, DiffOpDelete, DiffOpAdd and
  31. * DiffOpChange. FakeDiffOp also extends DiffOp, but it is not located in this file.
  32. *
  33. * @private
  34. * @ingroup DifferenceEngine
  35. */
  36. abstract class DiffOp {
  37. /**
  38. * @var string
  39. */
  40. public $type;
  41. /**
  42. * @var string[]|false
  43. */
  44. public $orig;
  45. /**
  46. * @var string[]|false
  47. */
  48. public $closing;
  49. /**
  50. * @return string
  51. */
  52. public function getType() {
  53. return $this->type;
  54. }
  55. /**
  56. * @return string[]
  57. */
  58. public function getOrig() {
  59. return $this->orig;
  60. }
  61. /**
  62. * @param int|null $i
  63. * @return string[]|string|null
  64. */
  65. public function getClosing( $i = null ) {
  66. if ( $i === null ) {
  67. return $this->closing;
  68. }
  69. if ( array_key_exists( $i, $this->closing ) ) {
  70. return $this->closing[$i];
  71. }
  72. return null;
  73. }
  74. abstract public function reverse();
  75. /**
  76. * @return int
  77. */
  78. public function norig() {
  79. return $this->orig ? count( $this->orig ) : 0;
  80. }
  81. /**
  82. * @return int
  83. */
  84. public function nclosing() {
  85. return $this->closing ? count( $this->closing ) : 0;
  86. }
  87. }