1212namespace Temporal \Nexus \Handler \Internal ;
1313
1414use Temporal \Api \Common \V1 \Payloads ;
15+ use Temporal \Client \WorkflowClientInterface ;
1516use Temporal \DataConverter \DataConverterInterface ;
1617use Temporal \DataConverter \EncodedValues ;
1718use Temporal \DataConverter \ValuesInterface ;
2324use Temporal \Interceptor \SimplePipelineProvider ;
2425use Temporal \Internal \Declaration \NexusServiceInstance ;
2526use Temporal \Internal \Nexus \NexusContext ;
26- use Temporal \Internal \Nexus \NexusEnvironment ;
2727use Temporal \Nexus \Exception \ErrorType ;
2828use Temporal \Nexus \Exception \HandlerException ;
2929use Temporal \Nexus \Exception \InvalidArgumentException ;
@@ -92,7 +92,8 @@ public function startOperation(
9292 OperationContext $ context ,
9393 OperationStartDetails $ details ,
9494 ValuesInterface $ input ,
95- ?NexusEnvironment $ environment = null ,
95+ ?WorkflowClientInterface $ workflowClient = null ,
96+ NexusOperationContext $ operationContext = new NexusOperationContext (),
9697 ): OperationStartResult {
9798 [$ instance , $ handler ] = $ this ->resolveHandler ($ context );
9899
@@ -119,8 +120,8 @@ public function startOperation(
119120 }
120121
121122 Nexus::setCurrentContext (new NexusContext (
122- operation: self ::buildPublicOperationContext ( $ environment ),
123- environment : $ environment ,
123+ operation: self ::publicOperationContext ( $ operationContext ),
124+ workflowClient : $ workflowClient ,
124125 current: $ contextWithServiceDefinition ,
125126 startDetails: $ details ,
126127 outboundPipeline: $ this ->interceptorProvider
@@ -160,7 +161,8 @@ public function startOperation(
160161 public function cancelOperation (
161162 OperationContext $ context ,
162163 OperationCancelDetails $ details ,
163- ?NexusEnvironment $ environment = null ,
164+ ?WorkflowClientInterface $ workflowClient = null ,
165+ NexusOperationContext $ operationContext = new NexusOperationContext (),
164166 ): void {
165167 [$ instance , $ handler ] = $ this ->resolveHandler ($ context );
166168
@@ -179,8 +181,8 @@ public function cancelOperation(
179181 $ contextWithServiceDefinition = $ context ->withServiceDefinition ($ instance ->prototype );
180182
181183 Nexus::setCurrentContext (new NexusContext (
182- operation: self ::buildPublicOperationContext ( $ environment ),
183- environment : $ environment ,
184+ operation: self ::publicOperationContext ( $ operationContext ),
185+ workflowClient : $ workflowClient ,
184186 current: $ contextWithServiceDefinition ,
185187 cancelDetails: $ details ,
186188 outboundPipeline: $ this ->interceptorProvider
@@ -201,12 +203,12 @@ static function (CancelOperationInput $input) use ($handler): void {
201203 }
202204 }
203205
204- private static function buildPublicOperationContext (? NexusEnvironment $ environment ): ?NexusOperationContext
206+ private static function publicOperationContext ( NexusOperationContext $ operationContext ): ?NexusOperationContext
205207 {
206- if ($ environment === null ) {
208+ if ($ operationContext -> namespace === '' || $ operationContext -> taskQueue === '' ) {
207209 return null ;
208210 }
209- return new NexusOperationContext ( $ environment -> namespace , $ environment -> taskQueue ) ;
211+ return $ operationContext ;
210212 }
211213
212214 /**
0 commit comments