Skip to content

Commit 22dd573

Browse files
committed
Add docs about attributes
1 parent b7e2b2e commit 22dd573

1 file changed

Lines changed: 41 additions & 6 deletions

File tree

README.md

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,48 @@ composer require temporal-php/support
3232

3333
### Activity and Worker factories
3434

35+
36+
37+
### Attributes
38+
39+
Attributes can be used on Workflow or Activity definitions to set default stub options.
40+
41+
```php
42+
#[\Temporal\Support\Attribute\TaskQueue('my-task-queue')]
43+
#[\Temporal\Support\Attribute\RetryPolicy(attempts: 5)]
44+
#[WorkflowInterface]
45+
interface HelloWorkflow {
46+
#[WorkflowMethod]
47+
public function greet(string $name);
48+
}
49+
50+
$stub = \Temporal\Support\Factory\WorkflowStub::workflow($client, HelloWorkflow::class);
51+
52+
// TaskQueue is now set to 'my-task-queue' and RetryPolicy to 5 attempts
53+
$stub->greet('User');
54+
55+
// You can override the default options
56+
$stub = \Temporal\Support\Factory\WorkflowStub::workflow(
57+
$client,
58+
HelloWorkflow::class,
59+
taskQueue: 'another-task-queue',
60+
retryAttempts: 1,
61+
)->greet('User');
62+
```
63+
64+
> [!NOTE]
65+
> Attributes will work only if you use the Activity and Worker factories from this package.
66+
3567
### VirtualPromise interface
3668

3769
Every time we use `yield` in a Workflow to wait for an action to complete, a Promise is actually yielded.
3870
At this point, the IDE and static analyzer usually get lost in type definitions,
3971
and we experience difficulties and inconveniences because of this.
40-
However, if the Promise interface had the `@yield` annotation, we could explain to the IDE what type of value we expect to be sent back into the generator from the coroutine.
41-
Since ReactPHP [isn't yet planning](https://github.com/orgs/reactphp/discussions/536) to add the `@yield` annotation to their promises (Temporal PHP uses ReactPHP promises),
72+
However, if the Promise interface had the `@yield` annotation,
73+
we could explain to the IDE what type of value we expect to be sent back into the generator from the coroutine.
74+
Since ReactPHP [isn't yet planning](https://github.com/orgs/reactphp/discussions/536)
75+
to add the `@yield` annotation to their promises
76+
(Temporal PHP uses ReactPHP promises),
4277
we suggest using our solution for typing - `VirtualPromise`.
4378

4479
```php
@@ -69,11 +104,11 @@ class WorkflowClass {
69104
}
70105
```
71106

72-
> Warning: don't implement the `VirtualPromise` interface yourself, use it only as a type hint.
73-
74-
> PHPStorm and Psalm can handle the @yield annotation, but PHPStan can't yet ([issue](https://github.com/phpstan/phpstan/issues/4245)).
107+
> [!WARNING]
108+
> don't implement the `VirtualPromise` interface yourself, use it only as a type hint.
75109
76-
### Attributes
110+
> [!NOTE]
111+
> PHPStorm and Psalm can handle the `@yield` annotation, but PHPStan can't yet ([issue](https://github.com/phpstan/phpstan/issues/4245)).
77112
78113
## Contributing
79114

0 commit comments

Comments
 (0)