\Drupal\strata\Storage StorageProviderManager

Holds the storage providers a site has available.

A registry, not a policy. Which provider a flush is written to is strata.settings's provider key, resolved by Engine; this class only knows what has been contributed and how to build it. An add-on registers here and needs no change anywhere else in the engine.

Every enabled submodule registers whether or not the site has configured it, so the ids held here are what is available rather than what is in use. A caller wanting to report on the store the site actually writes to has to name that provider itself.

Summary

Methods
Properties
Constants
register
registerFactory
registerProviderFactory
factory
get
has
ids
all
reachability
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
No private methods found
providers
deferred
factories
No private constants found

Properties

$deferred

$deferred : array

Providers not built yet, keyed by id.

Building a provider can fail - a missing bucket, an unreachable endpoint, credentials that do not resolve - so a provider the site is not using is never constructed. Registering an eager instance would make a misconfigured optional provider take the whole container down.

Type

array<string, callable(): StorageProviderInterface> —

$factories

$factories : array

Factories a submodule contributed, keyed by id.

Held alongside the deferred closure rather than swallowed by it, because a tiered store has to ask a factory for a second provider at a different location. A closure can only be called; a factory can be asked what it is capable of.

Type

array<string, StorageProviderFactoryInterface> —

Methods

register()

register(\Drupal\strata\Storage\StorageProviderInterface  $provider) : $this

Adds a provider.

Parameters

\Drupal\strata\Storage\StorageProviderInterface $provider

The provider.

Throws

\InvalidArgumentException

When another provider is already registered under that id. Silently replacing it would redirect every subsequent write with no signal.

Returns

$this —

The manager, for chaining.

registerFactory()

registerFactory(string  $id, callable  $factory) : $this

Adds a provider that is built the first time it is asked for.

Parameters

string $id

The provider id, as it appears in configuration.

callable $factory

Builds the provider.

Throws

\InvalidArgumentException

When another provider is already registered under that id.

Returns

$this —

The manager, for chaining.

registerProviderFactory()

registerProviderFactory(\Drupal\strata\Storage\StorageProviderFactoryInterface  $factory) : $this

Adds a provider contributed by a submodule, built on first use.

The shape a Drupal service collector calls: a submodule tags an object exposing id() and create(), and the manager holds it until something asks for that provider. A submodule whose endpoint is misconfigured therefore reports itself unreachable rather than taking the container down at compile time.

Parameters

\Drupal\strata\Storage\StorageProviderFactoryInterface $factory

The contributed factory.

Throws

\InvalidArgumentException

When another provider is already registered under that id.

Returns

$this —

The manager, for chaining.

factory()

factory(string  $id) : \Drupal\strata\Storage\StorageProviderFactoryInterface|null

The factory a provider id was contributed by.

What a tiered store needs: the same endpoint pointed at a second bucket can only be built by the thing that knows how to build the first one.

Parameters

string $id

A provider id.

Returns

\Drupal\strata\Storage\StorageProviderFactoryInterface|null —

The factory, or NULL when the provider was registered as an instance or a bare closure rather than through a factory.

get()

get(string  $id) : \Drupal\strata\Storage\StorageProviderInterface

A provider by id.

Parameters

string $id

A registered provider id.

Throws

\InvalidArgumentException

When nothing is registered under that id.

Returns

\Drupal\strata\Storage\StorageProviderInterface —

The provider.

has()

has(string  $id) : bool

Whether a provider is registered.

Parameters

string $id

A provider id.

Returns

bool —

TRUE when it is registered.

ids()

ids() : list<string>

Every registered provider id.

Returns

list

Ids in registration order.

all()

all() : array<string,\Drupal\strata\Storage\StorageProviderInterface>

Every registered provider.

Returns

array

Providers keyed by id.

reachability()

reachability(string  $id) : string|null

Whether one provider can be reached right now.

Used by strata_requirements() to report the store the site writes to. It names a single provider rather than sweeping every registered one because registration follows the enabled submodules and not the configuration: a site running strata_s3 and strata_b2 but configured for S3 alone would otherwise report B2 as broken on the status page every time it loaded.

Three failure modes collapse into one reason string, and none of them raise. A provider id nothing registered, a factory that throws while building, and a provider that builds but cannot answer are all just "unreachable, and here is why" to a caller that must not take the status report down with it.

Parameters

string $id

The provider id to probe, as it appears in strata.settings.

Returns

string|null —

Why the provider cannot be reached, or NULL when it can be.