@@ -30,9 +30,69 @@ composer require temporal-php/support
3030
3131## Usage
3232
33- ### Activity and Worker factories
33+ ### Factories
3434
35+ The package provides factories to create Activity and Worker stubs in a more convenient way.
36+ With these factories, there is less code because all nested options are moved to the parameters of one method.
3537
38+ Use the ` \Temporal\Support\Factory\ActivityStub ` factory to create an Activity stub:
39+
40+ ``` php
41+ use \Temporal\Support\Factory\ActivityStub;
42+
43+ #[\Temporal\Workflow\WorkflowInterface]
44+ class HelloWorkflow {
45+ #[\Temporal\Workflow\WorkflowMethod]
46+ public function run(string $user) {
47+ yield ActivityStub::activity(
48+ class: UserService::class,
49+ startToCloseTimeout: 60,
50+ retryAttempts: 5,
51+ )->getContactEmail($user)->then(
52+ fn (string $email) => ActivityStub::activity(
53+ class: HelloService::class,
54+ startToCloseTimeout: '10 minutes',
55+ retryAttempts: 5,
56+ )->sendHelloEmail($user, $email),
57+ );
58+ }
59+ }
60+ ```
61+
62+ Use the ` \Temporal\Support\Factory\WorkflowStub ` factory to create a Workflow stub in a client scope:
63+
64+ ``` php
65+ use \Temporal\Support\Factory\WorkflowStub;
66+ /**
67+ * @var \Temporal\Client\WorkflowClient $client
68+ */
69+ $stub = WorkflowStub::workflow($client, HelloWorkflow::class, executionTimeout: '1 day');
70+ $run = $client->start($stub, 'User');
71+ // ...
72+ ```
73+
74+ Or create a Child Workflow stub in a workflow scope:
75+
76+ ``` php
77+ use \Temporal\Support\Factory\WorkflowStub;
78+
79+ #[\Temporal\Workflow\WorkflowInterface]
80+ class RegisterWorkflow {
81+ #[\Temporal\Workflow\WorkflowMethod]
82+ public function run(string $user) {
83+ yield \Temporal\Promise::all([
84+ WorkflowStub::childWorkflow(GreetingWorkflow::class, executionTimeout: '1 hour'),
85+ WorkflowStub::childWorkflow(SubscribeNewsWorkflow::class, executionTimeout: '10 minutes'),
86+ WorkflowStub::childWorkflow(PrepareUserEnvironmentWorkflow::class, executionTimeout: '1 hour'),
87+ ])->then(
88+ // Suppress failures
89+ onRejected: static fn () => null,
90+ );
91+
92+ // ...
93+ }
94+ }
95+ ```
3696
3797### Attributes
3898
@@ -62,7 +122,12 @@ $stub = \Temporal\Support\Factory\WorkflowStub::workflow(
62122```
63123
64124> [ !NOTE]
65- > Attributes will work only if you use the Activity and Worker factories from this package.
125+ > Attributes will work only if you use the Activity and Worker factories from this package.
126+
127+ > [ !WARNING]
128+ > Use attributes on the definitions that you use in factories.
129+ > So, if you separate interfaces and implementation, apply attributes to the interfaces.
130+
66131
67132### VirtualPromise interface
68133
0 commit comments