4242use Temporal \Worker \Environment \Environment ;
4343use Temporal \Worker \Environment \EnvironmentInterface ;
4444use Temporal \Worker \LoopInterface ;
45+ use Temporal \Worker \ServiceCredentials ;
4546use Temporal \Worker \Transport \Codec \CodecInterface ;
4647use Temporal \Worker \Transport \Codec \JsonCodec ;
4748use Temporal \Worker \Transport \Codec \ProtoCodec ;
@@ -74,29 +75,10 @@ class WorkerFactory implements WorkerFactoryInterface, LoopInterface
7475{
7576 use EventEmitterTrait;
7677
77- /**
78- * @var string
79- */
8078 private const ERROR_MESSAGE_TYPE = 'Received message type must be a string, but %s given ' ;
81-
82- /**
83- * @var string
84- */
8579 private const ERROR_HEADERS_TYPE = 'Received headers type must be a string, but %s given ' ;
86-
87- /**
88- * @var string
89- */
9080 private const ERROR_HEADER_NOT_STRING_TYPE = 'Header "%s" argument type must be a string, but %s given ' ;
91-
92- /**
93- * @var string
94- */
9581 private const ERROR_QUEUE_NOT_FOUND = 'Cannot find a worker for task queue "%s" ' ;
96-
97- /**
98- * @var string
99- */
10082 private const HEADER_TASK_QUEUE = 'taskQueue ' ;
10183
10284 protected DataConverterInterface $ converter ;
@@ -112,7 +94,6 @@ class WorkerFactory implements WorkerFactoryInterface, LoopInterface
11294 protected ClientInterface $ client ;
11395 protected ServerInterface $ server ;
11496 protected QueueInterface $ responses ;
115- protected RPCConnectionInterface $ rpc ;
11697
11798 /**
11899 * @var MarshallerInterface<array>
@@ -123,21 +104,22 @@ class WorkerFactory implements WorkerFactoryInterface, LoopInterface
123104
124105 public function __construct (
125106 DataConverterInterface $ dataConverter ,
126- RPCConnectionInterface $ rpc ,
107+ protected RPCConnectionInterface $ rpc ,
108+ ServiceCredentials $ credentials ,
127109 ) {
128110 $ this ->converter = $ dataConverter ;
129- $ this ->rpc = $ rpc ;
130-
131- $ this ->boot ();
111+ $ this ->boot ($ credentials );
132112 }
133113
134114 public static function create (
135115 ?DataConverterInterface $ converter = null ,
136116 ?RPCConnectionInterface $ rpc = null ,
117+ ?ServiceCredentials $ credentials = null ,
137118 ): WorkerFactoryInterface {
138119 return new static (
139120 $ converter ?? DataConverter::createDefault (),
140121 $ rpc ?? Goridge::create (),
122+ $ credentials ?? ServiceCredentials::create (),
141123 );
142124 }
143125
@@ -237,10 +219,10 @@ protected function createTaskQueue(): RepositoryInterface
237219 return new ArrayRepository ();
238220 }
239221
240- protected function createRouter (): RouterInterface
222+ protected function createRouter (ServiceCredentials $ credentials ): RouterInterface
241223 {
242224 $ router = new Router ();
243- $ router ->add (new Router \GetWorkerInfo ($ this ->queues , $ this ->marshaller ));
225+ $ router ->add (new Router \GetWorkerInfo ($ this ->queues , $ this ->marshaller , $ credentials ));
244226
245227 return $ router ;
246228 }
@@ -269,12 +251,12 @@ protected function createMarshaller(ReaderInterface $reader): MarshallerInterfac
269251 return new Marshaller (new AttributeMapperFactory ($ reader ));
270252 }
271253
272- private function boot (): void
254+ private function boot (ServiceCredentials $ credentials ): void
273255 {
274256 $ this ->reader = $ this ->createReader ();
275257 $ this ->marshaller = $ this ->createMarshaller ($ this ->reader );
276258 $ this ->queues = $ this ->createTaskQueue ();
277- $ this ->router = $ this ->createRouter ();
259+ $ this ->router = $ this ->createRouter ($ credentials );
278260 $ this ->responses = $ this ->createQueue ();
279261 $ this ->client = $ this ->createClient ();
280262 $ this ->server = $ this ->createServer ();
0 commit comments