You are here

ComplexLcaResolver.php in Multiversion 8.2

Same filename and directory in other branches
  1. 8 src/Entity/Index/ComplexLcaResolver.php

File

src/Entity/Index/ComplexLcaResolver.php
View source
<?php

namespace Drupal\Multiversion\Entity\Index;

use Drupal\conflict\ConflictAncestorResolverInterface;
use Drupal\Core\Entity\RevisionableInterface;
use Relaxed\LCA\LowestCommonAncestor;
use Fhaculty\Graph\Graph;
class ComplexLcaResolver implements ConflictAncestorResolverInterface {

  /**
   * {@inheritdoc}
   */
  public function applies() {
    return TRUE;
  }

  /**
   * Find the lowest common parent of two revisions from given graph.
   *
   * @param RevisionableInterface $revision1
   * @param RevisionableInterface $revision2
   * @param Graph $graph
   *
   * @return array
   *   Returns an array of vertices or an empty array.
   */
  public function resolve(RevisionableInterface $revision1, RevisionableInterface $revision2, Graph $graph = NULL) {
    $lca = new LowestCommonAncestor($graph);
    $vertices = $graph
      ->getVertices()
      ->getMap();
    return $lca
      ->find($vertices[$revision1->_rev->value], $vertices[$revision2->_rev->value]);
  }

}

Classes

Namesort descending Description
ComplexLcaResolver