\Drupal\strata\Site SiteContext

Which site's history a read or a write belongs to.

Several sites can share one bucket, and often should: dedup is per-frame and content-addressed, so two sites running the same modules share the frames for their identical config and code, and the second site's code realm costs almost nothing. What they must not share is history. A commit is a statement about one site at one instant, and a ref that two sites both advanced would describe neither.

So every key is prefixed with a site id and every ref lives under it. A restore reads only its own site's refs; a prune walks only its own site's commits. Frames stay shared, because a frame is content and content has no owner.

The site id is derived once and then fixed. It defaults to a digest of the database connection's own identity - the database name and the table prefix - because that is what actually distinguishes two sites sharing a codebase, and because it does not change when a domain does. A site that moves to a new database keeps its history by setting the id explicitly, which is exactly the case where deriving it again would silently start a second history.

Summary

Methods
Properties
Constants
__construct
id
isExplicit
prefix
key
strip
reset
normalise
No public properties found
ID_LENGTH
No protected methods found
No protected properties found
No protected constants found
derive
id
configFactory
database
No private constants found

Constant

ID_LENGTH

ID_LENGTH = 12

How many hex characters of the derived digest the id uses.

Short enough to keep keys readable, long enough that two sites in one bucket will not collide.

Properties

$id

$id : ?string

The resolved id, or NULL until first asked.

Type

string|null

$configFactory

$configFactory : \Drupal\Core\Config\ConfigFactoryInterface

Type

ConfigFactoryInterface

$database

$database : \Drupal\Core\Database\Connection

Type

Connection

Methods

__construct()

__construct(\Drupal\Core\Config\ConfigFactoryInterface  $configFactory, \Drupal\Core\Database\Connection  $database) : mixed

Constructs a context.

Parameters

\Drupal\Core\Config\ConfigFactoryInterface $configFactory

Where a configured site id is read from.

\Drupal\Core\Database\Connection $database

Used to derive an id when none is configured.

Returns

mixed —

id()

id() : string

This site's id.

Returns

string —

The configured id, or one derived from the database connection.

isExplicit()

isExplicit() : bool

Whether the id was configured rather than derived.

Shown on the status page, because a derived id is one that would change if the database moved and a configured one is not.

Returns

bool —

TRUE when a site id is set in configuration.

prefix()

prefix() : string

The key prefix every object for this site sits under.

Returns

string —

Something such as "a1b2c3d4e5f6/".

key()

key(string  $key) : string

A key inside this site's namespace.

Parameters

string $key

The key relative to the site, such as "commits/aa/bb/cc".

Returns

string —

The full key.

strip()

strip(string  $key) : string|null

Strips this site's prefix off a key.

Parameters

string $key

The full key.

Returns

string|null —

The key relative to the site, or NULL when the key belongs to a different site. Returning NULL rather than the key unchanged is what stops a listing over a shared bucket quietly handing one site another's commits.

reset()

reset() : void

Forgets the resolved id.

Called after a settings change, and by a test that switches sites mid-run.

Returns

void —

normalise()

normalise(string  $id) : string

Reduces a configured id to something safe in an object key.

A site id ends up in every key this site writes, so a slash or a traversal segment in it would let one site write into another's namespace.

Parameters

string $id

The configured id.

Returns

string —

The id with everything but letters, digits, hyphens and underscores removed.

derive()

derive() : string

An id derived from the database connection's identity.

The database name and table prefix together are what distinguishes two Drupal sites sharing a codebase, which is the multi-site case this exists for. A domain is not used: it changes when a site is renamed or moved behind a different host, and a changed site id means a second history.

Returns

string —

The derived id.