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
dispose()
public function dispose(): void;
Scope
Namespace: Greenlight\Harness
Defines the lifetime of a harness service.
PerWorker matches the physical worker lifetime.
enum Scope: string
PerTest
case PerTest = 'per-test';
PerClass
case PerClass = 'per-class';
PerWorker
case PerWorker = 'per-worker';
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
$id
public ?string $id;
PHPDoc:
@var non-empty-string|null
$source
public ?string $source;
PHPDoc:
@var non-empty-string|null
__construct()
public function __construct(?string $id = null, ?string $source = null)
PHPDoc:
@throws \InvalidArgumentException
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
$type
public string $type;
PHPDoc:
@var class-string
$source
public ?string $source;
PHPDoc:
@var non-empty-string|null
$scope
public Scope $scope
$factory
public \Closure $factory
__construct()
public function __construct(
string $type,
public Scope $scope,
public \Closure $factory,
?string $source = null,
)
PHPDoc:
@template T of object@param class-string<T>|'' $type@param \Closure(): T $factory@throws \InvalidArgumentException
ServiceResolutionFailed
Namespace: Greenlight\Harness
Greenlight could not supply a valid service from a harness or container integration.
abstract class ServiceResolutionFailed extends \RuntimeException
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
resolve()
public function resolve(string $type, array $attributes): ?object;
PHPDoc:
@param class-string $type@param list<object> $attributes@throws ServiceResolutionFailed when the resolver handles the request but cannot supply a valid service
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
source()
public function source(): ?string;
PHPDoc:
@return non-empty-string|null
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
resolve()
public function resolve(string $type, array $attributes): ?object;
PHPDoc:
@param class-string $type@param list<object> $attributes@throws ServiceResolutionFailed when the resolver handles the request but cannot supply a valid service