Greenlight

Documentation

API reference

On this page

Harness API

This reference lists harness service and lifecycle contracts.

These signatures are the public API.

Disposable

Namespace: Greenlight\Harness

A harness service that Greenlight disposes when its service scope closes.

Greenlight disposes services in reverse creation order. An exception from one service does not prevent disposal of the remaining services.

interface Disposable

View source

dispose()

public function dispose(): void;

View source

Scope

Namespace: Greenlight\Harness

Defines the lifetime of a harness service.

PerWorker matches the physical worker lifetime.

enum Scope: string

View source

PerTest

case PerTest = 'per-test';

View source

PerClass

case PerClass = 'per-class';

View source

PerWorker

case PerWorker = 'per-worker';

View source

Service

Namespace: Greenlight\Harness

Selects a service ID or a named source for a constructor parameter. Each bridge translates the ID into its container lookup, or uses the default lookup if the ID is absent. The service must have the declared type.

#[\Attribute(\Attribute::TARGET_PARAMETER)]
final readonly class Service

View source

$id

public ?string $id;

PHPDoc:

View source

$source

public ?string $source;

PHPDoc:

View source

__construct()

public function __construct(?string $id = null, ?string $source = null)

PHPDoc:

View source

ServiceDefinition

Namespace: Greenlight\Harness

Defines one harness service. It contains the exact injected type, service scope, factory, and optional source name.

final readonly class ServiceDefinition

View source

$type

public string $type;

PHPDoc:

View source

$source

public ?string $source;

PHPDoc:

View source

$scope

public Scope $scope

View source

$factory

public \Closure $factory

View source

__construct()

public function __construct(
    string $type,
    public Scope $scope,
    public \Closure $factory,
    ?string $source = null,
)

PHPDoc:

View source

ServiceResolutionFailed

Namespace: Greenlight\Harness

Greenlight could not supply a valid service from a harness or container integration.

abstract class ServiceResolutionFailed extends \RuntimeException

View source

This type does not declare public members.

ServiceResolver

Namespace: Greenlight\Harness

Greenlight calls service resolvers with lower priorities first. Equal priorities use registration order. A terminal resolver runs after all other resolvers, regardless of priority.

A null result asks Greenlight to call the next resolver. An object must have the requested type. A ServiceResolutionFailed exception stops resolution.

Objects from a service resolver do not belong to a harness service scope. Greenlight does not dispose them. The source of an object controls its lifetime.

interface ServiceResolver

View source

resolve()

public function resolve(string $type, array $attributes): ?object;

PHPDoc:

View source

ServiceSource

Namespace: Greenlight\Harness

Names one source of harness definitions or resolved services. Source names are case-sensitive. A null name keeps the source unnamed.

interface ServiceSource

View source

source()

public function source(): ?string;

PHPDoc:

View source

TerminalServiceResolver

Namespace: Greenlight\Harness

Identifies a resolver that handles every request. Greenlight places one terminal resolver after all fallback-capable resolvers.

A terminal resolver returns an object or throws ServiceResolutionFailed.

interface TerminalServiceResolver extends ServiceResolver

View source

resolve()

public function resolve(string $type, array $attributes): ?object;

PHPDoc:

View source