You are here

class ConflictResolverManager in Conflict 8.2

Manages conflict resolving.

Hierarchy

Expanded class hierarchy of ConflictResolverManager

1 string reference to 'ConflictResolverManager'
conflict.services.yml in ./conflict.services.yml
conflict.services.yml
1 service uses ConflictResolverManager
conflict_resolver.manager in ./conflict.services.yml
\Drupal\conflict\ConflictResolver\ConflictResolverManager

File

src/ConflictResolver/ConflictResolverManager.php, line 15

Namespace

Drupal\conflict\ConflictResolver
View source
class ConflictResolverManager implements ConflictResolverManagerInterface {

  /**
   * The event dispatcher used to notify subscribers.
   *
   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
   */
  protected $eventDispatcher;

  /**
   * Constructs a new Conflict Resolver Manager.
   *
   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
   *   The event dispatcher used to notify subscribers of config import events.
   */
  public function __construct(EventDispatcherInterface $event_dispatcher) {
    $this->eventDispatcher = $event_dispatcher;
  }

  /**
   * {@inheritdoc}
   */
  public function resolveConflicts(EntityInterface $local, EntityInterface $remote, EntityInterface $base, EntityInterface $result = NULL, ParameterBag $context = NULL, array $conflicts = NULL) : array {

    // If none conflicts are given, then explicitly discover the conflicts.
    $conflicts = $conflicts ?? $this
      ->getConflicts($local, $remote, $base, $context);
    if ($conflicts) {
      $result = $result ?? $local;
      $event = new EntityConflictResolutionEvent($local, $remote, $base, $result, $conflicts, $context);

      // Fire an event to allow listeners to automatically resolve conflicts.
      $this->eventDispatcher
        ->dispatch(EntityConflictEvents::ENTITY_CONFLICT_RESOLVE, $event);
      $conflicts = $event
        ->getConflicts();
    }
    return $conflicts;
  }

  /**
   * {@inheritdoc}
   */
  public function getConflicts(EntityInterface $local, EntityInterface $remote, EntityInterface $base, ParameterBag $context = NULL) : array {
    $event = new EntityConflictDiscoveryEvent($local, $remote, $base, $context);

    // Fire an event to allow listeners to build a list of conflicting
    // properties.
    $this->eventDispatcher
      ->dispatch(EntityConflictEvents::ENTITY_CONFLICT_DISCOVERY, $event);
    return $event
      ->getConflicts();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConflictResolverManager::$eventDispatcher protected property The event dispatcher used to notify subscribers.
ConflictResolverManager::getConflicts public function Returns the conflicts between two entities based on their common parent. * Overrides ConflictResolverManagerInterface::getConflicts
ConflictResolverManager::resolveConflicts public function Resolves the conflicts between two entities based on their common parent. Overrides ConflictResolverManagerInterface::resolveConflicts
ConflictResolverManager::__construct public function Constructs a new Conflict Resolver Manager.