You are here

MultiversionIndexFactory.php in Multiversion 8.2

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

File

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

namespace Drupal\multiversion\Entity\Index;

use Drupal\workspaces\Entity\Workspace;
use Drupal\workspaces\WorkspaceManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MultiversionIndexFactory {

  /** @var  ContainerInterface */
  protected $container;

  /** @var  WorkspaceManagerInterface */
  protected $workspaceManager;

  /** @var EntityIndexInterface[]  */
  protected $indexes = [];
  public function __construct(ContainerInterface $container, WorkspaceManagerInterface $workspace_manager) {
    $this->container = $container;
    $this->workspaceManager = $workspace_manager;
  }
  public function get($service, Workspace $workspace = null) {
    $index = $this->container
      ->get($service . '.scope');
    if ($index instanceof IndexInterface) {
      $workspace_id = $workspace ? $workspace
        ->id() : $this->workspaceManager
        ->getActiveWorkspace()
        ->id();
      return $indexes[$workspace_id][$service] = $index
        ->useWorkspace($workspace_id);
    }
    else {
      throw new \InvalidArgumentException("Service {$service} is not an instance of IndexInterface.");
    }
  }

}

Classes