2020use Temporal \Internal \Declaration \Prototype \WorkflowPrototype ;
2121use Temporal \Internal \Declaration \WorkflowInstance \SignalQueue ;
2222use Temporal \Internal \Interceptor ;
23+ use Temporal \Workflow \InitMethod ;
2324
2425/**
25- * @psalm-import-type DispatchableHandler from InstanceInterface
2626 * @psalm-type QueryHandler = \Closure(QueryInput): mixed
2727 * @psalm-type UpdateHandler = \Closure(UpdateInput, Deferred): PromiseInterface
2828 * @psalm-type ValidateUpdateHandler = \Closure(UpdateInput): void
2929 * @psalm-type QueryExecutor = \Closure(QueryInput, callable(ValuesInterface): mixed): mixed
3030 * @psalm-type UpdateExecutor = \Closure(UpdateInput, callable(ValuesInterface): mixed, Deferred): PromiseInterface
3131 * @psalm-type ValidateUpdateExecutor = \Closure(UpdateInput, callable(ValuesInterface): mixed): mixed
3232 * @psalm-type UpdateValidator = \Closure(UpdateInput, UpdateHandler): void
33+ *
34+ * @internal
3335 */
3436final class WorkflowInstance extends Instance implements WorkflowInstanceInterface
3537{
@@ -39,7 +41,7 @@ final class WorkflowInstance extends Instance implements WorkflowInstanceInterfa
3941 private array $ queryHandlers = [];
4042
4143 /**
42- * @var array<non-empty-string, DispatchableHandler >
44+ * @var array<non-empty-string, MethodHandler >
4345 */
4446 private array $ signalHandlers = [];
4547
@@ -140,11 +142,23 @@ public function setUpdateValidator(\Closure $validator): self
140142 /**
141143 * Trigger constructor in Process context.
142144 */
143- public function initConstructor ( ): void
145+ public function init ( array $ arguments = [] ): void
144146 {
145- if (\method_exists ($ this ->context , '__construct ' )) {
147+ if (!\method_exists ($ this ->context , '__construct ' )) {
148+ return ;
149+ }
150+
151+ if ($ arguments === []) {
146152 $ this ->context ->__construct ();
153+ return ;
147154 }
155+
156+ // Check InitMethod attribute
157+ $ reflection = new \ReflectionMethod ($ this ->context , '__construct ' );
158+ $ attributes = $ reflection ->getAttributes (InitMethod::class);
159+ $ attributes === []
160+ ? $ this ->context ->__construct ()
161+ : $ this ->context ->__construct (...$ arguments );
148162 }
149163
150164 public function getSignalQueue (): SignalQueue
@@ -288,12 +302,9 @@ public function getPrototype(): WorkflowPrototype
288302 /**
289303 * Make a Closure from a callable.
290304 *
291- * @return \Closure(ValuesInterface): mixed
292305 * @throws \ReflectionException
293- *
294- * @psalm-return DispatchableHandler
295306 */
296- protected function createCallableHandler (callable $ handler ): \ Closure
307+ protected function createCallableHandler (callable $ handler ): MethodHandler
297308 {
298309 return $ this ->createHandler (
299310 new \ReflectionFunction ($ handler instanceof \Closure ? $ handler : \Closure::fromCallable ($ handler )),
0 commit comments