Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

Diff.php

Same filename in this branch
  1. 11.1.x vendor/sebastian/diff/src/Diff.php
  2. 11.1.x vendor/squizlabs/php_codesniffer/src/Reports/Diff.php

Namespace

Drupal\Component\Diff

File

core/lib/Drupal/Component/Diff/Diff.php

View source
<?php

namespace Drupal\Component\Diff;

use SebastianBergmann\Diff\Differ;

/**
 * Class representing a 'diff' between two sequences of strings.
 *
 * Component code originally taken from https://www.drupal.org/project/diff
 * which was itself based on the PHP diff engine for phpwiki. The original code
 * in phpwiki was copyright (C) 2000, 2001 Geoffrey T. Dairiki
 * <dairiki@dairiki.org> and licensed under GPL.
 */
class Diff {
    
    /**
     * The list of differences as an array of diff operations.
     *
     * @var \Drupal\Component\Diff\Engine\DiffOp[]
     */
    protected $edits;
    
    /**
     * Constructor.
     * Computes diff between sequences of strings.
     *
     * @param array $from_lines
     *   An array of strings.
     *   (Typically these are lines from a file.)
     * @param array $to_lines
     *   An array of strings.
     */
    public function __construct($from_lines, $to_lines) {
        $diffOpBuilder = new DiffOpOutputBuilder();
        $differ = new Differ($diffOpBuilder);
        $this->edits = $diffOpBuilder->toOpsArray($differ->diffToArray($from_lines, $to_lines));
    }
    
    /**
     * Gets the list of differences as an array of diff operations.
     *
     * @return \Drupal\Component\Diff\Engine\DiffOp[]
     *   The list of differences as an array of diff operations.
     */
    public function getEdits() {
        return $this->edits;
    }

}

Classes

Title Deprecated Summary
Diff Class representing a 'diff' between two sequences of strings.
RSS feed
Powered by Drupal