Props
in package
Immutable spawn configuration for an actor.
Props bundles the behavior factory with optional mailbox capacity and supervision strategy overrides. You pass a Props value to ActorSystem::spawn() or ActorContext::spawn() to create a new actor. The static factory methods (fromBehavior, fromFactory, fromStatefulFactory, fromContainer) cover the four actor definition styles supported by Nexus.
Example:
// Closure-based
$props = Props::fromBehavior(Behavior::receive(fn($ctx, $msg) => Behavior::same()));
// Class-based (fresh instance per spawn)
$props = Props::fromFactory(fn() => new OrderActor($repository));
// Class-based from PSR-11 container
$props = Props::fromContainer($container, PaymentActor::class);
// Override mailbox capacity and supervision strategy
$props = Props::fromBehavior($behavior)
->withMailbox(MailboxConfig::bounded(100, OverflowStrategy::DropNewest))
->withSupervision(SupervisionStrategy::oneForOne(maxRetries: 3));
Tags
Table of Contents
Properties
Methods
- fromBehavior() : Props<string|int, U>
- Create Props from a pre-built Behavior instance.
- fromContainer() : Props<string|int, U>
- Create Props from a PSR-11 container and actor class name.
- fromFactory() : Props<string|int, U>
- Create Props from a callable factory that produces an ActorHandler.
- fromStatefulFactory() : Props<string|int, U>
- Create Props from a callable factory that produces a StatefulActorHandler.
- withMailbox() : Props<string|int, T>
- Return a new Props with the given mailbox configuration.
- withSupervision() : Props<string|int, T>
- Return a new Props with the given supervision strategy.
Properties
$behavior
public
Behavior
$behavior
$mailbox
public
MailboxConfig
$mailbox
$supervision
public
SupervisionStrategy|null
$supervision
Methods
fromBehavior()
Create Props from a pre-built Behavior instance.
public
static fromBehavior(Behavior<string|int, U> $behavior) : Props<string|int, U>
This is the simplest factory — use it when you already have a Behavior value (e.g. from Behavior::receive() or Behavior::setup()) and do not need to change mailbox or supervision defaults.
Parameters
- $behavior : Behavior<string|int, U>
Tags
Return values
Props<string|int, U>fromContainer()
Create Props from a PSR-11 container and actor class name.
public
static fromContainer(ContainerInterface $container, string $actorClass) : Props<string|int, U>
Resolves a fresh instance per spawn via $container->get($actorClass).
Parameters
- $container : ContainerInterface
- $actorClass : string
Tags
Return values
Props<string|int, U>fromFactory()
Create Props from a callable factory that produces an ActorHandler.
public
static fromFactory(callable(): ActorHandler<string|int, U> $factory) : Props<string|int, U>
A fresh instance is created per spawn inside Behavior::setup. If the instance extends AbstractActor, lifecycle hooks (onPreStart, onPostStop) are wired automatically.
Parameters
- $factory : callable(): ActorHandler<string|int, U>
Tags
Return values
Props<string|int, U>fromStatefulFactory()
Create Props from a callable factory that produces a StatefulActorHandler.
public
static fromStatefulFactory(callable(): StatefulActorHandler<U, S> $factory) : Props<string|int, U>
A fresh instance is created per spawn. Uses Behavior::withState internally.
Parameters
- $factory : callable(): StatefulActorHandler<U, S>
Tags
Return values
Props<string|int, U>withMailbox()
Return a new Props with the given mailbox configuration.
public
withMailbox(MailboxConfig $config) : Props<string|int, T>
The default is an unbounded mailbox. Use MailboxConfig::bounded() when you need back-pressure or message-drop semantics.
Parameters
- $config : MailboxConfig
Return values
Props<string|int, T>withSupervision()
Return a new Props with the given supervision strategy.
public
withSupervision(SupervisionStrategy $strategy) : Props<string|int, T>
Overrides the default one-for-one restart strategy. Use this to configure exponential backoff or all-for-one restarts on a specific actor.
Parameters
- $strategy : SupervisionStrategy