2323use Temporal \Exception \Failure \CanceledFailure ;
2424use Temporal \Exception \OutOfContextException ;
2525use Temporal \Internal \Support \Facade ;
26- use Temporal \Internal \Workflow \ScopeContext ;
2726use Temporal \Workflow \ActivityStubInterface ;
2827use Temporal \Workflow \CancellationScopeInterface ;
2928use Temporal \Workflow \ChildWorkflowOptions ;
@@ -57,11 +56,10 @@ final class Workflow extends Facade
5756 * Get the current Workflow context.
5857 * @throws OutOfContextException
5958 */
60- public static function getCurrentContext (): ScopedContextInterface
59+ public static function getCurrentContext (): WorkflowContextInterface
6160 {
6261 $ ctx = parent ::getCurrentContext ();
63- /** @var ScopeContext $ctx */
64- $ ctx ::class === ScopeContext::class or throw new OutOfContextException (
62+ $ ctx instanceof WorkflowContextInterface or throw new OutOfContextException (
6563 'The Workflow facade can be used only inside workflow code. ' ,
6664 );
6765 return $ ctx ;
@@ -202,7 +200,9 @@ public static function getInput(): ValuesInterface
202200 */
203201 public static function async (callable $ task ): CancellationScopeInterface
204202 {
205- return self ::getCurrentContext ()->async ($ task );
203+ $ ctx = self ::getCurrentContext ();
204+ \assert ($ ctx instanceof ScopedContextInterface);
205+ return $ ctx ->async ($ task );
206206 }
207207
208208 /**
@@ -254,7 +254,9 @@ public static function async(callable $task): CancellationScopeInterface
254254 */
255255 public static function asyncDetached (callable $ task ): CancellationScopeInterface
256256 {
257- return self ::getCurrentContext ()->asyncDetached ($ task );
257+ $ ctx = self ::getCurrentContext ();
258+ \assert ($ ctx instanceof ScopedContextInterface);
259+ return $ ctx ->asyncDetached ($ task );
258260 }
259261
260262 /**
@@ -362,7 +364,9 @@ public static function registerQuery(
362364 callable $ handler ,
363365 string $ description = '' ,
364366 ): ScopedContextInterface {
365- return self ::getCurrentContext ()->registerQuery ($ queryType , $ handler , $ description );
367+ $ ctx = self ::getCurrentContext ();
368+ \assert ($ ctx instanceof ScopedContextInterface);
369+ return $ ctx ->registerQuery ($ queryType , $ handler , $ description );
366370 }
367371
368372 /**
@@ -382,7 +386,9 @@ public static function registerQuery(
382386 */
383387 public static function registerSignal (string $ name , callable $ handler , string $ description = '' ): ScopedContextInterface
384388 {
385- return self ::getCurrentContext ()->registerSignal ($ name , $ handler , $ description );
389+ $ ctx = self ::getCurrentContext ();
390+ \assert ($ ctx instanceof ScopedContextInterface);
391+ return $ ctx ->registerSignal ($ name , $ handler , $ description );
386392 }
387393
388394 /**
@@ -501,7 +507,9 @@ public static function registerUpdate(
501507 ?callable $ validator = null ,
502508 string $ description = '' ,
503509 ): ScopedContextInterface {
504- return self ::getCurrentContext ()->registerUpdate ($ name , $ handler , $ validator , $ description );
510+ $ ctx = self ::getCurrentContext ();
511+ \assert ($ ctx instanceof ScopedContextInterface);
512+ return $ ctx ->registerUpdate ($ name , $ handler , $ validator , $ description );
505513 }
506514
507515 /**
0 commit comments