1515use Temporal \Internal \Declaration \EntityNameValidator ;
1616use Temporal \Internal \Events \EventEmitterTrait ;
1717use Temporal \Internal \Events \EventListenerInterface ;
18- use Temporal \Internal \Nexus \NexusEnvironment ;
19- use Temporal \Internal \Nexus \NexusTaskHandler ;
2018use Temporal \Internal \Repository \RepositoryInterface ;
2119use Temporal \Internal \ServiceContainer ;
2220use Temporal \Internal \Transport \Router ;
@@ -37,21 +35,18 @@ class Worker implements WorkerInterface, EventListenerInterface, DispatcherInter
3735 private RouterInterface $ router ;
3836 private ServiceContainer $ services ;
3937 private RPCConnectionInterface $ rpc ;
40- private ?NexusEnvironment $ nexusEnvironment ;
4138
4239 public function __construct (
4340 string $ taskQueue ,
4441 WorkerOptions $ options ,
4542 ServiceContainer $ serviceContainer ,
4643 RPCConnectionInterface $ rpc ,
47- ?NexusEnvironment $ nexusEnvironment = null ,
4844 ) {
4945 EntityNameValidator::validateTaskQueue ($ taskQueue );
5046
5147 $ this ->rpc = $ rpc ;
5248 $ this ->name = $ taskQueue ;
5349 $ this ->options = $ options ;
54- $ this ->nexusEnvironment = $ nexusEnvironment ;
5550
5651 $ this ->services = $ serviceContainer ;
5752 $ this ->router = $ this ->createRouter ();
@@ -122,6 +117,14 @@ public function getActivities(): RepositoryInterface
122117
123118 public function registerNexusServiceImplementation (object ...$ services ): WorkerInterface
124119 {
120+ if ($ this ->services ->nexusEnvironment === null && $ services !== []) {
121+ throw new \LogicException (
122+ 'Cannot register Nexus service implementations on a worker without a WorkflowClient. ' .
123+ 'Pass a WorkflowClient to the WorkerFactory (e.g. WorkerFactory::create(client: $workflowClient)) ' .
124+ '— Nexus operations require cluster access. ' ,
125+ );
126+ }
127+
125128 foreach ($ services as $ service ) {
126129 $ prototype = $ this ->services ->nexusServicesReader ->fromClass (\get_class ($ service ));
127130 $ this ->services ->nexusServices ->add ($ prototype ->withInstance ($ service ), false );
@@ -153,27 +156,10 @@ protected function createRouter(): RouterInterface
153156 $ router ->add (new Router \StackTrace ($ this ->services ->running ));
154157
155158 // Nexus routes
156- $ nexusHandler = $ this ->createNexusTaskHandler ();
157- $ invocations = $ this ->services ->nexusInvocations ;
158- $ router ->add (new Router \InvokeNexusOperation ($ nexusHandler , $ invocations , $ this ->services ->dataConverter ));
159- $ router ->add (new Router \CancelNexusOperation ($ nexusHandler ));
160- $ router ->add (new Router \CancelNexusOperationMethod ($ invocations ));
159+ $ router ->add (new Router \InvokeNexusOperation ($ this ->services ->nexusTaskHandler , $ this ->services ->nexusInvocations , $ this ->services ->dataConverter ));
160+ $ router ->add (new Router \CancelNexusOperation ($ this ->services ->nexusTaskHandler ));
161+ $ router ->add (new Router \CancelNexusOperationMethod ($ this ->services ->nexusInvocations ));
161162
162163 return $ router ;
163164 }
164-
165- private function createNexusTaskHandler (): NexusTaskHandler
166- {
167- $ handler = new NexusTaskHandler (
168- $ this ->services ->nexusServices ,
169- $ this ->services ->dataConverter ,
170- interceptorProvider: $ this ->services ->interceptorProvider ,
171- );
172-
173- if ($ this ->nexusEnvironment !== null ) {
174- $ handler ->withNexusEnvironment ($ this ->nexusEnvironment );
175- }
176-
177- return $ handler ;
178- }
179165}
0 commit comments