You are here

class ContextRepository in GraphQL 8.3

Non-lazy un-optimized context repository.

Intermediate solution for graphql requests that change context within one request and would confuse the LazyContextBuilder.

Hierarchy

Expanded class hierarchy of ContextRepository

1 string reference to 'ContextRepository'
graphql.services.yml in ./graphql.services.yml
graphql.services.yml
1 service uses ContextRepository
graphql.context_repository in ./graphql.services.yml
Drupal\graphql\GraphQL\Context\ContextRepository

File

src/GraphQL/Context/ContextRepository.php, line 14

Namespace

Drupal\graphql\GraphQL\Context
View source
class ContextRepository implements ContextRepositoryInterface {

  /**
   * The list of content providers.
   *
   * @var \Drupal\Core\Plugin\Context\ContextProviderInterface[]
   */
  protected $contextProviders = [];

  /**
   * Add a context provider.
   *
   * @param \Drupal\Core\Plugin\Context\ContextProviderInterface $contextProvider
   *   The context provider to add.
   */
  public function addContextProvider(ContextProviderInterface $contextProvider) {
    $this->contextProviders[] = $contextProvider;
  }

  /**
   * {@inheritdoc}
   */
  public function getRuntimeContexts(array $contextIds) {
    $contexts = [];
    foreach ($this->contextProviders as $contextProvider) {
      foreach ($contextProvider
        ->getRuntimeContexts($contextIds) as $id => $context) {
        $contexts[$id] = $context;
      }
    }
    return $contexts;
  }

  /**
   * {@inheritdoc}
   */
  public function getAvailableContexts() {
    $contexts = [];
    foreach ($this->contextProviders as $contextProvider) {
      foreach ($contextProvider
        ->getAvailableContexts() as $id => $context) {
        $contexts[$id] = $context;
      }
    }
    return $contexts;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContextRepository::$contextProviders protected property The list of content providers.
ContextRepository::addContextProvider public function Add a context provider.
ContextRepository::getAvailableContexts public function Gets all available contexts for the purposes of configuration. Overrides ContextRepositoryInterface::getAvailableContexts
ContextRepository::getRuntimeContexts public function Gets runtime context values for the given context IDs. Overrides ContextRepositoryInterface::getRuntimeContexts