multiversion-8.x-1.0-beta34/src/Entity/Index/MultiversionIndexFactory.php
src/Entity/Index/MultiversionIndexFactory.php
<?php namespace Drupal\multiversion\Entity\Index; use Drupal\multiversion\Entity\WorkspaceInterface; use Drupal\multiversion\Workspace\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, WorkspaceInterface $workspace = null) { $index = $this->container->get($service . '.scope'); if ($index instanceof IndexInterface) { $workspace_id = $workspace ? $workspace->id() : $this->workspaceManager->getActiveWorkspaceId(); return $indexes[$workspace_id][$service] = $index->useWorkspace($workspace_id); } else { throw new \InvalidArgumentException("Service $service is not an instance of IndexInterface."); } } }