Skip to main content

Class Drupal\workspaces\Provider\WorkspaceProviderCollector - Source Code

Primary tabs

API docs: https://api.drupal.org/api/drupal/core!modules!workspaces!src!Provider!WorkspaceProviderCollector.php/11.3.x

GitLab: https://git.drupalcode.org/project/drupal/-/blob/11.3.x/core/modules/workspaces/src/Provider/WorkspaceProviderCollector.php

Location: /core/modules/workspaces/src/Provider/WorkspaceProviderCollector.php

    
        
declare(strict_types=1);

namespace Drupal\workspaces\Provider;

use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;

/**
 * Defines the workspace provider collector.
 *
 * @internal
 */
class WorkspaceProviderCollector {

  public function __construct(
    #[AutowireIterator(tag: 'workspace_provider', defaultIndexMethod: 'getId')]
    protected iterable $providers,
  ) {
    $this->providers = iterator_to_array($this->providers);
  }

  /**
   * Gets the workspace provider for the given ID.
   *
   * @param string $id
   *   A workspace provider ID.
   *
   * @return \Drupal\workspaces\Provider\WorkspaceProviderInterface
   *   The workspace provider.
   */
  public function getProvider($id): WorkspaceProviderInterface {
    if (!isset($this->providers[$id])) {
      throw new \DomainException("Workspace provider '$id' not found.");
    }

    return $this->providers[$id];
  }

}