Vendor

Reference for the Vendor module: an in-memory registry of third-party vendors such as Stripe, Twilio and AWS. A capability module declares a vendor type and the interface shape its vendors must fill; each vendor sub-module registers itself as that type with a name, its config keys and its function implementations; the owning module resolves a vendor by name and pulls out its functions and config. It holds descriptors only, never the vendor's own code, and never decides which vendor is active.

This page is a pure reference. For how the framework fits together, see the Guide.

Classes
  • VendorConfig - the registry: declare vendor types, register vendors, and resolve them by name.
  • VendorRegisterConfig - the collector used inside the VendorConfig::Register closure to describe a vendor.
  • VendorTypeConfig - the collector used inside the VendorConfig::Type closure to declare a vendor type's shape.

VendorConfig

The registry, in two levels. Level one: a capability module declares a vendor type and its shape with Type. Level two: a vendor sub-module registers itself as an implementation of a type with Register. The owning module then resolves a vendor by name with GetFunction and GetConfig. It is deliberately ignorant of selection and of what the functions do, holding only names, config-key names and callable references.

AllTypes

VendorConfig::AllTypes(): array

All declared vendor types.

Returns array The type definitions.

AllVendors

VendorConfig::AllVendors(): array

All registered vendors as a flat list, for the vendor directory.

Returns array The vendor definitions.

GetConfig

VendorConfig::GetConfig(string $type, string $name, string $key): mixed

A config value for the named vendor, read from the Config module under the vendor's module.

NameTypeDescription
$typestringThe vendor type.
$namestringThe vendor id.
$keystringThe config key to read.

Returns mixed The configuration value.

GetFunction

VendorConfig::GetFunction(string $type, string $name, string $function): callable

The callable implementing the given function for the named vendor of the type.

NameTypeDescription
$typestringThe vendor type.
$namestringThe vendor id.
$functionstringThe function name the vendor provides.

Returns callable The vendor's implementation.

Has

VendorConfig::Has(string $type, string $name): bool

Whether a vendor of the given type and name is registered.

NameTypeDescription
$typestringThe vendor type.
$namestringThe vendor id.

Returns bool True when the vendor is registered.

Register

VendorConfig::Register(string $module, string $type, string $name, callable $details): void

Register a vendor as an implementation of a declared type. The details closure fills in the vendor's display name, config keys and function implementations, which are then validated against the type.

NameTypeDescription
$modulestringThe registering vendor sub-module; namespaces its config.
$typestringThe type it fulfils; must be declared first.
$namestringThe vendor id, for example stripe or twilio.
$detailscallableClosure using VendorRegisterConfig::Name, ConfigKey and Implement.

Returns void

Type

VendorConfig::Type(string $module, string $type, callable $shape): void

Declare a vendor type and its shape: the interface functions a vendor must implement and any config common to the type.

NameTypeDescription
$modulestringThe declaring module, for attribution.
$typestringThe globally-unique type key vendors target.
$shapecallableClosure using VendorTypeConfig::RequireFunction and RequireConfig.

Returns void

VendorNames

VendorConfig::VendorNames(string $type): array

The names of the vendors registered for a type. The owning module picks one, from its own config value or logic, then acts on it with GetFunction and GetConfig.

NameTypeDescription
$typestringThe vendor type.

Returns array A list of vendor names.

VendorRegisterConfig

The collector used inside the closure passed to VendorConfig::Register. An individual vendor fills in the shape its type declared: a display name, the config keys it needs, and the implementations of the type's required functions. The implementations are callable references, so the registry stays a thin set of descriptors.

ConfigKey

VendorRegisterConfig::ConfigKey(string $key, mixed $configType): void

Declare a config key this vendor needs. It is registered with the Config module under the registering module's namespace, so it is fully qualified even when another vendor uses the same key name.

NameTypeDescription
$keystringThe config key name.
$configTypemixedThe Config type for the value.

Returns void

Implement

VendorRegisterConfig::Implement(string $function, callable $callable): void

Provide the implementation of one of the type's required functions.

NameTypeDescription
$functionstringThe required function name being implemented.
$callablecallableThe implementation, usually a Class::Method reference.

Returns void

Name

VendorRegisterConfig::Name(string $displayName): void

Set the human-readable name shown in the admin. Defaults to the vendor id.

NameTypeDescription
$displayNamestringThe display name.

Returns void

VendorTypeConfig

The collector used inside the closure passed to VendorConfig::Type. A module declares the shape of its vendors here: the interface functions every vendor of the type must implement, and any config keys common to all vendors of the type (usually none, since config is per-vendor).

RequireConfig

VendorTypeConfig::RequireConfig(string $key, mixed $configType): void

Declare a config key that every vendor of this type needs. Rare, since config is usually per-vendor.

NameTypeDescription
$keystringThe config key name.
$configTypemixedThe Config type for the value.

Returns void

RequireFunction

VendorTypeConfig::RequireFunction(string $name): void

Declare a function the owning module will call on any vendor of this type.

NameTypeDescription
$namestringThe required function name.

Returns void