Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ServiceLoaderIterator.php

function ServiceLoaderIterator::current

File

vendor/tbachert/spi/src/ServiceLoaderIterator.php, line 39

Class

ServiceLoaderIterator
@template-covariant S of object service type @implements Iterator<class-string, S>

Namespace

Nevay\SPI

Code

public function current() : ?object {
    $index = $this->index;
    if ($instance = $this->cache[$index] ?? null) {
        return $instance;
    }
    if (($class = $this->providers[$index] ?? null) === null) {
        return null;
    }
    $this->cache[$index] = false;
    if (!is_subclass_of($class, $this->service)) {
        throw new ServiceConfigurationError(sprintf('Invalid service provider, expected implementation of "%s", got "%s"', $this->service, $class));
    }
    try {
        return $this->cache[$index] = new $class();
    } catch (Throwable $e) {
        throw new ServiceConfigurationError(sprintf('Invalid service provider, failed to instantiate "%s" provider "%s": %s', $this->service, $class, $e->getMessage()), previous: $e);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal