Documentation

WpComponentContext
in package
implements HostComponentContextInterface

Read onlyYes
FinalYes

Neutral WordPress host context.

The host plugin's composition root builds this once at boot and injects it into the adapter's per-component services (InertiaAdapter, EmailSender, ...) through its own DI container, so they resolve the host's identity, asset version, and base path without referencing any specific consumer plugin or its global constants — and without sharing a process-wide slot with other plugins in the same request.

Example (host plugin bootstrap):

$context = new WpComponentContext(
    componentName: 'my-plugin',
    assetVersion: MY_PLUGIN_VERSION,
    basePath: plugin_dir_path(__FILE__),
);
$inertia = new InertiaAdapter($context);
$mailer = new EmailSender($logger, $context);

Table of Contents

Interfaces

HostComponentContextInterface

Properties

$assetVersion  : string
$basePath  : string|null
$componentName  : string

Methods

__construct()  : mixed
assetVersion()  : string
basePath()  : string|null
componentName()  : string

Properties

Methods

__construct()

public __construct(string $componentName, string $assetVersion[, string|null $basePath = null ]) : mixed
Parameters
$componentName : string
$assetVersion : string
$basePath : string|null = null
On this page

Search results